Current location: Hot Scripts Forums » Programming Languages » PHP » Problem with page redirection


Problem with page redirection

Reply
  #1 (permalink)  
Old 12-10-03, 09:14 PM
Mailman's Avatar
Mailman Mailman is offline
Newbie Coder
 
Join Date: Nov 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Problem with page redirection

Hi all, hope someone can help!

First the environment: Running PHP on Windows 2000, for development.

Now the problems:

1) On my login script I'm trying to set a session variable using

<?php $_SESSION['logged'] = true; ?>

whenever I do this the variable still local only.

2) After setting the session variable I want to reload the page using

<?php header("Location: $URL); ?>

where url is a valid url. This give me a fatal error. That line is on top of any HTML and no output has been sent.

Is any body know why or what is wrong in both cases?

I assume it's an environment problem, but since I'm new to PHP I can't figure it out!

Thanks in advance.
Reply With Quote
  #2 (permalink)  
Old 12-11-03, 05:11 AM
fyrestrtr fyrestrtr is offline
Wannabe Coder
 
Join Date: Nov 2003
Posts: 191
Thanks: 0
Thanked 0 Times in 0 Posts
You need to use session_start(); before setting any session variables.

What "fatal error"? Remember that the URL has to contain http:// and the domain name (ie, needs to be a fully qualified URL), not just "file.html".
Reply With Quote
  #3 (permalink)  
Old 12-11-03, 05:48 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
Quote:
Originally Posted by fyrestrtr
You need to use session_start(); before setting any session variables.

What "fatal error"? Remember that the URL has to contain http:// and the domain name (ie, needs to be a fully qualified URL), not just "file.html".
well, I am not sure about this http:// part because I use the file name only and it works fine here ....
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #4 (permalink)  
Old 12-11-03, 07:56 AM
Mailman's Avatar
Mailman Mailman is offline
Newbie Coder
 
Join Date: Nov 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Wow thanks guys much appreciated. I duno what happen during the night with the header thing, my previous url was a valid full url, I just change it to this board url, to test and bang it works

As for the session I already use session_start() and it was not working. No wonder here are the lines I set/gather the value:

$_SESSION['logged'] = true;

if( $_SESSION['logged'] != true ){
code
}else{
code
}

I just notice that a boolean variable will return 1 or 0 so I should do this instead

if( $_SESSION['logged'] != 1 ){
code
}else{
code
}

thank you so much
Reply With Quote
  #5 (permalink)  
Old 12-11-03, 09:57 AM
whiteraider whiteraider is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Boolean could be better tested by
using === or !== as you'll find if you test strings or arrays that 0 and FALSE are different!

Also TRUE is any non-zero value, -1 is TRUE.

Last edited by whiteraider; 12-11-03 at 09:59 AM.
Reply With Quote
  #6 (permalink)  
Old 12-11-03, 11:13 AM
Mailman's Avatar
Mailman Mailman is offline
Newbie Coder
 
Join Date: Nov 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Problem Persist

Ok the problem persist with the session variable!

When I set the $_SESSION['logged']; variable from my index.php page, I'm still able to read it. When I go on a different page the variable is lost! is that the way session variable works in PHP?

I use session_start() on my index.php page, when I try to use it on different page it give me that error: Parse error: parse error, unexpected ';' in c:\inetpub\wwwroot\PHPProject\modules\logout.php on line 3

Where line 3 contain: session_start();

What I'm doing wrong?
Reply With Quote
  #7 (permalink)  
Old 12-11-03, 11:36 AM
hyjacked hyjacked is offline
Wannabe Coder
 
Join Date: Nov 2003
Location: New Brunswick, Canada
Posts: 174
Thanks: 0
Thanked 0 Times in 0 Posts
Not sure if this applies at all but:
Quote:
Note: As of PHP 4.3.3, calling session_start() while the session has already been started will result in an error of level E_NOTICE. Also, the second session start will simply be ignored.
Also check the lines above the one that is giving the error, maybe it is causing problems that only show up on that line.
__________________
hyjacked
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Only allowing original referrer to access a page fixafone123 PHP 3 05-28-04 04:42 AM
Unicode problem invisible Perl 2 12-03-03 08:05 AM
echo foriegn html in static page fergusom Everything Java 4 11-10-03 02:35 AM
Problem with CDONTS javadude2003 ASP 23 08-07-03 11:09 PM
preload an asp page Gurrutello ASP 1 06-24-03 08:12 PM


All times are GMT -5. The time now is 07:31 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.