Jump to content

[SOLVED] Cookie not set


catelee2u

Recommended Posts

Hi

I have a page and want to set 2 cookies. The first cookie seems to work whereas the second does not.

 

<?php
// Connect to Database 
$con = mysql_connect("localhost","username","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

//Checking username and password are correct
mysql_select_db("DB")or die("Cannot select DB");
$loginname = mysql_real_escape_string($_POST['loginname']);
$pwd = md5($_POST['loginpwd']);
$verify = mysql_num_rows(mysql_query("SELECT * FROM members WHERE loginname =  '$loginname'  AND loginpwd = '$pwd' "));
if  ($verify != 1 )
{die('Your username or password is incorrect.');} 

//redirect
header("Location: http://192.168.0.8/members.php"); 

           
//set cookie 2 hours (60*60*2=7200)


$period = 7200 + time();
setcookie("ST[username]", $_POST['loginname'] ,$period);

//Get id cookie
$getid = mysql_query("SELECT id FROM members WHERE loginname = '$loginname'");
$id =  mysql_fetch_array($getid, MYSQL_BOTH);
setcookie("ST[iD]", $id ,$period);
?>

 

I cannot figure out why the second cookie is not set.

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/180724-solved-cookie-not-set/
Share on other sites

Hi

Thankyou both. It took me a while to figure out what you meant but got there in the end. Thankyou very much it works now.

 

Now I have:

//Get id cookie
$getid = mysql_query("SELECT id FROM members WHERE loginname = '$loginname'");
$id = mysql_fetch_array($getid);

setcookie("STID", $id['id']);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.