superglobals

What is the purpose of $_POST?

南楼画角 提交于 2019-12-20 04:56:03
问题 I know it is php global variable but I'm not sure, what it do? I also read from official php site, but did not understand. 回答1: You may want to read up on the basics of PHP. Try reading some starter tutorials. $_POST is a variable used to grab data sent through a web form. Here's a simple page describing $_POST and how to use it from W3Schools: PHP $_POST Function Basically: Use HTML like this on your first page: <form action="submit.php" method="post"> Email: <input type="text" name=

PHP: $_SESSION never getting set, but $_POST is ?

余生长醉 提交于 2019-12-13 21:16:24
问题 [@the downvote and idiot remarks, that's not cool to beat up on people. I rechecked the documentation and coursenotes for 3 whole days before even asking the question - . Closing this to prevent a chorus of idiots piling on with useless and factually incorrect comments, as James did. Thanks to Charles and Brent B for being very helpful. This turns out not to be a Safari issue so I removed those tags.] $_SESSION is not getting set in Safari, and hence my multipage form breaks. $_POST, $

How to display an error when the uploaded files are exceeding post_max_size php?

吃可爱长大的小学妹 提交于 2019-12-13 17:37:01
问题 How to display an error when the uploaded files are exceeding post_max_size php? print_r($_FILES); I get an empty array when I have exceeded the post_max_size array() I got this from php.net but I don't understand it and don't know how to do it, If the size of post data is greater than post_max_size, the $_POST and $_FILES superglobals are empty. This can be tracked in various ways, e.g. by passing the $_GET variable to the script processing the data, i.e. , and then checking if $_GET[

$_SERVER['document_root']?

安稳与你 提交于 2019-12-11 04:02:12
问题 is this pointing to the directory where the current file is executed? 回答1: No, it points to the root of your webserver - the topmost folder of your website. If you want the directory of the current file, use: dirname(__FILE__); 回答2: From http://php.net/manual/en/reserved.variables.server.php 'DOCUMENT_ROOT' The document root directory under which the current script is executing, as defined in the server's configuration file. 回答3: Maybe, depending on how the server is set up. A much better

Unregistering Globals?

与世无争的帅哥 提交于 2019-12-11 02:42:49
问题 I'm having trouble understading this function. I know what register_globals is and how long it has been depreciated from PHP but I'm looking at this code and I'm like, what in the?... <?php //Undo register_globals function unregister_globals() { if (ini_get(register_globals)) { $array = array('_REQUEST', '_SESSION', '_SERVER', '_ENV', '_FILES'); foreach ($array as $value) { foreach ($GLOBALS[$value] as $key => $var) { if ($var === $GLOBALS[$key]) { unset($GLOBALS[$key]); } } } } } ?> The part

Getting $_GET parameters from route in Zend Framework 2

帅比萌擦擦* 提交于 2019-12-09 06:12:33
问题 Zend Framework 1 had a very simple way of parsing URL routes and setting found params in the $_GET superglobal for easy access. Sure, you could use ->getParam($something) inside the controller, but if the param was found in the URL, it was also accessible via $_GET. Example for url mypage.com/mymodule/mycontroller/myaction/someparam/5: ZF1 $this->getParam('someparam'); // 5 $_GET['someparam']; // 5 ZF2 $this->getEvent()->getRouteMatch()->getParam('someparam'); // 5 $_GET['someparam'] //

PHP Accessing the user's country (locale)

懵懂的女人 提交于 2019-12-08 17:51:27
Is there a superglobal reference to the user's country or is using the IP against a database of IP to Country lookups the best way to go? i wish there were such thing as $_SERVER['HTTP_COUNTRY'] ... maybe in php99 ? ;) for the time being, http://php.net/manual/en/book.geoip.php is your best bet however, if you're only interested in user's language, there is $_SERVER["HTTP_ACCEPT_LANGUAGE"] Here are some more options for ip to country lookups http://www.hostip.info/ http://pear.php.net/package/Net_Geo Here an example of how to get country code from the IP. It's not a PHP superglobal, but it's

$_REQUEST superarray not initialized in $GLOBALS array

独自空忆成欢 提交于 2019-12-08 09:10:54
问题 PROBLEM So, I have this function to retrieve and proceed data from $_REQUEST, $_POST, $_GET or $_COOKIE arrays. I know which array to use only from function call. Simplified ex: function gg( $name, $type="_REQUEST" ) { return isset( $GLOBALS[$type][$name] ) ? $GLOBALS[$type][$name] : false; } And it works perfectly for calls like: gg('var', '_GET'); gg('var2', '_POST'); But fails dramatically for: gg('var'); // or gg('var', '_REQUEST'); I managed to simplify this problem thou to 2 lines:

Measuring the time of PHP scripts - Using $_SERVER['REQUEST_TIME']

ぃ、小莉子 提交于 2019-12-02 02:27:49
问题 Are this methods a reliable way to measure a script: $time = ($_SERVER['REQUEST_TIME_FLOAT'] - $_SERVER['REQUEST_TIME']); or $time = (microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']); Which one should be used? And what's the difference of each one? They return very different measurements. 回答1: $time = ($_SERVER['REQUEST_TIME_FLOAT'] - $_SERVER['REQUEST_TIME']); This will never give you execution time of you PHP script. Because both the values are used for storing start of request . The

Checking if a $_COOKIE value is empty or not

牧云@^-^@ 提交于 2019-12-01 07:44:25
问题 I assign a cookie to a variable: $user_cookie = $_COOKIE["user"]; How can I check if the $user_cookie received some value or not? Should I use if (empty($user_cookie)) or something else? 回答1: Use isset() like so: if (isset($_COOKIE["user"])){ $user_cookie = $_COOKIE["user"]; } This tells you whether a key named user is present in $_COOKIE . The value itself could be "" , 0 , NULL etc. Depending on the context, some of these values (e.g. 0 ) could be valid. PS: For the second part, I'd use ===