The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Cookies in PHP, real examples?
Discuss Cookies in PHP, real examples? in the PHP Development forum on Dev Shed. Cookies in PHP, real examples? PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

March 30th, 2000, 10:19 PM
|
|
Contributing User
|
|
Join Date: Feb 2000
Posts: 43
Time spent in forums: < 1 sec
Reputation Power: 14
|
|
|
I am trying to get a handle on setting and retrieving cookies. I think I might have it down, but I'm not sure... if anyone can help, please reply.
to set a cookie, I have only two variables, the user name ($user) and their password ($password)... okay, so I want to set this cookie after they logon.
I use: (this is more of a question than a statement)
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
setcookie("username",$user,time()+31536000);
setcookie("password",$password,time()+31536000);
[/code]
and this should set the cookie(s), right? I think this should go before the <html> or <head> tags in my page (so basically, the VERY first thing in my page should be this, if I'm setting the cookies)
To retrieve the cookies, I use : (again, another question based statement)
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
....
[/code]
okay, so I don't know how to retrieve information from the cookie.
Any help would be greatly appreciated, correcting my setcookie code, and completing my retrieval information. I am kinda new to php, not totally dumb to programming, but lost on cookies <G>
Thanks,
Mike
|

March 31st, 2000, 12:06 AM
|
 |
.Net Developer
|
|
Join Date: Feb 2000
Location: London
Posts: 987
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 14
|
|
|
your setup cookie is correct..
i am writing an easy example for cookie:
setcookie("CookieID", $USERID);
To retrieve the cookies from above example you can use..
print $CookieID;
ie,Name of the cookie..
|

March 31st, 2000, 05:38 AM
|
|
Contributing User
|
|
Join Date: Feb 2000
Posts: 43
Time spent in forums: < 1 sec
Reputation Power: 14
|
|
|
Alright, so if the top of my web page looked like this:
<?php3
setcookie("username",$user,time()+31536000);
setcookie("password",$pwrd,time()+31536000);
?><HTML><HEAD> ...........rest of page ....
that would set my cookie, and later in the site I use $username and $password as my variables to reference their cookie? There's no "getcookie" function or anything?
Thanks,
Mike
------------------
|

April 4th, 2000, 10:28 AM
|
|
Contributing User
|
|
Join Date: Dec 1999
Location: Netherlands
Posts: 77
Time spent in forums: < 1 sec
Reputation Power: 14
|
|
|
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by mmccue:
Alright, so if the top of my web page looked like this:
<?php3
setcookie("username",$user,time()+31536000);
setcookie("password",$pwrd,time()+31536000);
?><HTML><HEAD> ...........rest of page ....
that would set my cookie, and later in the site I use $username and $password as my variables to reference their cookie? There's no "getcookie" function or anything?
Thanks,
Mike
[/quote]
Hi Mike,
If the cookies have been set, then you can simply refer to their values in other php pages (within the same domain/directory the cookie is set in) with the variables $username and $password.
Try this to see whether the cookies are there:
Make a file (viewcookie.php3 or so), like:
<?
if(isset($username) and isset($username))
{
print $username . "<BR>n";
print $password . "<BR>n";
}
else { print "No cookies have been set!"; }
?>
Have a nice meal!
Peter
[This message has been edited by PAV (edited April 04, 2000).]
|

April 5th, 2000, 04:45 AM
|
|
Contributing User
|
|
Join Date: Feb 2000
Posts: 43
Time spent in forums: < 1 sec
Reputation Power: 14
|
|
|
Thanks both of ya for your help... I played with it, and got it to work on my third or fourth try.... Kept forgetting the "+" after the "time()" statement....
Just wanted to let ya know your help is appreciated.
Mike
------------------
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|