page redirection problem on new server

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
doafee
Forum Newbie
Posts: 2
Joined: Tue Sep 26, 2006 6:31 pm

page redirection problem on new server

Post by doafee »

i built a user registration system on an old shared server account a couple months back that work like a peach. i transfered it to another server recently and i am experiencing inconsistent page redirecting. the problem is not consistent and seems to happen more in IE on windows (which doesnt make sense because its PHP).

the problem is that: ususally on the first attempt at logging in, the user will be redirected to a blank page (at the same URL as the directed from url) intead of my defined page (the redirect). then, when the user refreshes, it takes him to the correct page (directed to). the blank page has no errors and the url is the same as the "directed from" url (on refresh--it changes to the directed to url).

i checked the old server and it is running php4 and the new server is running php5. it seems to me like its a setting issue rather than a coding issue but i dont know--im new at this.

if anyone can help, i am deseprate.

thanks in advance.

Jeremy

in action
http://www.cittdesign.com/hazmat_boulder/main/login.php

user id: 111111111

i also had a blank screen pop up when submitting a new registration form (which happens if you insert a new 9 digit ID so try both)

here is the code for the login page:

Code: Select all

<?php

header("Expires: Thu, 17 May 2001 10:17:17 GMT");    
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 
header ("Cache-Control: no-cache, must-revalidate");  
header ("Pragma: no-cache");                          

session_start();

$title = "Please Login";

// If session has not been set with the session_init initialization file, set the session with the file
if (!isset($_SESSION['SESSION'])) {
	require ("../includes/session_init.php");
}
// if the variable $_SESSION['ID_PASS'] has been set, proceed to the registration screen
if ($_SESSION['ID_PASS']) {
	header("Location: registration.php");
	exit();
}

// Check if any form data has been submitted yet.
if (isset($_POST['submit'])) { 

	// Check for an ID equality.
	if ($_POST['idone'] == $_POST['idtwo']) {

		// If IDs are equal:
		// Check if input is less than required digits
		if (strlen($_POST['idone']) < $id_characters) {
			$_SESSION['ID_ERROR'] = $less_msg;
			$_SESSION['ID_PASS'] = FALSE;
			header("Location: login.php");
			exit();
			
		// Check if input is greater than required digits
		} else if (strlen($_POST['idone']) > $id_characters) {
			$_SESSION['ID_ERROR'] = $more_msg;
			$_SESSION['ID_PASS'] = FALSE;
			header("Location: login.php");
			exit();
			
		// Check if input has numeric digits only
		} else if (!is_numeric($_POST['idone'])) {
			$_SESSION['ID_ERROR'] = $char_msg;
			$_SESSION['ID_PASS'] = FALSE;
			header("Location: login.php");
			exit();
		} else { 
			$_SESSION['ID_PASS'] = TRUE;
			$_SESSION['ID'] = $_POST['idone'];
			header("Location: registration.php");
			exit();
		}
	// If IDs are unequal:
	} else { 
		$_SESSION['ID_ERROR'] = $unequal_msg;
		$_SESSION['ID_PASS'] = FALSE;
		header("Location: login.php");
		exit();
	}
	
// If no form data has been submitted, present screen for the first time
} else {

include($headerFile);
include($loginScreen);
include($footerFile);
}
?>
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Not sure if this is your problem, but you should be using full urls with the http redirect header IE:

Code: Select all

header("Location: http://www.somepage.com/page.php");
Fix those, and then we can move on from there.

Here is a function that will make redirects a little less redundant as well...

Code: Select all

function redirect($page){
    if(!headers_sent()){
        header("Location: " . $page);
    } else{
        echo "Click <a href='$page'>here</a> to continue"; //silly of course - better use meta+javascript+link - that way at least one of these methods will succeed, the link being the less useful.
    }
   exit;
}
doafee
Forum Newbie
Posts: 2
Joined: Tue Sep 26, 2006 6:31 pm

Post by doafee »

I completed the URLs and still no good. Eveidently some people are getting 404s as well. Here is a message from my hosting support team:

"Not Found, The requested URL /main/registration.php was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request."

why does this work for some people and not others. it works on my machine and all the others at my work flawlessly. anybody else having this issue? could IE be making my redirects go berzerk, it should be safe since its PHP right?

is there another way that i can do this without using redirects to make it universal?

Jeremy
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Always use full URL's. And make sure that the domain is accessible to the world. You know, like making sure you are not behind a firewall or something of that nature. Another thing to try is hitting the referenced URL by typing it into the address bar EXACTLY like it looks in your code.
Post Reply