Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation My login script is not working correctly

    Hello,
    Im editing a login script for a project that im working on, When i login it's just freezes on the "checklogin.php" page,
    Can anyone help me? I need help fast,

    Best regards Gustav

    (Im swedish)

    Checklogin.php
    PHP Code:
    <?php

    session_start
    ();
    ob_start();

    $host="localhost"// Host name 
    $username="root"// Mysql username 
    $password=""// Mysql password 
    $db_name="members"// Database name 
    $tbl_name="members"// Table name 

    // Connect to server and select databse.
    mysql_connect("$host""$username""$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");

    // username and password sent from form
    $myusername=$_POST['myusername'];
    $mypassword=$_POST['mypassword'];

    // To protect MySQL injection (more detail about MySQL injection)
    $myusername stripslashes($myusername);
    $mypassword stripslashes($mypassword);
    $myusername mysql_real_escape_string($myusername);
    $mypassword mysql_real_escape_string($mypassword);

    $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
    $result=mysql_query($sql);

    // Mysql_num_row is counting table row
    $count=mysql_num_rows($result);
    // If result matched $myusername and $mypassword, table row must be 1 row

    if($count==1){
    // Register $myusername, $mypassword and redirect to file "login_success.php"
    session_register("myusername");
    session_register("mypassword");
    header("location:list.php");
    }
    else {
    echo 
    "Wrong Username or Password";
    }
    ob_end_flush();
    ?>

  • #2
    Regular Coder
    Join Date
    Oct 2004
    Posts
    363
    Thanks
    0
    Thanked 18 Times in 18 Posts
    Try adding
    PHP Code:
    error_reporting(-1);
    ini_set('display_errors','On'); 
    to see if you are getting any PHP errors.

    Also try replacing
    Code:
    session_register("myusername");
    session_register("mypassword");
    header("location:list.php");
    with
    Code:
    $_SESSION['myusername'] = $myusername;
    $_SESSION['mypassword'] = $mypassword;
    header('Location: http://example.com/path/to/list.php');
    session_register is deprecated

  • #3
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    I'm just going to take a stab at this without testing anything ...

    Try this:
    PHP Code:

     <?php

    session_start
    ();
    //ob_start();

    $host="localhost"// Host name 
    $username="root"// Mysql username 
    $password=""// Mysql password 
    $db_name="members"// Database name 
    $tbl_name="members"// Table name 

    // Connect to server and select databse.
    mysql_connect("$host""$username""$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");

    // username and password sent from form
    $myusername=$_POST['myusername'];
    $mypassword=$_POST['mypassword'];

    // To protect MySQL injection (more detail about MySQL injection)
    $myusername stripslashes($myusername);
    $mypassword stripslashes($mypassword);
    $myusername mysql_real_escape_string($myusername);
    $mypassword mysql_real_escape_string($mypassword);

    $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
    $result=mysql_query($sql);

    // Mysql_num_row is counting table row
    $count=mysql_num_rows($result);
    // If result matched $myusername and $mypassword, table row must be 1 row

    if($count==1){
    // Register $myusername, $mypassword and redirect to file "login_success.php"
    //session_register("myusername");
    //session_register("mypassword");
    $_SESSION['myusername']=$myusername;
    $_SESSION['mypassword']=$mypassword;
    header("location:list.php");
    exit;
    }
    else {
    echo 
    "Wrong Username or Password";
    }
    //ob_end_flush();
    ?>
    Last edited by mlseim; 05-14-2014 at 11:59 PM.

  • #4
    Regular Coder
    Join Date
    Sep 2011
    Posts
    428
    Thanks
    18
    Thanked 26 Times in 26 Posts
    If that doesn't work (all I noticed was change near the bottom to not use session_register(), which is deprecated anyways)then enable error reporting and see what it says.

    To do so, start your php code like so:
    PHP Code:
    <?php
    ini_set
    ('display_erros'true); //Enable error display
    error_reporting(E_ALL); //Set error level
    Doing this will cause every error, warning, notice, etc. to be displayed to you so you can see what's happening and know what to fix. You shouldn't have the display set too high in production environments, however there's an alternative function you can use to log errors in a custom way, such as to a database or text file. Check out set_error_handler(); for more information.


  •  

    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
    •