redirect doesn't redirect without refresh

Reply

Join Date: Jun 2005
Posts: 3
Reputation: Juls is an unknown quantity at this point 
Solved Threads: 0
Juls Juls is offline Offline
Newbie Poster

redirect doesn't redirect without refresh

 
0
  #1
Jun 14th, 2005
Hi,

I have a login page that has a form that goes to processing page wich the has the logic that in case login fields are empty or invalid to redirect back to login page with result variable set to "badlogin". I ran it a couple times and it worked fine. Then all of a sudden: when I run it, the original login page doesn't reload after being redirected from processing. I have to hit refresh on a browser for it to come up.

[PHP]
Here is the code freom my processing page that redirects it:
$user = $_REQUEST["username"];
$pass = $_REQUEST["password"];
$logintype = $_REQUEST["logintype"];
if( "" == $pass || !preg_match( "^[a-zA-Z]+^", $pass ) ){
$error = 1;
}
if( 0 != $error ){

if ( $logintype == "admin" ) {
header( "Location: ../LoginAdmin.php?loginresult=badlogin" );
include( "../LoginAdmin.php" );
exit();
}

exit();
}[/PHP]
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 27
Reputation: Royalty Hosting is an unknown quantity at this point 
Solved Threads: 0
Royalty Hosting's Avatar
Royalty Hosting Royalty Hosting is offline Offline
Light Poster

Re: redirect doesn't redirect without refresh

 
0
  #2
Jun 14th, 2005
If it was working than maybe it could be you cache?
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 294
Reputation: zippee is an unknown quantity at this point 
Solved Threads: 6
zippee's Avatar
zippee zippee is offline Offline
Posting Whiz in Training

Re: redirect doesn't redirect without refresh

 
0
  #3
Jun 14th, 2005
replace the header script with javascript may solve the problem.
  1. //you php code here...
  2. ?>
  3. <script language="JavaScript" type="text/javascript">
  4. <!--
  5. window.location.href = "../your_page.php"
  6. //-->
  7. </script>
  8. <?php
  9. exit;
  10. // other php code
The include( "../LoginAdmin.php" ); will have to include in the forwarding page.
Ecommerce-Web-Store.com Building Your e-Business.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 26
Reputation: darklordsatan is an unknown quantity at this point 
Solved Threads: 1
darklordsatan's Avatar
darklordsatan darklordsatan is offline Offline
Light Poster

Re: redirect doesn't redirect without refresh

 
0
  #4
Jun 14th, 2005
First of all, I might be drunk, but the header() functions redirects right away to the given location, so theres no need to call exit() and the include() below wont have any effect; you might wanna take that in account first
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 2
Reputation: NomadFromRocks is an unknown quantity at this point 
Solved Threads: 0
NomadFromRocks NomadFromRocks is offline Offline
Newbie Poster

Re: redirect doesn't redirect without refresh

 
0
  #5
Jul 29th, 2005
Hey people .... i need your help!
I am having the same problem ....

I have tried cleaning up my cache memory.... apparently it doesn't help, because the second time I open the browser it responds in the same manner, by showing me the blank browser... which i need to refresh manually .

The wierd thing is that Mozilla Firefox is absolutely fine ... the same redirects work just fine. I have tried infinitely many times.... no problem, perfect.

But IE 6, for some reason, has problems with it....

I am using Header("Location: xxx.php"); to redirect to other page...

i have tried everything possible... even when i put header function as the first function in my code it shows me the damned blank page....

Before, I thought that the problem might be in sending HTTP headers... but i why then mozilla works just fine???


PLEEEEEEEEEEEEEEEZ
if anyone has a solution for the problemmm..... let me know
I appreciate your help....
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 45
Reputation: Sp!ke is an unknown quantity at this point 
Solved Threads: 0
Sp!ke's Avatar
Sp!ke Sp!ke is offline Offline
Light Poster

Re: redirect doesn't redirect without refresh

 
0
  #6
Jul 29th, 2005
Gah! Your PHP Code is an absolute disaster, sorry to say, and it hurts my eyes. This might help:
[php]<?php
// Here is the code from my processing page that redirects it:
$user = $_REQUEST['username'];
$pass = $_REQUEST['password'];
$logintype = $_REQUEST['logintype'];
// Gah! ALWAYS, when using preset variables, use
// single quotes inside brackets. PHP is more friendly,
// that way Also, are you trying to get this data
// from a form? You might want to change these to POST,
// and set the form in your HTML page to be POST, as well,
// but for now I'll just leave them as they are.

if($pass == '') {
// There is no point using preg if you're going to search for
// a-z and A-Z, it's easier to just use if($pass == '').
$error = 1;
};
if($error == 0) {
if ($logintype == 'admin') {
header('Location: ../LoginAdmin.php?loginresult=badlogin');

// include("../LoginAdmin.php" );
// Why are you including a page here? You've already
// been redirected to the other page!

exit;
// The 'exit;' command does not have parameters, therefore
// do not put parenthesis () after it.
};
exit;
};
?>[/php]If you are not being redirected to that page, you are doing something wrong, and by the looks of your PHP code, you are.

Also, if this is a user authentication form, I'd suggest using a database with usernames and passwords, simply testing if the user has entered a password is not secure at all, especially if you then redirect them to an Administration page. Troy has some good tutorials on the subject, you might want to get in touch with him.

Also, zippee, it is pointless to end your PHP script just so that Javascript can redirect you to a page, especially if PHP can do it for you. The correct way to redirect someone to a page:[php]<?php
header('Location: http://www.google.com/');
?>[/php]will redirect you to Google. This header(); function MUST be executed before any other headers are, otherwise you will get an error.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,039
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: redirect doesn't redirect without refresh

 
0
  #7
Jul 29th, 2005
Juls, your real problem is that the Location HTTP header must use an _absolute_ path. E.g. "Location: http://www.example.com/path/file.html" instead of "Location: ../file.html"
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 2
Reputation: NomadFromRocks is an unknown quantity at this point 
Solved Threads: 0
NomadFromRocks NomadFromRocks is offline Offline
Newbie Poster

Re: redirect doesn't redirect without refresh

 
0
  #8
Jul 30th, 2005
It seems like I got the way around this problem....

If you have any useless stuff in headers, like for example....
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

get rid of it... for some reason it worked for me.

Why people use all those w3c advised headers anyways???


hope I was helpful
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 45
Reputation: Sp!ke is an unknown quantity at this point 
Solved Threads: 0
Sp!ke's Avatar
Sp!ke Sp!ke is offline Offline
Light Poster

Re: redirect doesn't redirect without refresh

 
0
  #9
Jul 31st, 2005
Originally Posted by NomadFromRocks
If you have any useless stuff in headers, like for example....
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"> get rid of it... for some reason it worked for me.
Ahh, yes, that's right, many HTML editing programs, such as Macromedia Dreamweaver add that to every page, so removing it (since it is a header) will allow the Location Header to be sent, even with a relative link.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC