Page 1 of 1

Cookie problem (transfer variable from onepage to other)

Posted: Mon Nov 23, 2009 3:51 pm
by sumittyagi
I need to transfer a variable from one page to other using cookies, and I am having problems, Please help me with that.

the variable $user->getLogin() needs to be transferred.

PAGE 1

Code: Select all

 
<script language="Javascript">
function move() {
    window.location = 'http://schedfox.com/employee/test.php'
    }
    </script>
 
<?php include("include/configure.inc.php");
include(COM_PATH."admin/user.inc.php");
 
PostgresDriver::Open();
if(isset($_REQUEST['new'])) {
  $user = User::findByExternal($_REQUEST['new']);
}
 
if($user->getID()>0)
{
  //good
  setcookie("sessionid", $user->getLogin(), time() + 3600);
  echo "<SCRIPT LANGUAGE='javascript'>move();</SCRIPT>";
}
else{
 
  exit(1);
}
 
 
 
 
?>
 
 
 
PAGE 2

Code: Select all

 
<?php 
if (isset($HTTP_COOKIE_VARS['sessionid'])){
    
  echo "Welcome " . $HTTP_COOKIE_VARS['sessionid'] . "!<br />";
}
else
  echo "Welcome guest!<br />";
?>
 
 
 
Everytime I run this code, it says welcome guest, I dont know what happening. I have tried changing $HTTP_COOKIE_VARS to $_COOKIE
still it doesn't work.
Any ideas guys....
Thanks in Advance.

Re: Cookie problem (transfer variable from onepage to other)

Posted: Mon Nov 23, 2009 5:19 pm
by pickle
Well, you should definitely be using $_COOKIE rather than $HTTP_COOKIE_VARS, as $HTTP_COOKIE_VARS has been deprecated for years. Are you sure setcookie() is returning TRUE?

Re: Cookie problem (transfer variable from onepage to other)

Posted: Mon Nov 23, 2009 5:25 pm
by sumittyagi
Yeah setcookie is returning true. 100% sure. I changed it to $_COOKIE[], but still it doesn't work.

Re: Cookie problem (transfer variable from onepage to other)

Posted: Tue Nov 24, 2009 9:45 am
by pickle
Are the pages on the same domain?