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

cookie problems

Status
Not open for further replies.

dazza12345

Programmer
Nov 25, 2005
35
GB
Hi, I hope someone can help me out with this problem as its starting to seriously bug me.

Right, the following code is the first thing in my php script:

<?
$logusername = $_POST['logusername'];
$logpassword = $_POST['logpassword'];

if ($logusername != ""){
ob_start();
setcookie("bewiseusername", $logusername, time()+3600);
setcookie("bewisepassword", $logpassword, time()+3600);
ob_end_flush();
echo"SAVE COOKIE";
}

$bewiseusername = $logusername;
$bewisepassword = $logpassword;

if ($bewiseusername == ""){
echo "GET VALUSE FROM COOKIE";
$bewiseusername = $HTTP_COOKIE_VARS["BewiseBetsusername"];
$bewisepassword = $HTTP_COOKIE_VARS["BewiseBetspassword"];
}

What will happen is; a user will enter their username + password (using a form) then will click 'login' button which will call the same script again (using $_SERVER['PHP_SELF'];).

Im trying to get the username and password saved into two cookies. This is not as easy as I first thought. Once the user clicks the submit button, the username and password are saved into the two varables ($logusername and $logpassword) and 'cookie saved' is outputted onto the screen.

However, the cookie does not seem to want to save. In another php script, I have put the following code:

<?
if(isset($_COOKIE['bewiseusername'])) {
echo "cookie exists";
}
else {
echo "cookie dont exists";
}
?>

Every time, it will output "cookie dont exist". I really have no idea what is going wrong with saving the cookie. Anyone with any additional knowledge of setting cookies, PLEASE, PLEASE HELP.

Kind Regards
Daryl
 
You should set all the parameters for the cookie - just to be sure (path and domain).
Also note that there are 'designed' flaws in IIS when a 302 header is issued to redirect to a different page. In that case cookies are silently dropped.
 
Status
Not open for further replies.

Similar threads

Replies
21
Views
252
Replies
2
Views
96
Replies
2
Views
63

Part and Inventory Search

Sponsor

Back
Top