I wanna cookie, please.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lexx
Forum Newbie
Posts: 21
Joined: Sat Jun 08, 2002 10:30 pm

I wanna cookie, please.

Post by lexx »

Hehe I know that there are whole bunch of tutorials on cookies on stuff but I dont get them. So can someone write me a code for cookie that stores $user and $password and expires in 1 hour and code that gets $user and $password from that cookie. comments in the code are very welcomed.

Thanks for any help.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

This is not a script-writing service, if you are looking for pre-made scripts go to http://www.hotscripts.com, if you want to pay someone to write your scripts for you go to the Jobs Forum.

Mac
lexx
Forum Newbie
Posts: 21
Joined: Sat Jun 08, 2002 10:30 pm

Post by lexx »

But I wanna cookie :(
Ok thanks
lexx
Forum Newbie
Posts: 21
Joined: Sat Jun 08, 2002 10:30 pm

Post by lexx »

At least help me understand it...

<?

//Write a cookie.php
$user_name="me";
$user_password="knocking";
$user_input="$user_name,$user_password";
setcookie("login",$user_input,time()+600);
// Cookie name "login" is dded to users computer containing "$user_input
// right?

?>

How do you get "$user_input" from that cookie?
User avatar
RandomEngy
Forum Contributor
Posts: 173
Joined: Wed Jun 26, 2002 3:24 pm
Contact:

Post by RandomEngy »

Code: Select all

$cookie_array = array(
  "user" => $username,
  "pass" => $password );
set_cookie("login",serialize($cookie_array),time()+600);
Would create a 10 minute cookie. To get the values out,

Code: Select all

$cookie_output_array = unserialize($_COOKIE&#1111;'login']);
$username = $cookie_output_array&#1111;'user'];
$password = $cookie_output_array&#1111;'pass'];
You could also use explode() and implode() if you don't need to use an associative array.
lexx
Forum Newbie
Posts: 21
Joined: Sat Jun 08, 2002 10:30 pm

Post by lexx »

the set cookie works but the other thing doesnt...?
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Hey

Post by Takuma »

Which script wasn't working?

P.S. If you want a cookie go and buy it :lol:
lexx
Forum Newbie
Posts: 21
Joined: Sat Jun 08, 2002 10:30 pm

Post by lexx »

Code: Select all

&#1111;quote]$cookie_output_array = unserialize($_COOKIE&#1111;'login']); 
$username = $cookie_output_array&#1111;'user']; 
$password = $cookie_output_array&#1111;'pass'];&#1111;/quote]
echo $username;
echo $password;

Nothing happends
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

lexx wrote:

Code: Select all

cookie_output_array = unserialize($_COOKIE&#1111;'login']); 
$username = $cookie_output_array&#1111;'user']; 
$password = $cookie_output_array&#1111;'pass']
echo $username;
echo $password;

Nothing happends
Have you set the cookie, "login"? And also what does $_COOKIE["login"] return?
Post Reply