PHP Empty Page
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Empty Page

  1. #1
    Join Date
    Aug 2017
    Posts
    5

    Question Empty Page

    Folks,


    Why does my login.php show a complete blank page ?
    Error reporting is set in the config.php but no errors are shown! Strange!


    site_details.php

    Code:
    <?php
    
    $site_name = "myworld";
    $social_network_name = "myworld";
    $site_domain = "EDITED";
    $site_admin_email = "myworld_admin@EDITED";
    $social_network_admin_email = "myworld_admin@EDITED";
    
    ?>

    login.php

    Code:
    <?php
    
    include 'config.php';
    
    // check if user is already logged in
    if (is_logged() === true) 
    {
    	//Redirect user to homepage page after 5 seconds.
    	header("refresh:5;url=home.php");
    }
    
    if ($_SERVER['REQUEST_METHOD'] == "POST")
    {
    	if (isset($_POST["login_username_or_email"]) && isset($_POST["login_password"]))
    	{
    		$username_or_email = trim(mysqli_real_escape_string($conn, $_POST["login_username_or_email"]));
    		$password = $_POST["login_password"];		
            //Hashed Password.
    		$hashed_password = password_hash($password, PASSWORD_DEFAULT);
    		
    		// Check if inputted Username is between 8 to 30 characters long or not. Or, if inputed Email is valid or not.
    		if ((strlen($username_or_email) < 8 || strlen($username_or_email) > 30) || (!filter_var($username_or_email, FILTER_VALIDATE_EMAIL)))
    		{
    			$_SESSION['error'] = "Your Username or Email is incorrect! If you input your Username, then it must be between 8 to 30 characters long.
    			If you input your Email, then it must be a valid one!";
    			exit;
    			}
    		// Check if Password is between 8 to 30 characters long or not.
    		elseif (strlen($password) < 8 || strlen($password) > 30) 
    		{
    			$_SESSION['error'] = "Password must be between 6 to 30 characters long!";
    			exit;
    		}
            
    		//Select Username and Email to check against Mysql DB if they are already registered or not.
    		$stmt = mysqli_stmt_init($conn);
    		if($stmt = mysqli_prepare($conn, "SELECT accounts_activations, usernames, emails, passwords FROM users WHERE passwords = ?"))
    		{
    			mysqli_stmt_bind_param($stmt, 's', $hashed_password);
    			mysqli_stmt_execute($stmt);
    			//$result = mysqli_stmt_get_result($stmt); //Use either this line, or ...
    			$result = mysqli_stmt_bind_result($stmt, $db_account_activation_state, $db_username, $db_email, $db_password); // ... this line. But not both.
    				
    			$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
    			mysqli_stmt_close($stmt);
    			
    			// Check if inputted Username or Email is registered or not.
    			//Either type following paragraph or the next one but not both. Ask in forum which one is best.
    			/* PARAGRAPH 1
    			if (($username_or_email == $row['usernames'] || $username_or_email == $row['emails']) && $hashed_password == $row['passwords']) // either this paragraph or ...
    			{
    				echo "IF Triggered";
    			}
    			else
    			{
    				if($row['accounts_activations'] == '0')
    				{
    					$error = "You have not activated your account yet! Check your email for instructions on how to activate it. Check your spam folder if you don;t find an email from us.";
    					exit;
    				}
    			}			
    			*/
    			
    			//PARAGRAPH 2
    			if (($username_or_email == $db_username || $username_or_email == $db_email) && password_verify($hashed_password, $db_password)) // ..... this paragraph. But not both.
    			{
    				echo "IF Triggered";
    			}
    			else
    			{
    				if($row['accounts_activations'] == '0')
    				{
    					$error = "You have not activated your account yet! Check your email for instructions on how to activate it. Check your spam folder if you don;t find an email from us.";
    					exit;
    				}
    			}
    			
    			
    			$_SESSION["user"] = $username;					
    			//If 'Remember Me' check box is checked then set the cookie.				
    			//if(!empty($_POST["login_remember"])) // Either use this line ....
    			if (isset($_POST['login_remember']) && $_post['login_remember'] == "on") // ...or this line. But not both!
    				{
    					setcookie("login_username_or_email", $username_or_email, time()+ (10*365*24*60*60));
    					setcookie("login_password", $login_password, time()+ (10*365*24*60*60));
    				}
    			else
    			{
    				//If Cookie is available then use it to auto log user into his/her account!
    				if (isset($_COOKIE['login_username_or_email']))
    				{
    					setcookie("login_username_or_email","","");
    				}
    				if (isset($_COOKIE['login_password']))
    				{
    					setcookie("login_password", "", "");
    				}
    			}
    		header("location:home.php");
    		}
    		else
    		{
    			$_SESSION['error'] = "That Username or Email is not registered!";
    			exit;
    		}
    	}
    }
    			
    ?>
    
    <!DOCTYPE html>
    <html>
    <head>
    <title><?php $site_name?> Member Login Page</title>
      <meta charset="utf-8">
    </head>
    <body>
    <div class = "container">
    <form method="post" action="">
    <center><h3><?php $site_name ?> Member Login Form</h3></center>
    <div class="text-danger">
    <?php
    if(isset($message))
    {
        echo $message;
    }
    ?>
    <div class="form-group">
    <center><label>Username/Email:</label>
    <input type="text" placeholder="Enter Username or Email" name="login_username_or_email" value="<?php if(isset($_COOKIE["login_username_or_email"])) echo $_COOKIE["login_username_or_email"]; ?>"</center>
    </div>
    <div class="form-group">
    <center><label>Password:</label>
    <input type="password" placeholder="Enter password" name="login_password" value="<?php if(isset($_COOKIE["login_password"])) echo $_COOKIE["login_password"]; ?>"></center>
    </div>
    <div class="form-group">
    <center><label>Remember Login Details:</label>
    <input type="checkbox" name="login_remember" /></center>
    </div>
    <div class="form-group">
    <center><input type="submit" name="login_submit" value="Login" class="button button-success" /></center>
    </div>
    <div class="form-group">
    <center><font color="red" size="3"><b>Forgot your password ?</b><br><a href="login_password_reset.php">Reset it here!</a></font></center>
    <center><font color="red" size="3"><b>Not registered ?</b><br><a href="register.php">Register here!</a></font></center>
    </form>
    </div>
    </body>
    </html>

    config.php

    Code:
    <?php
    
    /*
    ERROR HANDLING
    */
    declare(strict_types=1);
    ini_set('display_errors', '1');
    ini_set('display_startup_errors', '1');
    error_reporting(E_ALL);
    
    mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
    
    // session start
    if(!session_start()) {
    	session_start();
    }
    
    // include files
    include 'conn.php';
    include 'site_details.php';
    
    // include functions
    include 'functions.php';
    
    ?>

    functions.php

    Code:
    <?php
    // functions file
    
    /*
    * check if user is logged by checking if session named "user" isset
    * return true if session "user" exists or false if not exists
    */
    function is_logged() {
    	if (isset($_SESSION["user"]) && !empty($_SESSION["user"])) {
    		return true;
    	} else {
    		return false;
    	}
    }
    ?>

  2. #2
    Join Date
    Aug 2017
    Posts
    1

    Re: Empty Page

    Do you have error_reporting turned on? Might have an error somewhere causing it to fail.

  3. #3
    Join Date
    Aug 2017
    Posts
    5

    Re: Empty Page

    Issue was solved, But I cannot remember how.

Tags for this Thread

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)