Can't send value with Session

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
md7dani
Forum Newbie
Posts: 13
Joined: Fri Oct 23, 2009 1:55 am

Can't send value with Session

Post by md7dani »

When I pass the value to another page with session_register the wrong value is printed. When I do the same thing by passing the value in the URL it works perfectly. So why can't I send it with Session??

I have another value, a $_COOKIE value. Maybe it's not possible to receive both a cookie and a session on the same page?

I use this code:

Code: Select all

//**** index.php ***
session_start(); // start up your PHP session! 

$username = "Superman";
session_register("username"); 

//**** shop.php ***
$name = $_SESSION['username'];
Do you see any errors?
iansane
Forum Commoner
Posts: 62
Joined: Sun Apr 18, 2010 1:26 pm

Re: Can't send value with Session

Post by iansane »

Hi,

session_register is deprecated depending on which version of php you are using.

http://php.net/manual/en/function.session-register.php

This is the newer way,

Code: Select all

//**** index.php ***
session_start(); // start up your PHP session!

$username = "Superman";
$_SESSION['username'] = $username;

//**** shop.php ***
$name = $_SESSION['username'];

They're all stored in array form ie.($_SESSION['username'], $_SESSION['password'], $_SESSION['email'] etc.) Like $_POST
wangxiaoyu
Forum Newbie
Posts: 4
Joined: Mon Sep 06, 2010 2:16 am

Re: Can't send value with Session

Post by wangxiaoyu »

maybe your register_globals is disabled.
Post Reply