Page 1 of 1
Strange Variable Problem
Posted: Mon Apr 03, 2006 1:43 am
by faisy_master
Hi,
I have a server configured against a site and everything was fine until the server crashed. I had to re-configure the server with PHP-MySQL and the site is now successfully running.
Now there is a strange problem that there is a Session in the site which is set against the UserID when the user successfully signs in.
Now this session variable is assessed as [ $MM_UserID ] at certain points and it gives NULL at every point. Ofcourse, the variable should be assessed as "$_SESSION[MM_UserID]", but the previous developer has used it in the site as [$MM_UserID], and it actually worked fine previously.
Now either, there must be some setting in the PHP.ini file or else, can anyone of you please help me in this regard.
Either some change may be devised in PHP.ini file or I may assign the Session value to some Global Variable which can be assessed by all $MM_UserID's throughout the site.
Thanks.
Posted: Mon Apr 03, 2006 1:51 am
by RobertGonzalez
The following is taken from the PHP manual page for
session_register...
The PHP Manual wrote:If you want your script to work regardless of register_globals, you need to instead use the $_SESSION array as $_SESSION entries are automatically registered. If your script uses session_register(), it will not work in environments where the PHP directive register_globals is disabled.
Is register_globals off?
Posted: Mon Apr 03, 2006 5:46 am
by faisy_master
Thanks Eve, yeah this was actually the problem ... the register_globals was off in php.ini file.
As soon as it was 'On', the Variables were checked with the value.
I would be very thankful to you if you help me in one other issue.
There is a line as
Code: Select all
header(sprintf("Location: %s", "somepage.php"));
It is not working and does not redirect to the particular page. It moreover also gives the warning, which is
Code: Select all
Warning: Cannot modify header information - headers already sent by (output started at C:\Server\Apache2\htdocs\devServer\portal\stats\counter.inc.php:12) in C:\Server\Apache2\htdocs\devServer\portal\news\news.php
Now, can you help me in figuring it out that whether why it was previously working and not now?
Thanks and Regards.
Posted: Mon Apr 03, 2006 5:59 am
by JayBird
Posted: Mon Apr 03, 2006 7:17 am
by faisy_master
Thanks, but that post tells me the workout of the code ...
But actually I want to have the change which have cause this error ... because this code was previously running fine and appeared when PHP is re-installed.
There must be some changing needs to be done in PHP.ini file.
Posted: Mon Apr 03, 2006 8:19 am
by JayBird
its nothing to do with your php.ini.
The clue is int he error message "output already started"
My guess is you will have some whitespace or something outputting by accident
Posted: Mon Apr 03, 2006 8:25 am
by RobertGonzalez
faisy_master wrote: ... the register_globals was off in php.ini file. As soon as it was 'On', the Variables were checked with the value.
I would suggest you rewrite your code and leave register_globals off. Search these forums (or google) for the term "register_globals" to see why.
faisy_master wrote:
There is a line as
Code: Select all
header(sprintf("Location: %s", "somepage.php"));
It is not working and does not redirect to the particular page. It moreover also gives the warning, which is
Code: Select all
Warning: Cannot modify header information - headers already sent by (output started at C:\Server\Apache2\htdocs\devServer\portal\stats\counter.inc.php:12) in C:\Server\Apache2\htdocs\devServer\portal\news\news.php
The
header function will not work if any output has been sent to the browser before header() is called. Look at counter.inc.php, somewhere on line 12 I would guess there is an echo or something that is meant to display in the browser. The error message is PHP's way of telling you that you tried to use header() AFTER your script began output to the browser.
Posted: Mon Apr 03, 2006 1:14 pm
by Benjamin
Actually I think you can enable output buffering in php.ini. Have another look.
Posted: Mon Apr 03, 2006 1:40 pm
by RobertGonzalez
Yeah, output buffering can handle this issue also. But for redirects, my typical logic is that if the user needs to be redirected, this should be known by the app and done before the need to output anything to the browser. For other header parameters output buffering is a useful tool.