944,112 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 11393
  • PHP RSS
Jun 14th, 2005
0

redirect doesn't redirect without refresh

Expand Post »
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]
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Juls is offline Offline
3 posts
since Jun 2005
Jun 14th, 2005
0

Re: redirect doesn't redirect without refresh

If it was working than maybe it could be you cache?
Reputation Points: 10
Solved Threads: 0
Light Poster
Royalty Hosting is offline Offline
27 posts
since Jun 2005
Jun 14th, 2005
0

Re: redirect doesn't redirect without refresh

replace the header script with javascript may solve the problem.
PHP Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 7
Posting Whiz in Training
zippee is offline Offline
294 posts
since Jan 2005
Jun 14th, 2005
0

Re: redirect doesn't redirect without refresh

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
Reputation Points: 10
Solved Threads: 1
Light Poster
darklordsatan is offline Offline
26 posts
since Jun 2005
Jul 29th, 2005
0

Re: redirect doesn't redirect without refresh

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....
Reputation Points: 10
Solved Threads: 0
Newbie Poster
NomadFromRocks is offline Offline
2 posts
since Jul 2005
Jul 29th, 2005
0

Re: redirect doesn't redirect without refresh

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.
Reputation Points: 14
Solved Threads: 0
Light Poster
Sp!ke is offline Offline
45 posts
since Jul 2005
Jul 29th, 2005
0

Re: redirect doesn't redirect without refresh

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"
Team Colleague
Reputation Points: 1135
Solved Threads: 172
Super Senior Demiposter
Rashakil Fol is offline Offline
2,479 posts
since Jun 2005
Jul 30th, 2005
0

Re: redirect doesn't redirect without refresh

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
NomadFromRocks is offline Offline
2 posts
since Jul 2005
Jul 31st, 2005
0

Re: redirect doesn't redirect without refresh

Quote 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.
Reputation Points: 14
Solved Threads: 0
Light Poster
Sp!ke is offline Offline
45 posts
since Jul 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: PHP Includes +
Next Thread in PHP Forum Timeline: Simple Subform?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC