PHP注意事项-index.PHP上未定义索引
我遇到了一个服务器通知,它似乎不会影响页面的加载,但是每次加载页面时都会在错误日志中创建一个新条目。。。这个错误是: PHP注意:未定义索引:第1行C:\File Location\htdocs\index.PHP中的东西 我不确定问题是在第一行还是在下一行,所以我包含了整个文件的修改版本。对我来说,奇怪的是,在其他几个文件上有一行相同的代码,但却没有引起任何问题。此外,值被正确提取,一切正常,我只是不知道要更改什么以避免通知PHP注意事项-index.PHP上未定义索引,php,apache,notice,Php,Apache,Notice,我遇到了一个服务器通知,它似乎不会影响页面的加载,但是每次加载页面时都会在错误日志中创建一个新条目。。。这个错误是: PHP注意:未定义索引:第1行C:\File Location\htdocs\index.PHP中的东西 我不确定问题是在第一行还是在下一行,所以我包含了整个文件的修改版本。对我来说,奇怪的是,在其他几个文件上有一行相同的代码,但却没有引起任何问题。此外,值被正确提取,一切正常,我只是不知道要更改什么以避免通知 $thingvalue = $_REQUEST['thing'];
$thingvalue = $_REQUEST['thing'];
include("mdetect.php");
$iphoneTierHomePage = 'mobilemain.php';
$iphoneTierMobilePage = 'mobilepage.php?thing=' . $thingvalue;
$genericMobileDeviceHomePage = 'mobilemain.php';
$genericMobileDeviceMobilePage = 'mobilepage.php?thing=' . $thingvalue;
$line1 = define('WP_USE_THEMES', true);
$line2 = require('./wp-blog-header.php');
$desktopPage == $line1 + $line2;
$uagent_obj = new uagent_info();
function AutoRedirectToProperHomePage()
{
global $thingvalue, $uagent_obj, $iphoneTierHomePage, $genericMobileDeviceHomePage, $iphoneTierMobilePage, $genericMobileDeviceMobilePage, $desktopPage;
if ($thingvalue == ''){
if ($uagent_obj->isTierIphone == $uagent_obj->true)
header ('Location: '.$iphoneTierHomePage);
else if ($uagent_obj->DetectMobileQuick() == $uagent_obj->true)
header ('Location: '.$genericMobileDeviceHomePage);
else
header ('Location: '.$desktopHomePage);
}
if ($thingvalue != ''){
if ($uagent_obj->isTierIphone == $uagent_obj->true)
header ('Location: '.$iphoneTierMobilePage);
else if ($uagent_obj->DetectMobileQuick() == $uagent_obj->true)
header ('Location: '.$genericMobileDeviceMobilePage);
else
header ('Location: '.$desktopPage);
}
}
AutoRedirectToProperHomePage();
它指的是index.php中第一行的数组索引: 试试这个:
$thingvalue = empty($_REQUEST['thing']) ? '' : $_REQUEST['thing'];
它指的是index.php中第一行的数组索引: 试试这个:
$thingvalue = empty($_REQUEST['thing']) ? '' : $_REQUEST['thing'];
问题是,你试图在这里得到东西的价值
$thingvalue=$\u请求['thing']先检查该值是否存在,然后执行代码>
先试试这个
if( !isset( $_REQUEST['thing']) )
{
do something because its missing
}
问题是,你试图在这里得到东西的价值
$thingvalue=$\u请求['thing']先检查该值是否存在,然后执行代码>
先试试这个
if( !isset( $_REQUEST['thing']) )
{
do something because its missing
}
它正试图引用$\u请求
超全局中的索引thing
。如果有人正在直接查看该页面,并且没有通过表单发布,也没有在查询字符串中使用?thing=foobar
,PHP将显示该通知。我建议不要使用$\u REQUEST
,因为它会同时检查$\u GET
和$\u POST
,这不是很安全/实用-然后检查它是否已设置,如果未设置,则采取一些故障保存操作:
try
{
if(!isset($_POST['thing']))
{
throw new Exception('No direct access. Please use our <a href="http://www.mysite.com/contact">Contact form</a>');
}
else
{
$thingvalue = $_POST['thing'];
}
}
catch(Exception $e)
{
echo $e->getMessage();
exit();
}
试试看
{
如果(!isset($_POST['thing']))
{
抛出新异常('无直接访问。请使用我们的');
}
其他的
{
$thingvalue=$_POST['thing'];
}
}
捕获(例外$e)
{
echo$e->getMessage();
退出();
}
它正在尝试引用$\u请求中的索引内容
。如果有人正在直接查看该页面,并且没有通过表单发布,也没有在查询字符串中使用?thing=foobar
,PHP将显示该通知。我建议不要使用$\u REQUEST
,因为它会同时检查$\u GET
和$\u POST
,这不是很安全/实用-然后检查它是否已设置,如果未设置,则采取一些故障保存操作:
try
{
if(!isset($_POST['thing']))
{
throw new Exception('No direct access. Please use our <a href="http://www.mysite.com/contact">Contact form</a>');
}
else
{
$thingvalue = $_POST['thing'];
}
}
catch(Exception $e)
{
echo $e->getMessage();
exit();
}
试试看
{
如果(!isset($_POST['thing']))
{
抛出新异常('无直接访问。请使用我们的');
}
其他的
{
$thingvalue=$_POST['thing'];
}
}
捕获(例外$e)
{
echo$e->getMessage();
退出();
}
在第二行输入这个,看看它给你带来了什么:var_dump($_REQUEST['thing'])在第二行输入这个,看看它给你带来了什么:var_dump($_REQUEST['thing'])再一次,我被这个社区迷住了!非常感谢你,道格!再一次,我被这个社区迷住了!非常感谢你,道格!