Login Script
Results 1 to 5 of 5

Thread: Login Script

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    17

    Login Script

    Hi all,

    I decided to come back to the world of PHP and, just like how I left it, fall for all the basic errors...
    I'm trying to create a login script for my website but for some unknown reason this produces an Internal Error (500).
    I'm not sure what part in the script causes this so I'm posting the whole script.
    (Error 500's are usually caused (with my site anyway) by a missing semicolon or something stupid)
    Thanks in advance!

    PHP Code:
                    if (isset($_COOKIE["Username"])){
                        echo 
    "<did><p><b>Welcome, ".$_SESSION["Username"]."!</b></p></div>";
                    }else{
                        if(isset(
    $_POST['Submit'])) {  
                            if(!empty(
    $_POST['Username'])){
                                if(!empty(
    $_POST['Password'])){
                                    
    $mysqli = new mysqli([Removed]);   
                                    
    $Username $mysqli->real_escape_string($_POST['Username']);  
                                    
    $Password md5($_POST['Password']);
                                    if (
    mysqli_connect_errno()) {  
                                        
    printf("Connect failed: %s\n"mysqli_connect_error());
                                        exit();  
                                    }              
                                    
    $Result $mysqli->query("SELECT * FROM `Users` WHERE `Username` = '$Username' && `Password` = '$Password'");
                                    if(
    $Result->num rows === 1){  
                                        
    $Expires 1000 60 60 24;   
                                        
    setcookie("Username"$Result['Username'], time()+$Expires); 
                                    }else{
                                        echo 
    '<div class="LoginError"><p>That Username or Password is wrong!</p></div>';
                                    }
                                }else{
                                    echo
    '<div class="LoginError"><p>Please enter your Username and Password!</p></div>';
                                }
                            }else{
                                echo
    '<div class="LoginError"><p>Please enter your Username and Password!</p></div>';
                            }
                        }
                        echo <<<END
                            <form id="Login" Method ="post" Action = "http://thefunnyzone.co.uk/index.php" accept-charset='UTF-8'>    
                                <fieldset style="border: none;">
                                    <label style="position: relative;">Username:</label>
                                    <input Type="Text" name="Username" class="text-input" style="position: relative;"/>
                                    <label style="position: relative;">Password:</label>
                                    <input Type="Password" name="Password" class="text-input" style="position: relative;"/>
                                    <input Type="Submit" Name="Submit" Value="Login" style="position: relative;"/>
                                </fieldset>
                            </form>
    END;
                    } 

  2. #2
    High Energy Magic Dept. NogDog's Avatar
    Join Date
    Aug 2006
    Location
    Ankh-Morpork
    Posts
    13,886
    First thing I see is that you left out an underscore on this line:
    Code:
    if($Result->num_rows === 1){
    Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be." ~ from Nation, by Terry Pratchett

    "But the main reason that any programmer learning any new language thinks the new language is SO much better than the old one is because hes a better programmer now!" ~ http://www.oreillynet.com/ruby/blog/...ck_to_p_1.html


    eBookworm.us

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    17
    Thank you, that was the main issue!
    It appears that the very first if statement causes an issue, though. Please click here and enter User as the username and Password as the Password to see what I mean.
    Thanks again!

  4. #4
    Senior Member Derokorian's Avatar
    Join Date
    Apr 2011
    Location
    Denver
    Posts
    1,767
    PHP Code:
                    if (isset($_COOKIE["Username"])){ 
                        echo 
    "<did><p><b>Welcome, ".$_SESSION["Username"]."!</b></p></div>"
                    }else{ 
    You've mixed checking a cookie and checking the session.
    Sadly, nobody codes for anyone on this forum. People taste your dishes and tell you what is missing, but they don't cook for you. ~anoopmail
    I'd rather be a comma, then a full stop.
    User Authentication in PHP with MySQLi - Don't forget to mark threads resolved - MySQL(i) warning

  5. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    17
    Oh I forgot to mention, I've already spotted and changed that.
    Thanks for the reply though!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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