superglobals

How to grab URL parameters using PHP?

℡╲_俬逩灬. 提交于 2019-11-29 16:14:58
I'm trying to grab each URL parameter and display them from first to last, but I want to be able to display any of the parameters anywhere on the page. How can I do this? What do I have to add or modify on my script? Here is an example of a URL value. http://www.localhost.com/topics/index.php?cat=3&sub1=sub-1&sub2=sub-2&sub3=sub-3&sub4=sub-4 Here is my PHP script. $url = $_SERVER['QUERY_STRING']; $query = array(); if(!empty($url)){ foreach(explode('&', $url) as $part){ list($key, $value) = explode('=', $part, 2); $query[$key] = $value; } } You don't need to do that manually, PHP already

how to check multiple $_POST variable for existence using isset()?

本小妞迷上赌 提交于 2019-11-29 07:55:02
I need to check if $_POST variables exist using single statement isset. if (isset$_POST['name'] && isset$_POST['number'] && isset$_POST['address'] && etc ....) is there any easy way to achieve this? Use simple way with array_diff and array_keys $check_array = array('key1', 'key2', 'key3'); if (!array_diff($check_array, array_keys($_POST))) echo 'all exists'; $variables = array('name', 'number', 'address'); foreach($variables as $variable_name){ if(isset($_POST[$variable_name])){ echo 'Variable: '.$variable_name.' is set<br/>'; }else{ echo 'Variable: '.$variable_name.' is NOT set<br/>'; } } Or,

how safe is $_SERVER[“HTTP_HOST”]?

江枫思渺然 提交于 2019-11-29 07:02:38
I have a database full of website urls, the primary key is the $_SERVER["HTTP_HOST"] of the website. When a user navigates to ... lets say www.my-epic-example-url.com , It will connect the the database and use the $_SERVER["HTTP_HOST"] of that websites, then fetches all the data referencing that website! What I want to know is, how safe is $_SERVER["HTTP_HOST"] ? Can it be externally modified? The only reason i ask is because i read an artical a while back ( cant remember where it was ) saying be careful when using $_SERVER because it is unsafe... Is this true? $_SERVER["HTTP_HOST"] is the

How to grab URL parameters using PHP?

亡梦爱人 提交于 2019-11-28 10:00:57
问题 I'm trying to grab each URL parameter and display them from first to last, but I want to be able to display any of the parameters anywhere on the page. How can I do this? What do I have to add or modify on my script? Here is an example of a URL value. http://www.localhost.com/topics/index.php?cat=3&sub1=sub-1&sub2=sub-2&sub3=sub-3&sub4=sub-4 Here is my PHP script. $url = $_SERVER['QUERY_STRING']; $query = array(); if(!empty($url)){ foreach(explode('&', $url) as $part){ list($key, $value) =

how to check multiple $_POST variable for existence using isset()?

ぐ巨炮叔叔 提交于 2019-11-28 01:32:09
问题 I need to check if $_POST variables exist using single statement isset. if (isset$_POST['name'] && isset$_POST['number'] && isset$_POST['address'] && etc ....) is there any easy way to achieve this? 回答1: Use simple way with array_diff and array_keys $check_array = array('key1', 'key2', 'key3'); if (!array_diff($check_array, array_keys($_POST))) echo 'all exists'; 回答2: $variables = array('name', 'number', 'address'); foreach($variables as $variable_name){ if(isset($_POST[$variable_name])){

how safe is $_SERVER[“HTTP_HOST”]?

三世轮回 提交于 2019-11-28 00:40:41
问题 I have a database full of website urls, the primary key is the $_SERVER["HTTP_HOST"] of the website. When a user navigates to ... lets say www.my-epic-example-url.com , It will connect the the database and use the $_SERVER["HTTP_HOST"] of that websites, then fetches all the data referencing that website! What I want to know is, how safe is $_SERVER["HTTP_HOST"] ? Can it be externally modified? The only reason i ask is because i read an artical a while back ( cant remember where it was )

Is using superglobals directly good or bad in PHP?

青春壹個敷衍的年華 提交于 2019-11-28 00:02:15
So, I don't come from a huge PHP background—and I was wondering if in well formed code, one should use the 'superglobals' directly, e.g. in the middle of some function say $_SESSION['x'] = 'y'; or if, like I'd normally do with variables, it's better to send them as arguments that can be used from there, e.g: class Doer { private $sess; public function __construct(&$sess) { $this->sess =& $sess; } } $doer = new Doer($_SESSION); and then use the Doer->sess version from within Doer and such. (The advantage of this method is that it makes clear that Doer uses $_SESSION.) What's the accepted PHP

Possible Values For: PHP_OS

↘锁芯ラ 提交于 2019-11-27 17:35:15
Is there a place to find a list of the possible values for the PHP predefined constant PHP_OS ? I'd like to use this value for a system requirements check, but need to know how different operating systems are named in this variable. Through some searching, so far I've compiled the following list: CYGWIN_NT-5.1 Darwin FreeBSD HP-UX IRIX64 Linux NetBSD OpenBSD SunOS Unix WIN32 WINNT Windows If anyone has a more complete list, or knows of any additional values I'd love to hear them! PHP passes through the uname , except on Windows ( WINNT ) and Netware ( Netware ) . See Wikipedia for a non

Is using superglobals directly good or bad in PHP?

半城伤御伤魂 提交于 2019-11-27 04:06:53
问题 So, I don't come from a huge PHP background—and I was wondering if in well formed code, one should use the 'superglobals' directly, e.g. in the middle of some function say $_SESSION['x'] = 'y'; or if, like I'd normally do with variables, it's better to send them as arguments that can be used from there, e.g: class Doer { private $sess; public function __construct(&$sess) { $this->sess =& $sess; } } $doer = new Doer($_SESSION); and then use the Doer->sess version from within Doer and such.

Possible Values For: PHP_OS

风流意气都作罢 提交于 2019-11-26 19:05:35
问题 Is there a place to find a list of the possible values for the PHP predefined constant PHP_OS ? I'd like to use this value for a system requirements check, but need to know how different operating systems are named in this variable. Through some searching, so far I've compiled the following list: CYGWIN_NT-5.1 Darwin FreeBSD HP-UX IRIX64 Linux NetBSD OpenBSD SunOS Unix WIN32 WINNT Windows If anyone has a more complete list, or knows of any additional values I'd love to hear them! 回答1: PHP