SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2005
    Location
    ble
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Login script errors..

    Bah, this is the first time coding my own login script, and I dont mind using GET's btw, but when I go to login.php?1=test&2=test it comes up

    Parse error: parse error, unexpected T_VARIABLE in /usr/export/www/hosting/aaron/test/login.php on line 3

    Heres my code:

    PHP Code:
    <?

    $login 
    $_GET[1]
    $pass $_GET[2]

       if(!
    $login or !$pass) {
         print(
    "You didn't enter your login and pass. <br>Try once more.");
         exit();
       }

      if (
    $login=test) & ($pass=test) {
     print 
    "Welcome Admin";
       }
    }
    ?>
    O btw, anyone know how to make it like "if $login doesnt = test", "wrong username" or something.. catch my drift? :P

    Script is probably scrappy, im sort of newb at php and bad at making my own script. Im good at editing.. just not creating from scratch..
    If someone was helpful, give them some 'rep'.

  2. #2
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try
    PHP Code:
     $login $_GET[1];
     
    $pass $_GET[2]; 
    to make your code more maintainable, you woud be better off naming the GET variables login and password

    e.g.
    login.php?login=login-name&pass=password

    then you access the variables like
    PHP Code:
     $login = (isset($_GET['login']) ? $_GET['login'] : '';
     
    $pass = (isset($_GET['pass']) ? $_GET['pass'] : ''
    to test for a specifi value, use this code
    PHP Code:
     if ( ('test' == $login) && ('test' == $pass) )
     {
       echo 
    'Welcome admin!';
     } 
    Note that this is a ver insecure method, as your username and password are shown in the browser's address bar.

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2005
    Location
    ble
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks man, but:


    Code:
     $login = (isset($_GET['login']) ? $_GET['login'] : '';
    $pass = (isset($_GET['pass']) ? $_GET['pass'] : '';
    Should be:

    Code:
     $login = (isset($_GET['login'])) ? $_GET['login'] : '';
     $pass = (isset($_GET['pass'])) ? $_GET['pass'] : '';
    Heh, you missed a ) ;-)

    Thanks man, again..
    If someone was helpful, give them some 'rep'.

  4. #4
    Non-Member bronze trophy geniusgoalie's Avatar
    Join Date
    Sep 2004
    Location
    Buffalo, USA
    Posts
    979
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why not try this instead, in your html login page, why not add this to your form tag:
    method=POST
    so the variables would be hidden and you wouldn't need to "get" them.
    i.e. it probably looks something liek
    <form action="login.php">
    change it to
    <form action="login.php" method=POST>

    O btw, anyone know how to make it like "if $login doesnt = test", "wrong username" or something.. catch my drift? :P
    Try this:
    PHP Code:
    if ($login != 'test'){
    echo 
    "you aren't signed in";

    Hope that helps

  5. #5
    SitePoint Zealot
    Join Date
    Jan 2005
    Location
    ble
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks man hehe
    If someone was helpful, give them some 'rep'.


Bookmarks

Posting Permissions

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