Jump to content

johnwalsh1020

New Members
  • Posts

    1
  • Joined

  • Last visited

Posts posted by johnwalsh1020

  1. On 11/28/2018 at 11:29 PM, phpsane said:

    Mac & Req,

    Here is the full script. Not finished yet. Especially, html form part.

    ISSUE: 1.
    I am having one problem.
    When user inputs wrong user details and clicks "Log-in" button, then he gets shown a complete blank page with error message:
    "Incorrect log-in details". 
    Login form disappears from the page.
    This is due to the "exit()" on this lines 59-63:

    
    if (!password_verify($login_password,$db_password)) 
        { 
            echo "Incorrect log-in details<br>"; 
            exit(); 
        } 
    

    Now, if I remove the "exit()", then user gets the same error if his login details are incorrect but the login form still remains on the page. This is what I want so user not have to click BACK button on his browser. But, keeping the "exit()" still runs the script. Waste of bandwidth and/or cpu usage.

    Shall I replace it with die() to achieve what I want or do something else ?

    Q1a.
    How to solve this so script halts but user still sees the login form. And, I want his input to still remain in the form fields and so why don't they especially when I have echoed the form inputs variables like so:

    
    <h2><p align="center"><?php echo "$site_name Member Login Form";?></p></h2> 
    <form name = "login_form" method = "post" action="" enctype = "multipart/form-data"> 
        <fieldset> 
            <label for="login_name">Username/Email:</label> 
            <input type="text" name="login_username_or_email_or_domain" id="login_name" required [A-Za-z0-9] autocorrect=off value="<?php if(isset($_POST['login_username_or_email_or_domain'])) { echo htmlentities($_POST['login_username_or_email_or_domain']); }?>"><br> 
            <label for="login_pass">Password:</label> 
            <input type="password" name="login_password" id="login_pass" required [A-Za-z0-9] autocorrect=off value=""> 
        </fieldset> 
        <div class="SubmitsAndHiddens"> 
            <label for="login_remember">Remember Log-in Details:</label> 
            <input type="checkbox" name="login_remember" id="login_remember" /> 
            <br> 
            <p align="left"><input type="submit" class="btn btn-default" name="submit" value="Log-in!"></p> 
            <br> 
            <a href="login_password_reset.php">Forgot your password ? Reset it here!</a> 
            <br> 
            <a href="register.php">Don't yet have an account ? Register here!</a> 
        </div> 
    </form> 
    

    Note the "value=" in the input field:

    
    <input type="text" name="login_username_or_email_or_domain" id="login_name" required [A-Za-z0-9] autocorrect=off value="<?php if(isset($_POST['login_username_or_email_or_domain'])) { echo htmlentities($_POST['login_username_or_email_or_domain']); }?>"><br>         
    

    Q1b.
    Should I do the same echoing of the variable in the "Password" input field or not  ? Like so:

    
    <input type="password" name="login_password" id="login_pass" required [A-Za-z0-9] autocorrect=off value="<?php if(isset($_POST['login_password])) { echo htmlentities($_POST['login_password']); }?>">    
    

    ISSUE: 2.
    Look at this form I found here:
    https://www.tutorialrepublic.com/php-tutorial/php-mysql-login-system.php
    Why is it echoing in "action=" like this:

    
    <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
    

    Q2a.
    Why not like so:

    
    <form action="" method="post">
    
    
    	<!DOCTYPE html>
    
    	<html lang="en">
    
    	<head>
    
    	    <meta charset="UTF-8">
    
    	    <title>Sign Up</title>
    
    	    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
    
    	    <style type="text/css">
    
    	        body{ font: 14px sans-serif; }
    
    	        .wrapper{ width: 350px; padding: 20px; }
    
    	    </style>
    
    	</head>
    
    	<body>
    
    	    <div class="wrapper">
    
    	        <h2>Sign Up</h2>
    
    	        <p>Please fill this form to create an account.</p>
    
    	        <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
    
    	            <div class="form-group <?php echo (!empty($username_err)) ? 'has-error' : ''; ?>">
    
    	                <label>Username</label>
    
    	                <input type="text" name="username" class="form-control" value="<?php echo $username; ?>">
    
    	                <span class="help-block"><?php echo $username_err; ?></span>
    
    	            </div>    
    
    	            <div class="form-group <?php echo (!empty($password_err)) ? 'has-error' : ''; ?>">
    
    	                <label>Password</label>
    
    	                <input type="password" name="password" class="form-control" value="<?php echo $password; ?>">
    
    	                <span class="help-block"><?php echo $password_err; ?></span>
    
    	            </div>
    
    	            <div class="form-group <?php echo (!empty($confirm_password_err)) ? 'has-error' : ''; ?>">
    
    	                <label>Confirm Password</label>
    
    	                <input type="password" name="confirm_password" class="form-control" value="<?php echo $confirm_password; ?>">
    
    	                <span class="help-block"><?php echo $confirm_password_err; ?></span>
    
    	            </div>
    
    	            <div class="form-group">
    
    	                <input type="submit" class="btn btn-primary" value="Submit">
    
    	                <input type="reset" class="btn btn-default" value="Reset">
    
    	            </div>
    
    	            <p>Already have an account? <a href="login.php">Login here</a>.</p>
    
    	        </form>
    
    	    </div>    
    
    	</body>
    
    	</html>
    

    you can also follow login and registration system in php and mysql.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.