动作变量不被接受

时间:2013-05-18 12:58:18

标签: php

我之前已经使用过这个代码一百万次,但现在我遇到了问题。

在我的top.php文件中,我将代码设为http://www.sentuamsg.com/index.php?action=about

现在当我到达我的索引页面时,我收到错误代码通知:未定义变量:第4行/home/content/90/9753290/html/index.php中的操作

<?php
include("top.php");

if($action == "") {

echo "<p align=center><img src=mondaymoan.jpg></img></p>";

echo "<p><font face=Tahoma><b><font size=2>Monday Moan:</font></b> <font size=2>
All the weeks Gaming Action, Rumours, News snipplets assessed and talked about 
all in one blog. Have a read of your own on this Monday's Moan</font></font></p>";

echo "<p align=right><font face=Tahoma size=2>[Read]</font></p>";

echo "<p><img src=mostloved.jpg></p>";

echo "<p align=center><img src=retrogamer.jpg></img></p>";

echo "<p><font face=Tahoma><b><font size=2>Retro Gamer:</font></b> <font size=2>
Taking on the games from the past, these games range from Video Game consoles to PC Games. One of our most popular feature as you the gamers relive the past with us through the joys and frustrations.</font></font></p>";

echo "<p align=right><font face=Tahoma size=2>[View]</font></p>";

include("bottom.php");
exit;
}

if($action == "action") {

echo "done";

include("bottom.php");
exit;
}
?>

为什么会发生这种错误?我错过了什么,或者我使用的是php5中没有使用的旧编码技术?

2 个答案:

答案 0 :(得分:3)

那是因为你在尝试使用之前没有设置$action。以下代码行需要超出if($action == "") {语句:

$action = $_GET['action'];

或者,更好的是,您应该首先查看它是否存在:

$action = (isset($_GET['action'])) ? $_GET['action'] : '';

答案 1 :(得分:0)

你应该使用$_GET["action"]并阅读本文; register_globals