Results 1 to 6 of 6

Thread: Begginers Login help

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Begginers Login help

    Hi guys,

    Below is the code but when i run the script on my server it shows the Access Denied before i even type anything in also when i type in the correct username and password how do i get it to remove the login box stuff and just leave the Access Granted text?.

    PHP Code:
    <html>
    <head/>
    <body>

    <form action="login.php" method=POST>
    Username <input type=text name=user><br/>
    Password <input type=text name=pass><br/>
    <input type=submit value="Go"><p>
    </form>

    <?php

    $user
    =$_POST['user'];
    $pass=$_POST['pass'];

    if ((
    $user=='admin') && ($pass=='admin')) echo "Access Granted!";
    else echo 
    "Access Denied!";

    ?>

    </body>
    </html>
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  2. #2
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Begginers Login help

    I'm not going to give you the answer on this one, but I will attempt to help.

    PHP Code:
    <?php

    $user
    =$_POST['user'];
    $pass=$_POST['pass'];

    if ((
    $user=='admin') && ($pass=='admin')) echo "Access Granted!";
    else echo 
    "Access Denied!";

    ?>
    The above code is getting the post variables "user" and "pass" and putting them in the local variables $user and $pass.

    So, when you first access the form, you have not posted anything, thus the "Access Denied" message.

    If you enter "admin" and "admin" into the text boxes, it will post back and show "Access Granted" but the form will still appear.

    You will need to check your variables and decide what you want to display based on that.

  3. #3
    Lively Member
    Join Date
    Aug 2007
    Posts
    95

    Re: Begginers Login help

    Quote Originally Posted by Jamie_Garland
    Hi guys,

    Below is the code but when i run the script on my server it shows the Access Denied before i even type anything in also when i type in the correct username and password how do i get it to remove the login box stuff and just leave the Access Granted text?.

    PHP Code:
    <html>
    <head/>
    <body>

    <form action="login.php" method=POST>
    Username <input type=text name=user><br/>
    Password <input type=text name=pass><br/>
    <input type=submit value="Go"><p>
    </form>

    <?php

    $user
    =$_POST['user'];
    $pass=$_POST['pass'];

    if ((
    $user=='admin') && ($pass=='admin')) echo "Access Granted!";
    else echo 
    "Access Denied!";

    ?>

    </body>
    </html>
    Unless "login.php" is the same page, then it is not processing the infomation in the text boxes.

    Alternatively, try
    <form action="" method=POST>
    Visual Basic 6 + MS Access

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2004
    Posts
    1,202

    Re: Begginers Login help

    Can anyone help me with placing a link if the access has been accepted and if its denied the link dosent show this is the code that i have so far?.

    Code:
    <?php
    
    $user=$_POST['user'];
    $pass=$_POST['pass'];
    
    if (($user=='admin') && ($pass=='admin')) echo "Access Granted!"; 
    
    else echo "Access Denied!";
    
    ?>
    come back and mark your original post as resoved if your problem is fixed

    Jamie Garland

  5. #5
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Begginers Login help

    That code looks identical to the code you posted above.

    At least change your echo to output a link before you ask for help; You'll find most people around here help those who help themselves.

    Also, if you're looking at having someone authenticate to get into your page, and any subsequent pages, you should look into Sessions.

    W3Schools has a good tutorial at:

    http://www.w3schools.com/php/php_sessions.asp

    But I would also suggest you go through their entire PHP tutorial at:

    http://www.w3schools.com/php/php_intro.asp

  6. #6
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959

    Re: Begginers Login help

    Check to see if the POST is == ""

    If(!$_POST['user'] == "" && !$_POST['pass'] == ""){

    if (($user=='admin') && ($pass=='admin')) echo "Access Granted!";

    else echo "Access Denied!";



    }

Posting Permissions

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



Click Here to Expand Forum to Full Width