By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,569 Members | 1,386 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,569 IT Pros & Developers. It's quick & easy.

question about using "global" on one page then using the variable on another page

P: n/a
I am taking over an exisitng app. I have the following function on one
page:

function check($v) {
global $user;
return $user->validate($v[1], $v[0]);
}

And it reference $user on the next page. Register_globals are set on the
existing server but I am moving to a new server where it is not. The code
of the next page is lilke:

session_register('user');
$user=$_SESSION['user'];

I also want to turn it around so it's:
$_SESSION['user'] = $user;

But that fails - $user is empty. By the way, $user is an object.

Any ideas to how to make sure:
$_SESSION['user'] = $user;

works on the second page?
Apr 5 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Paul wrote:
I am taking over an exisitng app. I have the following function on one
page:

function check($v) {
global $user;
return $user->validate($v[1], $v[0]);
}

And it reference $user on the next page. Register_globals are set on the
existing server but I am moving to a new server where it is not. The code
of the next page is lilke:

session_register('user');
$user=$_SESSION['user'];

I also want to turn it around so it's:
$_SESSION['user'] = $user;

But that fails - $user is empty. By the way, $user is an object.

Any ideas to how to make sure:
$_SESSION['user'] = $user;

works on the second page?

First of all, you don't need to call session_register(). Just set the
value in $_SESSION.

And ensure you are calling session_start() before *any* output (even
white space) on both pages.

If it still fails, enable all errors and display them. See if you're
getting any (errors, that is :-) ). If not, echo $user just before you
put in $_SESSION and see what's there. Also, in the second page, try

echo "<pre>\n";
print_r($_SESSION);
echo "</pre>\n";

to see what's actually in your $_SESSION superglobal.

It does work just fine.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 5 '07 #2

P: n/a
On 5 apr, 19:28, "Paul" <l...@invalid.comwrote:
And it reference $user on the next page. Register_globals are set on the
existing server but I am moving to a new server where it is not. The code
of the next page is lilke:

session_register('user');
$user=$_SESSION['user'];

I also want to turn it around so it's:
$_SESSION['user'] = $user;

But that fails - $user is empty. By the way, $user is an object.

Any ideas to how to make sure:
$_SESSION['user'] = $user;

works on the second page?
Like Jerry said, drop the session_register(). Also, on the original
page you'd have to put the object in the session, not in the second
page. So:

First page:
$_SESSION['user'] = $user;

And then you can use it on the next page (if the object hasn't got
recursive/self-referencing qualities).

--
Rik
"Why break one foot if you've got two of them?"

Apr 6 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.