php – 不能在函数调用的结果上使用isset()(你可以使用“null!=
( ! ) Fatal error: Cannot use isset() on the result of a function call (you can use "null !== func()" instead) in C:UserssanojDocumentsNetBeansProjectsvideo-siteappdetect.php on line 45 Call Stack # Time Memory Function Location 1 0.0000 234208 {main}( ) ..index.php:0 以前我的代码是 if(!defined('WAP')) define('WAP',isset($_REQUEST['wap']) || isset($_REQUEST['wap2']) || isset($_REQUEST['imode'])|| isset($_REQUEST['html'])|| isset($_REQUEST['Android'])|| isset($_REQUEST['iphone'])|| isset($_REQUEST['IEMobile'])); if (WAP) { define('WIRELESS_PROTOCOL',isset($_REQUEST['wap']) ? 'wap' : (isset($_REQUEST['wap2']) ? 'wap2' : (isset($_REQUEST['iphone']) ? 'iphone' : (isset($_REQUEST['imode']) ? 'imode' : (isset($_REQUEST['IEMobile']) ? 'IEMobile' :(isset($_REQUEST['html']) ? 'html' : (isset($_REQUEST['Android']) ? 'Android' : ''))))))); 我的IDE警告不要直接访问SuperGlobal $_REQUEST数组 if(!defined('WAP')) { define('WAP',isset(filter_input(INPUT_REQUEST,'wap',FILTER_SANITIZE_STRING)) || isset(filter_input(INPUT_REQUEST,'wap2','imode',FILTER_SANITIZE_STRING))|| isset(filter_input(INPUT_REQUEST,'html','Android','iphone','IEMobile',FILTER_SANITIZE_STRING))); } if (WAP) { define('WIRELESS_PROTOCOL',FILTER_SANITIZE_STRING)) ? 'wap' : (isset(filter_input(INPUT_REQUEST,FILTER_SANITIZE_STRING)) ? 'wap2' : (isset(filter_input(INPUT_REQUEST,FILTER_SANITIZE_STRING)) ? 'iphone' : (isset(filter_input(INPUT_REQUEST,FILTER_SANITIZE_STRING)) ? 'imode' : (isset(filter_input(INPUT_REQUEST,FILTER_SANITIZE_STRING)) ? 'IEMobile' :(isset(filter_input(INPUT_REQUEST,FILTER_SANITIZE_STRING)) ? 'html' : (isset(filter_input(INPUT_REQUEST,FILTER_SANITIZE_STRING)) ? 'Android' : ''))))))); 这是detect.php <?php $userBrowser = $_SERVER['HTTP_ACCEPT']; if(stristr($userBrowser,'application/vnd.wap.xhtml+xml')) { $_REQUEST['wap2'] = 1; } elseif(stripos($_SERVER['HTTP_USER_AGENT'],"iPod")) { $_REQUEST['iphone'] = 1; } elseif(stripos($_SERVER['HTTP_USER_AGENT'],"iPhone")) { $_REQUEST['iphone'] = 1; } elseif(stripos($_SERVER['HTTP_USER_AGENT'],"Android")) { $_REQUEST['Android'] = 1; } elseif(stripos($_SERVER['HTTP_USER_AGENT'],"IEMobile")) { $_REQUEST['IEMobile'] = 1; } elseif(stristr($userBrowser,'DoCoMo/' || 'portalmmm/')) { $_REQUEST['imode'] = 1; } elseif(stristr($userBrowser,'text/vnd.wap.wml')) { $_REQUEST['wap'] = 1; } elseif(stristr($userBrowser,'text/html')) { $_REQUEST['html'] = 1; } if(!defined('WAP')) define('WAP',isset($_REQUEST['wap']) ? 'wap' : (isset($_REQUEST['wap2']) ? 'wap2' : (isset($_REQUEST['iphone']) ? 'iphone' : (isset($_REQUEST['imode']) ? 'imode' : (isset($_REQUEST['IEMobile']) ? 'IEMobile' :(isset($_REQUEST['html']) ? 'html' : (isset($_REQUEST['Android']) ? 'Android' : ''))))))); if (WIRELESS_PROTOCOL == 'wap') { $browser_t = "mobile"; } elseif (WIRELESS_PROTOCOL == 'wap2') { $browser_t = "mobile"; } elseif (WIRELESS_PROTOCOL == 'imode') { $browser_t = "mobile"; } elseif (WIRELESS_PROTOCOL == 'iphone') { $browser_t = "smartphone"; } elseif (WIRELESS_PROTOCOL == 'Android') { $browser_t = "smartphone"; } elseif (WIRELESS_PROTOCOL == 'IEMobile') { $browser_t = "smartphone"; } elseif (WIRELESS_PROTOCOL == 'html') { $mobile_browser = '0'; if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone)/i',strtolower($_SERVER['HTTP_USER_AGENT']))){ $mobile_browser++; } if((strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml')>0) or ((isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE'])))){ $mobile_browser++; } $mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'],4)); $mobile_agents = array( 'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac','blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno','ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-','maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-','newt','noki','oper','palm','pana','pant','phil','play','port','prox','qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar','sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-','tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp','wapr','webc','winw','xda','xda-'); if(in_array($mobile_ua,$mobile_agents)){ $mobile_browser++; } if (strpos(strtolower($_SERVER['ALL_HTTP']),'OperaMini')>0) { $mobile_browser++; } if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'iemobile')>0) { $mobile_browser++; } if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'windows')>0) { $mobile_browser=0; } if($mobile_browser>0){ // do something wap $browser_t = "mobile"; } // non-mobile else { $_SESSION['Browser_d'] = "web"; $browser_t = "web"; } } else { // do something else html $_SESSION['Browser_d'] = "web"; $browser_t = "web"; } } else { $mobile_browser = '0'; if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone)/i',$mobile_agents)){ $mobile_browser++; } if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'iemobile')>0) { $mobile_browser++; } if (strpos(strtolower($_SERVER['ALL_HTTP']),'OperaMini')>0) { $mobile_browser++; } if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'windows')>0) { $mobile_browser=0; } if($mobile_browser>0){ // do something wap $browser_t = "mobile"; } // non-mobile else { $_SESSION['Browser_d'] = "web"; $browser_t = "web"; } } ?> 和index.php <?php include "app/config.php"; include "app/detect.php"; if ($page_name=='') { include $browser_t.'/index.html'; } elseif ($page_name=='index.html') { include $browser_t.'/index.html'; } elseif ($page_name=='singlepage.html') { include $browser_t.'/singlepage.html'; } elseif ($page_name=='categories.html') { include $browser_t.'/categories.html'; } elseif ($page_name=='contact.html') { include $browser_t.'/contact.html'; } else { include $browser_t.'/404.html'; } ?> 和config.php <?php $current_page_uri = $_SERVER['REQUEST_URI']; $part_url = explode("/",$current_page_uri); $page_name = end($part_url); $email_id = "s.hidayath@agileits.com"; ?> 当加载索引文件时,它应检测设备并将其重定向到正确的根,但在我的情况下它不会 ( ! ) Notice: Undefined index: ALL_HTTP in C:UserssanojDocumentsNetBeansProjectsvideo-site-2appdetect.php on line 118 Call Stack # Time Memory Function Location 1 0.0090 233992 {main}( ) ..index.php:0 2 0.0230 295896 include( 'C:UserssanojDocumentsNetBeansProjectsvideo-site-2appdetect.php' ) ..index.php:11 ( ! ) Warning: include(web/404.html): failed to open stream: No such file or directory in C:UserssanojDocumentsNetBeansProjectsvideo-site-2index.php on line 30 Call Stack # Time Memory Function Location 1 0.0090 233992 {main}( ) ..index.php:0 ( ! ) Warning: include(): Failed opening 'web/404.html' for inclusion (include_path='.;C:phppear') in C:UserssanojDocumentsNetBeansProjectsvideo-site-2index.php on line 30 Call Stack # Time Memory Function Location 1 0.0090 233992 {main}( ) ..index.php:0
首先,NetBeans IDE会向您显示这些警告,以便您不直接信任$_REQUEST值并以某种方式验证它.通过检查isset($_ REQUEST [‘wap’]),您已经在检查IDE建议的哪个部分.此过程可以有其他步骤,您应该在使用它之前执行此操作,例如插入数据库.我忽略了许多NetBeans警告,因为NetBeans不知道我将如何处理输入/变量.它只是警告我最佳实践,这可能是也可能不是我的最佳实践.并且警告应该仅作为建议,而不是您必须做的事情.
其次,如果使用filter_input(),则不需要另外使用isset().因为,filter_input()已经为你做了.正如文件所说,
所以你可以删除isset(),你的代码应该安全地工作.但您可能仍想检查该值是否设置为应用替代值.在这种情况下,只需使用empty()函数,当filter_input()返回的值为NULL / FALSE时,它将返回FALSE.所以只是否定符合条件的条件.像这样 – if(!defined('WAP')) { define('WAP',!empty(filter_input(INPUT_REQUEST,FILTER_SANITIZE_STRING)) || !empty(filter_input(INPUT_REQUEST,FILTER_SANITIZE_STRING))|| !empty(filter_input(INPUT_REQUEST,FILTER_SANITIZE_STRING))); } if (WAP) { define('WIRELESS_PROTOCOL',FILTER_SANITIZE_STRING)) ? 'wap' : (!empty(filter_input(INPUT_REQUEST,FILTER_SANITIZE_STRING)) ? 'wap2' : (!empty(filter_input(INPUT_REQUEST,FILTER_SANITIZE_STRING)) ? 'iphone' : (!empty(filter_input(INPUT_REQUEST,FILTER_SANITIZE_STRING)) ? 'imode' : (!empty(filter_input(INPUT_REQUEST,FILTER_SANITIZE_STRING)) ? 'IEMobile' :(!empty(filter_input(INPUT_REQUEST,FILTER_SANITIZE_STRING)) ? 'html' : (!empty(filter_input(INPUT_REQUEST,FILTER_SANITIZE_STRING)) ? 'Android' : ''))))))); } 第二个错误
我在$_SERVER的php文档中找不到任何名为ALL_HTTP的变量.所以请检查链接并找到一个可以满足您目的的变量.我不确定你到底想要用它做什么,所以我无法提出任何建议. 第三个错误
错误已经说明该文件不存在.因此,文件不存在或者您提供的路径不正确.请检查并修复它. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |