Login Page. Re-direct to somewhere?

Discussion in 'Web Design and Development' started by JackT06, Aug 19, 2009.

  1. JackT06 macrumors 6502

    JackT06

    Joined:
    Jul 24, 2009
    #1
    I followed a tour trail on Youtube about setting my Login page up. The trouble im having is that it keeep redirecting to a blankpage everytime i click on go. Here are my two codes
    Please can someone help me:
    PHP:
    <?php
           $username 
    $_POST['username'];
           
    $password$_POST['password'];
           
    $login $_GET['login'];
           
           
    setcookie("username,"$username", time()+86400);
           
           
           
           if(
    $login='yes') {
           
           
               
    $conn = mysql_connect("localhost","a2034243_JackT06","PASSWORD");
               
               mysql_select_db("
    a2034243_Member");
               
               
    $get = mysql_query("SELECT count(idFROM login WHERE user='$username' and pass='$password'");
           
           
    $result = mysql_result($get,0);
           if(
    $result!=1)[
           echo "
    Invalid login.";
           ] else[
           echo "
    login Successful.Welcome back" . $_COOKIE['username'] . "sir/madem.";
           
    $_SESSION['username'] = $username;
           ]
           }
    ?>
    PHP:
    <html>
    <
    body>
           <
    form action="login.php?login=yes" method="post">
           
    Username: <input type="text" name="username"
           
    <br />
           
    Password: <input type="password" name="password" />
           <
    br />
           <
    input type="submit" value="Go!!" />
         </
    form>
    </
    body>
    </
    html>
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    Use the color coding of the PHP in your post to see where you may have a quote problem. hint hint.

    Also if statements use {} around its content, not [].
     
  3. Darth.Titan macrumors 68030

    Darth.Titan

    Joined:
    Oct 31, 2007
    Location:
    Austin, TX
    #3
    Well it looks like
    PHP:
    setcookie("username,"$username", time()+86400);
    should be
    PHP:
    setcookie("username",$usernametime()+86400);
     
  4. JackT06 thread starter macrumors 6502

    JackT06

    Joined:
    Jul 24, 2009
    #4
    Thanks for spotting that out. Changed it yet it still doing the samething it redirects me to:

    file:///Users/jack/Desktop/Tester/login.php?login=yes

    I can even enter random letters and it directs me to there?
     
  5. uberamd macrumors 68030

    uberamd

    Joined:
    May 26, 2009
    Location:
    Minnesota
    #5
    Are you testing this locally or on a remote server? Do you have PHP error reporting turned on? Take a look at the contents of /var/log/apache2/error.log and see if it reports any errors when you load that page.

    A trick would be to open command prompt, and type:

    Code:
    sudo tail -f /var/log/apache2/error.log
    That will follow the error log and each time you refresh the page the new error log contents will output on your screen automatically.
     
  6. SrWebDeveloper macrumors 68000

    SrWebDeveloper

    Joined:
    Dec 7, 2007
    Location:
    Alexandria, VA, USA
    #6
    Incorrect:

    PHP:
    if($login='yes') {


    Should be:

    PHP:
    if($login=='yes') {
     
  7. JackT06 thread starter macrumors 6502

    JackT06

    Joined:
    Jul 24, 2009
    #7
    Signup page redirects to nothing

    This evening since about 7 non stop i have been makeing this login script. The problem that im having is that when i click submit it takes me to the page it is ment to but it does not display anything on that page.

    Here are my codes if they will help
    HTML:
    <html>
    <body>
    <font size="5" face="sans-serif">Login</font>
    <form action="login2.php" method="POST">
    <table cellpadding="3" cellspacing="4" border="0">
    <tr>
    <td>Username:</td>
    <td><input type="text" name="user" /></td>
    </tr>
    <tr>
    <td>Password:</td>
    <td><Input type="password" name="pass"</td>
    </tr>
    <td><input type="submit" name="submit" value="login"</td>
    </table>
    </form>
    
    </body>
    
    </html>
    PHP:
    <?php
    include ("connect.php");

    if (
    $_POST['submit']);
    {
      
    // Get data 
      
    $username $_POST['user'];
      
    $password $_POST['pass'];
      
      if(
    $username && $password)
      {
       
       
    $query mysql_query("SELECT * FROM users");
       while (
    $getrows mysql_fetch_assoc($query))
       {
                 
    $dbuser $getrows['user'];
                 
    $dbuser $getrows['pass'];
       
       }
       
       if ((
    $username == $dbuser) && ($password == $dbuser)) 
       {
       echo 
    "login Successfull..";
       }
       else
       {
       echo 
    "Login Failure"
       
    }
       
       
       
      }
      else
      {
       die(
    "The username and password fields should not be left empty.");
      }
    }

    ?>
    PHP:
    <?php

    $connect 
    mysql_connect("localhost","root") or die (mysql_error());
    mysql_select_db("Website") or die (mysql_error());


    ?>
     
  8. Cerebrus' Maw macrumors 6502

    Joined:
    Mar 9, 2008
    Location:
    Brisbane, Australia
    #8
    This might be your problem
    Code:
    if ($_POST['submit']);
    
    Remove the ; at the end;
     
  9. JackT06 thread starter macrumors 6502

    JackT06

    Joined:
    Jul 24, 2009
  10. Cerebrus' Maw macrumors 6502

    Joined:
    Mar 9, 2008
    Location:
    Brisbane, Australia
    #10
    So taking the semi colon out above didnt help....?
     
  11. JackT06 thread starter macrumors 6502

    JackT06

    Joined:
    Jul 24, 2009
    #11

    no im affraid not
     
  12. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #12
    Try this for you if statement,
    PHP:
    if (array_key_exists('submit'$_POST)) 
    You can also try printing out some debug messages to see where things are getting screwy. Also, do you have access to the PHP error log file? It would be very helpful probably.
     
  13. Cerebrus' Maw macrumors 6502

    Joined:
    Mar 9, 2008
    Location:
    Brisbane, Australia
    #13
    Blast.

    Ok, the fact that it's not displaying anything, it must mean that the $_POST['submit'] is not being set, as you dont have an else statement for that loop.

    just try appending
    Code:
    else {
     echo "Submit not set";
    }
    
    onto your code.
     
  14. JackT06 thread starter macrumors 6502

    JackT06

    Joined:
    Jul 24, 2009
    #14
    Changed it and it didn't make a difference. How do i get access to the php error file?
     
  15. JackT06 thread starter macrumors 6502

    JackT06

    Joined:
    Jul 24, 2009
    #15

    Sorry to ask a dum question but where does that need to go?
     
  16. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #16
    Are you doing this locally with the built-in PHP, MAMP, or a web host? It may be a logs folder named php_error.log.
     
  17. Cerebrus' Maw macrumors 6502

    Joined:
    Mar 9, 2008
    Location:
    Brisbane, Australia
    #17
    PHP:
    <?php
    include ("connect.php");

    if (
    $_POST['submit'])
    {
      
    // Get data 
      
    $username $_POST['user'];
      
    $password $_POST['pass'];
      
      if(
    $username && $password)
      {
       
       
    $query mysql_query("SELECT * FROM users");
       while (
    $getrows mysql_fetch_assoc($query))
       {
                 
    $dbuser $getrows['user'];
                 
    $dbuser $getrows['pass'];
       
       }
       
       if ((
    $username == $dbuser) && ($password == $dbuser)) 
       {
       echo 
    "login Successfull..";
       }
       else
       {
       echo 
    "Login Failure"
       
    }
       
      }
      else
      {
       die(
    "The username and password fields should not be left empty.");
      }
    }
    else
    {
       echo 
    "Submit is not set";
    }
    ?>

     
  18. JackT06 thread starter macrumors 6502

    JackT06

    Joined:
    Jul 24, 2009
    #18

    To view them i put them in mamp htdocs and open them up. I think that is how i am ment to do it.
     
  19. JackT06 thread starter macrumors 6502

    JackT06

    Joined:
    Jul 24, 2009
    #19

    didnt make a difference
     
  20. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #20
    Check in MAMP/logs/ for the error log. That's where MAMP keeps the PHP error log.

    Let's actually simplify some things for your script,

    PHP:
    <?php
    include ("connect.php");

    if (
    array_key_exists('submit'$_POST))
    {
      
    // Get data and escape the string to protect from SQL-injection attacks
      
    $username mysql_real_escape_string($_POST['user']);
      
    $password mysql_real_escape_string($_POST['pass']);
      
      if (
    $username && $password)
      {
        
    $query "SELECT user, pass FROM users WHERE user='$username' AND pass='$password'";
        
    $result mysql_query($query);
        
    // If there's a result, we have a correct login pair
        
    if (mysql_num_rows($result)) {
          
    // login credentials correct
          
    echo '<h1>login success</h1>';
        }
        else {
          
    // incorrect login
          
    echo '<h1>login was not a success</h1>';
        }
      }
      else {
        
    // didn't fill out username and password
        
    echo '<p>Hey bonehead, you forgot the user name or password!</p>';
      }
    }
    else {
      
    // Output form
      
    echo '<p>put form here</p>';
    }
    ?>
     
  21. JackT06 thread starter macrumors 6502

    JackT06

    Joined:
    Jul 24, 2009
    #21
    There is only two logs in there. Mysql and apache
     
  22. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #22
    Interesting. Go to MAMP/conf/php5 and open the php.ini file. Do a search for "error_log" (w/o quotes). It'll be a line that starts with that or may have a # in front of it, which means it's commented out. It'll show where it's saving the error log file. A few lines up there'll also be a line that should have "log_errors = On" so that it's actually logging.
     
  23. JackT06 thread starter macrumors 6502

    JackT06

    Joined:
    Jul 24, 2009
    #23

    It says that it was allready on
     
  24. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #24
    And the location of the error log? Is that pointing to the place I had you look for it?

    You can also change settings for these lines if need be,
    Code:
    error_reporting  =  E_ALL
    display_errors = Off # turn on if you want errors to show on page as well
    If you do make a change you'll need to restart the server for them to take effect.
     
  25. JackT06 thread starter macrumors 6502

    JackT06

    Joined:
    Jul 24, 2009
    #25
    ; Log errors to specified file.
    error_log = "/Applications/MAMP/logs/php_error.log"

    Thats where it is pointing to.
     

Share This Page