Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

issue reading $_COOKIE a second time.

Status
Not open for further replies.

CliffLandin

Programmer
Nov 14, 2004
81
US
I am having an issue reading the value from a cookie that I had no problem reading in an earlier page. I have a sign in page that sets a cookie when you sign in. If you then return to the sign in page during the session it will redirect you to the next page, no sign in required.
The cookie holds the value of the users name and I would like to read from it on other pages. It works fine on the signin page, but doesn't want to work after that.

here is how I am setting the cookie and reading the cookie:
SETTING THE COOKIE:
else{
setcookie("tlconc",$user, 0, "/");
header("Location: }

READING THE COOKIE:

$user = $_COOKIE["tlconc"];

Like I said, the first time that I read it it works fine but then nothing. What am I doing wrong?

Thanks for any help that you can offer.

When in doubt, go flat out!

 
From the lack of responses I must assume that I am asking the wrong question or no one has the answer. I doubt that no one has the answer so then perhaps I can ask the question better. Hmm...

When in doubt, go flat out!

 
Sorry, noone has taken to your question yet.
Alas, here we go.

I would recommend to use a session rather than a cookie. The session resides server side and is safer than a cookie which can be issues by anyone who is able to send headers.

All pages contain session_start(). The session ID is transferred with a cookie - bu tyou don't have to worry about that, PHP takes care of it.
Assign the login variable to $_SESSION['whatever'] and it will be available in all scripts that share the session.

Setting cookie by 'hand' often creates issues with timeout, where the cookie is valid etc. I'd go for the session.

To answer the question:
register_globals has nothing to do with bein able to read cookies.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top