Jump to content

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']);

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.