Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

setcookie problems

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

setcookie problems

Postby WillemM » Sun Nov 24, 2002 10:30 am

I have this code:

Code: Select all

if(($username == 'testuser') && ($password == 'testpassword'))
{
  setcookie('userid',1,$cookie_life);
  header('Location: index.php');
}


When I use this, my cookie doesn't become set.
How can I solve this ?[/code]
WillemM
New php-forum User
New php-forum User
 
Posts: 3
Joined: Sun Nov 24, 2002 10:28 am

Re: setcookie problems

Postby WiZARD » Mon Nov 25, 2002 12:17 am

Hi!
Try this:
Code: Select all
if(($username == 'testuser') && ($password == 'testpassword'))
{
  setcookie("userid"',"1", time() - 3600);
  header('Location: index.php');
  exit;
}else
{
  setcookie("userid"',"0", time() - 3600);
  header('Location: index.php');
  exit;
}

As you see firstly your script nothing to do, couse one of your variable ($username or $password) not sets.
User avatar
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol

Postby WillemM » Mon Nov 25, 2002 3:10 am

OK my code does not generate anymore errors.

But when I go to page 2 I cannot read the cookie value anymore.

I do this:

Code: Select all
echo $_COOKIE['userid'];


It says something like: variable not set !
WillemM
New php-forum User
New php-forum User
 
Posts: 3
Joined: Sun Nov 24, 2002 10:28 am


Return to PHP coding => General

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot] and 4 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron