isset

custom function that uses isset() returning undefined variables when used [duplicate]

那年仲夏 提交于 2020-01-17 14:50:49
问题 This question already has answers here : PHP take string and check if that string exists as a variable (3 answers) Closed 5 years ago . I have a field that depends has custom text if a certain condition is met...and if it isn't the field is blank. I have written a custom function test if a variable is set function AmISet($fieldName) { if (isset($fieldName)) { echo "I am set"; }else{ echo "I am not set"; } }; but when I attach it the field I get an error that the variable is undefined. But

PHP-009-【特殊变量】-服务器变量-$_SERVER

…衆ロ難τιáo~ 提交于 2020-01-16 03:16:13
$_SERVER涉及的内容太多了就不一一列出来 捡一些比较重要的来学习 可以直接运行下面的代码来查看 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <?php //时间戳(timestamp),通常是一个字符序列,唯一地标识某一刻的时间 echo "显示脚本开始运行时间:\"".$_SERVER["REQUEST_TIME"]."\"<br />"; echo "<hr />"; echo "显示脚本文件的相对路径和文件名:\"".$_SERVER["PHP_SELF"]."\"<br />"; echo "显示服务器使用的CGI脚本规范:\"".$_SERVER["GATEWAY_INTERFACE"]."\"<br />"; echo "显示当前运行脚本所在服务器的IP地址:\"".$_SERVER["SERVER_ADDR"]."\"<br />"; echo "显示当前运行脚本服务器名称:\"".$_SERVER["SERVER_NAME"]."\"<br />"; echo "显示当前运行脚本服务器标识:\"".$_SERVER["SERVER_SOFTWARE"]."\"<br />"; echo "显示请求页面的通信协议的名称和版本:\"".$_SERVER["SERVER

TP5判断是手机端或PC端

为君一笑 提交于 2020-01-15 17:09:39
TP5判断是手机端或PC端 //判断是否是手机端 public static function ismobile ( ) { $_SERVER [ 'ALL_HTTP' ] = isset ( $_SERVER [ 'ALL_HTTP' ] ) ? $_SERVER [ 'ALL_HTTP' ] : '' ; $mobile_browser = '0' ; if ( preg_match ( '/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|iphone|ipad|ipod|android|xoom)/i' , strtolower ( $_SERVER [ 'HTTP_USER_AGENT' ] ) ) ) $mobile_browser ++ ; if ( ( isset ( $_SERVER [ 'HTTP_ACCEPT' ] ) ) and ( strpos ( strtolower ( $_SERVER [ 'HTTP_ACCEPT' ] ) , 'application/vnd.wap.xhtml+xml' ) !== false ) ) $mobile_browser ++ ; if ( isset ( $_SERVER [ 'HTTP_X_WAP_PROFILE' ] ) ) $mobile

If isset $_SESSION goto this page?

…衆ロ難τιáo~ 提交于 2020-01-13 19:25:11
问题 Ok, having trouble here: I created a login script, so after a person logs in then they will get direted to another page. And also, I have it redirecting them to the login page if they try and access one of those other pages. My problem is, if a user is logged in and stumbles to the login page again --by accident-- I would like for it to recognize that the user is logged in and redirect them to that next page (which is index2.php) ?? Having troubles :-( Here is my code so far: require_once

php isset()与empty()的使用

冷暖自知 提交于 2020-01-11 06:21:43
本文转载自: https://www.cnblogs.com/dreamflower/p/5230132.html 作者:dreamflower 转载请注明该声明。 PHP isset函数作用 isset函数是检测变量是否设置。 格式:bool isset( mixed var [, mixed var [, ...]] ) 返回值: 若变量不存在则返回FALSE 若变量存在且其值为NULL,也返回FALSE 若变量存在且值不为NULL,则返回TURE 同时检查多个变量时,每个单项都符号上一条要求时才返回TRUE,否则结果为FALSE 如果已经 使用 unset()释放了一个变量之后,它将不再是isset()。若使用isset()测试一个被设置成NULL的变量,将返回FALSE。同时要注意的是一个NULL字节("\0")并不等同于PHP的NULL常数。 警告:isset()只能用于变量,因为传递任何其它参数都将造成解析错误。若想检测常量是否已设置,可使用defined()函数。 1 <? php 2 3 $a = array ('test' => 1, 'hello' => NULL ); 4 5 var_dump ( isset ( $a ['test') ); // TRUE 6 var_dump ( isset ( $a ['foo') ); // FALSE 7 var

Can I able to write with out isset($post[]) for the below code

坚强是说给别人听的谎言 提交于 2020-01-06 17:46:15
问题 <script> function removeAllRowsContainingCheckedCheckbox() { alert("hello"); for (var rowi= table.rows.length; rowi-->0;) { var row= table.rows[rowi]; var inputs= row.getElementsByTagName('input'); for (var inputi= inputs.length; inputi-->0;) { //alert("inside for"); var input= inputs[inputi]; if (input.type==='checkbox' && input.checked) { //alert("indide if ") row.parentNode.removeChild(row); break; } } } } </script> <html> <head> </head> <body> <form action="" method="post" enctype=

Triggering or preventing a javascript function if $_SESSION['SESS_USER_ID'] isn't set

陌路散爱 提交于 2020-01-06 07:58:31
问题 This php function currently redirects the user to another page if they aren't logged in if(!isset($_SESSION['SESS_USER_ID']) || (trim($_SESSION['SESS_USER_ID']) == '')){ header("location: login_failed.html"); exit(); } How can I change the function so that instead of redirecting the user it does the following: Triggers the javascript function: loginFailed(); Prevents specific iframes which are preloaded from launching (these require a user to be logged in, and are currently opening as empty

isset on static class attributes

戏子无情 提交于 2020-01-04 03:12:13
问题 class A { public static $foo = 42; } $class = 'A'; $attribute = 'foo'; var_dump(isset($class::$attribute)); //gives bool(false) How can i checkt, of this static attribute exists in this class? 回答1: Use variable variables: var_dump(isset($class::$$attribute)); // the two dollars are intentional If you don't have PHP 5.3 yet the only accurate way is probably using the Reflection API: $reflectionClass = new ReflectionClass($class); $exists = $reflectionClass->hasProperty($attribute) &&

PHP associative arrays - how to treat integer as string

喜欢而已 提交于 2020-01-03 09:12:09
问题 I have a simple associative array. $a = array("a"=>"b", "c"=>"d"); I want to check if the key "1" exists in the array, e.g. isset($a["1"]); This string is being treated as an integer, so that echo $a["1"]; //prints "d" How do I get it to treat it as a string? I don't want to use array_key_exists or in_array because my benchmarking shows isset will be a lot faster. 回答1: It doesn't appear that you can do what you want to do. from http://us.php.net/manual/en/language.types.array.php: A key may

获取真实IP地址

[亡魂溺海] 提交于 2020-01-02 05:04:11
/** * 获得用户的真实IP地址 * * @return string */ function getRealip() { static $realip = NULL; if ($realip !== NULL) { return $realip; } if (isset($_SERVER)) { if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); /* 取X-Forwarded-For中第一个非unknown的有效IP字符串 */ foreach ($arr AS $ip) { $ip = trim($ip); if ($ip != 'unknown') { $realip = $ip; break; } } } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) { $realip = $_SERVER['HTTP_CLIENT_IP']; } else { if (isset($_SERVER['REMOTE_ADDR'])) { $realip = $_SERVER['REMOTE_ADDR']; } else { $realip = '0.0.0.0'; } } } else { if