| | |
redirect doesn't redirect without refresh
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jun 2005
Posts: 3
Reputation:
Solved Threads: 0
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]
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]
replace the header script with javascript may solve the problem.
The include( "../LoginAdmin.php" ); will have to include in the forwarding page.
PHP Syntax (Toggle Plain Text)
//you php code here... ?> <script language="JavaScript" type="text/javascript"> <!-- window.location.href = "../your_page.php" //--> </script> <?php exit; // other php code
Ecommerce-Web-Store.com Building Your e-Business.
•
•
Join Date: Jul 2005
Posts: 2
Reputation:
Solved Threads: 0
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....
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....
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.
[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.
Geek and a Half Blog
•
•
Join Date: Jul 2005
Posts: 2
Reputation:
Solved Threads: 0
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

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
•
•
•
•
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.
Geek and a Half Blog
![]() |
Similar Threads
- Buy Targeted Traffic, higher ROI (Ad Space for Sale)
- Quick Help for Cookie script? (JavaScript / DHTML / AJAX)
- piping urgent help (C++)
- How do i set a page as a Home Page (HTML and CSS)
- Form not sending email (PHP)
- DANI WEB ABOUT DOGS???? and webart about dogs. (DaniWeb Community Feedback)
Other Threads in the PHP Forum
- Previous Thread: PHP Includes +
- Next Thread: Simple Subform?
| Thread Tools | Search this Thread |
.htaccess alerts apache api archive array autocomplete beginner binary broken cakephp checkbox class cms code convert cron curl database dataentry date display duplicates dynamic echo email emptydisplayvalue error execute explodefunction file files firstoptioninphpdroplist folder form forms function functions google hack href htaccess html htmlspecialchars image include insert ip javasciptvalidation javascript joomla keywords limit link login mail matching menu methods mlm multiple mysql network object oop paypal pdf php problem query radio random recursion recursive redirect remote script search securephp server sessions shot sms source space sql subscription syntax system table tutorial tutorials update upload url validator variable video web youtube






