SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Apr 2011
    Location
    South Africa
    Posts
    24
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Blank page after logging in

    Hello everyone,

    I hope someone can help me with this as I'm a bit stumped. I moved my website (everything worked perfectly) to another domain and now something strange happens when I log in.

    I type in my username and password (into admin_login.php) and press Enter.
    Then a blank page appears (index.php).
    When I press the Back button, I'm on the correct page and I'm logged in.

    I don't know why the page is blank at first. Does anyone have any ideas?

    This is my php code for both pages:

    admin_login.php:

    HTML Code:
    <?php 
    	session_start();
    	if (isset($_SESSION["manager"])) {
        header("location: index.php"); 
        exit();
    	}
    ?>
    
    <?php 
    	// Parse the log in form if the user has filled it out and pressed "Log In"
    	if (isset($_POST["username"]) && isset($_POST["password"])) {
    
    	$manager = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["username"]); // filter everything but numbers and letters
        $password = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["password"]); // filter everything but numbers and letters
    
    	// Connect to the MySQL database  
        include "../storescripts/connect_to_mysql.php"; 
        $sql = mysql_query("SELECT id FROM admin WHERE username='$manager' AND password='$password' LIMIT 1"); // query the person
      
    	// Make sure the person exists in the database
        $existCount = mysql_num_rows($sql); // count the row nums
        if ($existCount == 1) { // evaluate the count
    	     while($row = mysql_fetch_array($sql)){ 
                 $id = $row["id"];
    		 }
    		 $_SESSION["id"] = $id;
    		 $_SESSION["manager"] = $manager;
    		 $_SESSION["password"] = $password;
    		 header("location: index.php");
             exit();
        } else {
    		echo 'The information is incorrect, please try again. <a href="index.php">Click Here</a>';
    		exit();
    	}
    	}
    ?>
    index.php:

    HTML Code:
    <?php 
    	session_start();
    	if (!isset($_SESSION["manager"])) {
        header("location: admin_login.php"); 
        exit();
    	}
    
    	// Be sure to check that this manager SESSION value is in fact in the database
    	$managerID = preg_replace('#[^0-9]#i', '', $_SESSION["id"]); // filter everything but numbers and letters
    	$manager = preg_replace('#[^A-Za-z0-9]#i', '', $_SESSION["manager"]); // filter everything but numbers and letters
    	$password = preg_replace('#[^A-Za-z0-9]#i', '', $_SESSION["password"]); // filter everything but numbers and letters
    
    	// Run mySQL query to be sure that this person is an admin and that their password session 
    	// var equals the database information
    
    	// Connect to the MySQL database  
    	include "../storescripts/connect_to_mysql.php"; 
    	$sql = mysql_query("SELECT * FROM admin WHERE id='$managerID' AND username='$manager' AND password='$password' LIMIT 1"); // query the person
    
    	// Make sure this person exists in the database
    	$existCount = mysql_num_rows($sql); // count the row nums
    	if ($existCount == 0) { // evaluate the count
    	echo "Your login session data is not on record in the database.";
        exit();
    	}
    ?>
    Any help/ideas would be much appreciated.

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    Capitalize the L in location? (Sometimes it really is something that silly.)

    Also, follow the WPSE steps listed in the "Common PHP Problems" thread at the top of this forum. See if it spits an error out at you.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Member
    Join Date
    Apr 2011
    Location
    South Africa
    Posts
    24
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thank you very much StarLion, I followed these steps and it fixed the problem:

    Place this at the top of your page:
    <? ob_start(); ?>

    And this at the bottom of your page:
    <? ob_flush(); ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •