Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php $_REQUEST doesn't contain cookies

Tags:

php

iis-7.5

I have some simple code like this:

<?php
setcookie("user","test", time() + 3600);
echo $_REQUEST['user']."<br>";
echo $_COOKIE['user'];
?>

and this is the result:

Notice: Undefined index: user in D:\interpub\wwwroot\live\cookie.php on line 3 
test

I'm running it on IIS 7.5. I've reloaded the page and I'm sure the browser sends the cookie to the php file (because I have it in $_COOKIE). So why doesn't $_REQUEST contain that cookie?

like image 843
esihaj Avatar asked Jan 19 '12 15:01

esihaj


People also ask

What is $_ cookies in PHP?

A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values.

What is $_ request in PHP?

PHP $_REQUEST is a PHP super global variable which is used to collect data after submitting an HTML form. The example below shows a form with an input field and a submit button. When a user submits the data by clicking on "Submit", the form data is sent to the file specified in the action attribute of the <form> tag.

How we can get the cookie values in PHP?

Accessing Cookies ValuesThe PHP $_COOKIE superglobal variable is used to retrieve a cookie value. It typically an associative array that contains a list of all the cookies values sent by the browser in the current request, keyed by cookie name.

How do you check if a cookie is set?

Right-click and click on Inspect Element to open the developer console. Go to the Storage tab. Expand the Cookies menu and select the website to check cookies. On the right side of the console, you will see the cookies that have been set on the website.


1 Answers

$_REQUEST on newer PHP setups contains only $_GET and $_POST.

With the typical PHP 5.3 php.ini $_COOKIE is excluded from there by request_order=GP.
See http://php.net/manual/en/ini.core.php#ini.request-order
And http://php.net/manual/en/ini.core.php#ini.variables-order

like image 166
mario Avatar answered Oct 05 '22 05:10

mario