"Redirect" Help

theknight571

Platinum Member
Mar 23, 2001
2,896
2
81
I'm working on an internal webiste that requires the user to sign-in.

Currently the login is page is called either without "parameters": loginpage.php If they are logging into the main page as default user.

Or with "parameters": loginpage.php?src=X (where X identifies the page they came from)

The code then looks like this:

/* verify login etc... */

if($_POST['src'] == "1")
{
echo '<META http-equiv="refresh" content="0;URL=http://.../page1.php">';
}
else
{
echo '<META http-equiv="refresh" content="0;URL=http://.../page2.php">';
}


The code works in IE but doesn't do anything in FireFox (most recent version).

Anyone know why it's not working in FF?

I'm sure there's probably a better way, but I still consider myself a novice with PHP, so I'm open to suggestions for better ways.

Thanks for the help.

Edit: Also on another page I have the page setup to refresh itself every minute... this also doesn't seem to work in FF... it's a meta refresh tag as well.

Also I checked the "WebDeveloper" plugin and meta redirect is not blocked... and it doesn't work with that plugin is disabled either.
 
Last edited:

Ka0t1x

Golden Member
Jan 23, 2004
1,724
0
71
I'm not sure what your code looks like for the pages but you could just as easily include the file from the loginpage.php, which would just dump the php into the current file.

Code:
if($_REQUEST['src']=='1'){
  include('/path/to/page1.php');
} else {
  include('/path/to/page2.php');
}

Or depending on the difference in coding, if minimal, just run the difference of code inside the brackets and put the like coding from both files below the if statement. That way both conditions are met and accomplished.

EDIT: I don't understand the reasoning on the page refresh, I would simply process the data as it comes through instead of forwarding to another page.

Edit2: It seems as if you want to verify the login, then redirect to the correct page.. You could use the include code posted above for that, or use a header redirect within PHP itself, as long as you don't send any information to the screen .. ie: echo/print.

http://php.net/header

That should do the trick.
 
Last edited:

theknight571

Platinum Member
Mar 23, 2001
2,896
2
81
Thanks for your help.

After much tinkering and testing I've come to the conclusion that it's not the redirect that's not working... it's my session variables.

After logging in I set a number of session variables, I then, on the page being redirected to, verify that the session variables are set, and if not, redirect them back to the login page. (Attempting to prevent direct access to the "core" pages).

So I was logging in, being redirected to the "core" page then immediately redirected back to the login page. It happened fast enough that I never noticed it hit the other page before sending me back the login screen.

Now I'm looking into the session variables issue... anyone have suggestions on that one while I look it up?

Thanks.
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
The easy way to figure out if it's client issue or server side is to look at the headers your browser is sending/receiving during the login process.

For firefox you can use the LiveHTTPHeaders plugin. You need to make sure your cookise are being set for the correct domain.
 

theknight571

Platinum Member
Mar 23, 2001
2,896
2
81
10 BANG HEAD ON DESK
20 GOTO 10

Ok... just for fun I tried a different PC... on that PC FireFox works but IE doesn't.

On the original PC I was able to figure out that the session_id was changing from screen to screen.

I'm still not sure why.

I'll look at the headers and see what they say.
 

theknight571

Platinum Member
Mar 23, 2001
2,896
2
81
OK... Got it figured out.

I moved the session_start() to the very beginning of the file and it works.

It never dawned on me that the html/head/etc html commands actually constituted output.

I had the session_start command before anything was echoed but not before the html/head "commands".

Thanks for everyone's help.