Page 1 of 1
setcookie() not working
Posted: Mon Feb 14, 2005 12:45 pm
by guest
Code: Select all
<?php
session_start();
?>
<?php
if ($_REQUESTї"loggedin"] == "t") {s
setcookie("CG_login",$_REQUESTї"username"],time()*60*60*24*365);
echo "OK -".$_REQUESTї"username"];
}
if ($_COOKIEї"CG_login"] && $_REQUESTї"loggedin"] != "t") {
header("Location:Login/LoginSuccess.php?Username=".$_COOKIEї"CG_login"]);
}
else {
// OTHER CODE NOT SHOWN HERE
}
When I Send The Required Details Using The Query String - To Set The Cookie, It Says It Has Done It.
Yet When I Reload The Page, It Goes Straight Into The ELSE Bit
Why?
Posted: Mon Feb 14, 2005 12:50 pm
by feyd
your second part of the if expression requires $_REQUEST['loggedin'] to not equal 't' .. if you just reload the page, loggedin will still be 't' (a requirement of your setcookie() bit.
Posted: Mon Feb 14, 2005 2:14 pm
by guest
Reload -
Close The Window.
Open A New Window.
Type In The Adress (localhost/codeandgames/index2.php)
Posted: Tue Feb 15, 2005 2:28 pm
by guest
PLEASE! THIS IS IMPORTANT AS I COMPLETELY TRANSFORMING MY SITE FROM PHP TO MYSQL
Posted: Tue Feb 15, 2005 2:37 pm
by feyd
yelling gets you nowhere.

Posted: Tue Feb 15, 2005 3:52 pm
by d3ad1ysp0rk
Have you tried printing out any variables for debugging purposes?
Posted: Wed Feb 16, 2005 7:51 am
by guest
Yes.
When I Get Home (At A Different Computer Now), I Will Upload A ZIP File.
Anyone With Apache + MYSQL + PHP5 - Unzip This Into A Directory Of Your Choice, And Run The index2.php in your browser.
Inspect The Code A Bit, You Will Soon See My Problem. It Is In index2.php and Login/LoginSuccess.php
ZIP WILL BE POSTED AT APPROXIMATELY 4:45 PM GMT
Posted: Wed Feb 16, 2005 8:30 am
by Maugrim_The_Reaper
You should write out the process in steps - then compare that to your code.
Then you'll spot that when you set the cookie, the second if condition returns false - not true. Why? Because you seem to assume $_REQUEST["loggedin"] changes value by itself. Unfortunately PHP is not psychic - you need to unset this yourself.
Flowcharts are a great help - requires only paper, a pen and some ability to draw lines...

Posted: Wed Feb 16, 2005 2:47 pm
by guest
Tried That Before.
Tried A Whole Load Of Things Tonight.
Eventually, Decided To Do It In Trusty Old JavaScript.
So, Now I Have Got A Working System.
But I Still Wonder Why......
Posted: Wed Feb 16, 2005 3:03 pm
by shiznatix
is ur page in frames? cause u cant use cookies in frames
Posted: Sat Feb 26, 2005 11:55 am
by guest
Yes, It Was..........
Anyway, As I Said, I Used JavaScript, And It Works