Cookie problem (transfer variable from onepage to other)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sumittyagi
Forum Newbie
Posts: 16
Joined: Wed Sep 09, 2009 3:28 pm

Cookie problem (transfer variable from onepage to other)

Post 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.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

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

Post 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?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
sumittyagi
Forum Newbie
Posts: 16
Joined: Wed Sep 09, 2009 3:28 pm

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

Post by sumittyagi »

Yeah setcookie is returning true. 100% sure. I changed it to $_COOKIE[], but still it doesn't work.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

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

Post by pickle »

Are the pages on the same domain?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply