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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cookies sometimes works?!!

Status
Not open for further replies.

thenewa2x

Programmer
Joined
Dec 10, 2002
Messages
349
Location
US
When I visit my site after I login and save my session data in a cookie (not PHP session, but my own), let say at:

I am logged in already, that's what I want. But when I start surfing my site, for example:

I am no longer logged in because my program could not retrieve the cookie data from my browser. I realized that when a query string exists, the HTTP_COOKIES variable in the _SERVER array disappears. I don't know why this happens. Does anyone have any idea?

---------------------------------------
If you helped... thx.
 
Hmm, why dont you just use SESSIONS?
It's VERY easy! You can specify a timeout on the session too!
 
Check the path for which your cookie is valid.


But as DaButcher has said, PHP's sessions are easy to use and more secure than storing sensitive data in a cookie.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
My problem was with PHP sessions before this. I just wrote a work around. Thx for the help anyway!

---------------------------------------
If you helped... thx.
 
thenewa2x:
what was your problems with sessions?

maybe you used some out-dated functions for sessions?
did you forget to start the session on each page?
 
The very first thing any of my scripts did was start the session. Cookies were set but once there was content in the QUERY_STRING environment variable, cookies could not be accessed and therefore could not access the PHPSESSID cookie. Not only that but PHP isn't parsing the href tags in my output to include the SID. Later i added them but it still didn't work so I said, "The heck with it, I'll write my own.". Member's logging and staying logged in was a major issue.

---------------------------------------
If you helped... thx.
 
example of session pages:
Code:
[b]// code for page1.php[/b]
<?php
// always start session fist!
session_start();

$_SESSION['unam'] = "leroy brown";

echo "<a href=\"page2.php?{SID}\">Page 2</a>";
?>

[b]// code for page2.php[/b]
<?php
// always start session fist!
session_start();

echo $_SESSION['unam'];
?>

if you use forms, simply do it like this:
<form action="page.php?<?=SID?>" method="post">

if this does not work, try specifying a new path for saving sessions in.

ref:
I hope this will work for you, as it's very easy to use and also works great!

Olav Alexander Mjelde
Admin & Webmaster
 
Thx

---------------------------------------
If you helped... thx.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top