Page 1 of 1

Pulling information from cookies.

Posted: Tue Nov 19, 2002 6:03 am
by Jim
Hey all.

So here's the dealio -

I have two cookies that are set when one logs in to my page:

IamJim_user and IamJim_pass

This is the code I *tried* using to pull the information:

Code: Select all

<?
if($_COOKIE&#1111;'IamJim_user']) &#123;
	if($_COOKIE&#1111;'IamJim_pass']) &#123;
	$user_name = $_COOKIE&#1111;'IamJim_user'];
	$password = $_COOKIE&#1111;'IamJim_pass'];
	&#125;
&#125;
?>
I thought this would check for the first cookie, then find it and check for the second cookie, find it and then set those variables equal to the values of the cookies.

Later on in the script, I have

Code: Select all

<?
echo "Welcome '$user_name'!";
?>
And I get:

Welcome "! (for an example, visit http://www.empiregaming.net/iamjim and log in at the bottom of the script as aaa, pass: aaa.)

Any ideas?

Posted: Tue Nov 19, 2002 6:06 am
by volka
check wether there has been any cookie-data sent with

Code: Select all

echo '&lt;pre&gt;'; print_r($_COOKIE); echo '&lt;/pre&gt;';

Posted: Tue Nov 19, 2002 6:28 am
by Jim
Output comes from phpbb :P

Here's what I used to set the cookies. Maybe this code is incorrect?

Code: Select all

&lt;?php
	setcookie("IamJim_user" , $user_name , +3600);
	setcookie("IamJim_pass" , $password , +3600);
?&gt;

Posted: Tue Nov 19, 2002 6:36 am
by volka
this will mark the cookie as invalid one hour after January 1 1970 00:00:00 GMT ;)

take a look at the examples at http://www.php.net/manual/en/function.setcookie.php

Posted: Tue Nov 19, 2002 6:42 am
by mydimension
here is a quick way to do what you want, but you should still read what volka gave you.

Code: Select all

<?php
   setcookie("IamJim_user" , $user_name , time() + 3600);
   setcookie("IamJim_pass" , $password , time() + 3600);
?>
this adds one hour to the current time as the expiration date.