Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redirect works partially via Meta refresh tag...

Status
Not open for further replies.

Theseekers

Technical User
Jul 22, 2004
118
US
Hello everyone.

I have played around with redirecting feature with PHP 4.3.7 and found out that because I am running php with IIS 5; I can not use the header function for automatically redirecting my pages while maintaining the session cookies.

A tip has been provided in this forum (thank you very much) suggested that I use the Meta tags instead. I did and it works.....partially. Let me provide you a pseudo code and hope that some 1 will spot my mistake since I am fairly new to PHP.

I have 3 scripts (login, welcome, logout). My login script gets the user input through a form, test it to make sure that their credentials is all match up. If so, I redirect them to my welcome page via a meta tag as:

print '<Meta http-equiv="refresh" content="2; url=http://locahost/mywebserver/phpscripts/welcome.php">';

This is ok because I can see/print all the information using the session that was created in the login. However, when I issue the similar command (only change the welcome.php to logout.php) in the welcome scripts then what it does is to create an empty new session id and use it to fill in the blank on my logout page.

I don't quite understand what is happenning here??? Does the refresh imply that once you have refreshed, the browser will consider that there is not any current session cookies are available and create a new one ????

TIA for your time and help.....
 
I'm not sure I understand.

When you use a META tag to direct the browser to the welcome page, your session variables work. But when you use a META tag to direct the browser to a logout page, they does not?




Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Hi sleipnir214,

Yeap!!!. This is the case. Let me provide the sequence so you would see it more clearly (I hope.)

login redirect to welcome page - can print out every variables that I have set in login script via a session cookie

welcome redirect to logout page - can't print out any of those variable and a new session cookie is created with 0KB like the one I have encounter when using the header function.

The working session cookie is still there with all the infor but the browser uses the new and empty one as source. Am I missconfigured any thing in php, iis, or the ie6????

Thanks for your help Sleipnir214...

 
I see no reason why you can successfully use functions after using a redirect META tag to one site but not another site. The destination should make no difference.

Here's my testing scripts:

test_login_session.html
Code:
<html><body>
<form method="post" action="test_login_session1.php">
<input type="text" name="foo"><br>
<input type="text" name="bar"><br>
<input type="submit">
</form></body></html>

test_login_session1.php:
Code:
<?php
session_start();
$_SESSION['baz'] = 'fnord';

print '<html><head>';

if ($_POST['foo'] == 'a' && $_POST['bar'] == 'b')
{
	$_SESSION['foo'] = $_POST['foo'];
	$_SESSION['bar'] = $_POST['bar'];
	print '<meta http-equiv="refresh" content="1; url=test_login_session2.php">';
}
else
{
	print '<meta http-equiv="refresh" content="1; url=test_login_session3.php">';
}

print "</head><body></body></html>";
?>

test_login_session2.php:
Code:
<?php
session_start();
print "Good Login:";

include ('test_showsession.php');

?>

test_login_session3.php:
Code:
<?php
session_start();
print "Bad Login:";

include ('test_showsession.php');

?>

test_showsession.php: (included by the two previous scripts)
Code:
<?php
session_start();
print '<pre>';
print_r ($_SESSION);
?>

The redirect works for me, regardless of the script to which I am redirected.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Wow Sleipnier214,

You are truely a super PHPer.... and thanks for the example

I have gotten my code worked up to this point (as you have demonstrated) but my trouble is (if I may use your code example to point out my problem...) that in the test_login2 or 3 (does not matter which 1).php when I redirect to another page using meta tag; it does not use the current session id for the information that I want. Instead, it created another empty one and use it to provide the information which are blanks... I am blind on this......

Thank Sleipnier214....
 
Hi Sleipnier214,

Yes, that exactly what I did. Am I getting another issue with Microsoft product.....


Thanks for your help...
 
I don't know.

I modified these scripts:

test_login_session2.php:
Code:
<?php
session_start();

print '<html><head><meta http-equiv="refresh" content="3; url=test_login_session4.php"></head><body>';

print "Good Login:";

include ('test_showsession.php');

print '</body></html>';

?>

test_login_session3.php:
Code:
<?php
session_start();

print '<html><head><meta http-equiv="refresh" content="3; url=test_login_session5.php"></head><body>';

print "Bad Login:";

include ('test_showsession.php');

print '</body></html>';
?>

And created:

test_login_session4.php:
Code:
<?php
session_start();

print '<html><body>';

print "After Good Login:";

include ('test_showsession.php');

print '</body></html>';

?>

test_login_session5.php:
Code:
<?php
session_start();

print '<html><body>';

print "After Bad Login:";

include ('test_showsession.php');

print '</body></html>';
?>

But I still can't duplicate your problem. And I've tried with both IE and Opera. The difference between my installation and yours, however, is that I'm running PHP on a LAMP box.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Hi Sleipnir214,

That's ok. You have already help alots. I will do more reading to figure out why. I just hope that this is not another "cork" in iis that prevent me from doing this.

Again, thanks lot for your help.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top