Reply to Re: question about using "global" on one page then using the variable on another page

Your name:

Reply:


Posted by Jerry Stuckle on 04/05/07 22:11

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.
jstucklex@attglobal.net
==================

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация