SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    May 2008
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Password protected

    Hello everyone. I don't know anything of php but at least I got it all working on my computer.

    I would like to create a password protected link through which, depending on the user name and password, the user will be directed to a specific page.

    I am not sure how to accomplish this. Any guidance would be greatly appreciated.

    Regards,

    Andres.

  2. #2
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you could do an .htaccess password,
    or did you want a php password with text or mysql storage?

    Here is a easy one i dug up on the web:
    PHP Code:

    <html> 
    <head></head> 

    <body> 

    <?php 

    $username 
    "username"
    $password "password"

    if (
    $_POST['txtUsername']!= $username || $_POST['txtpassword']!= $password) { 

    ?> 

    <form name="form" method="post" action="<?php echo $_SERVER['php_SELF'];?>"> 

    Username: <input type="text" name="txtUsername" /> 
    password: <input type="password" name="txtpassword" /> 
    <input type="submit" value="Submit" /> 

    </form> 

    //else bit 

    <?php 



    else { 

    ?> 

    <p> passworded bit </p> 

    <?php 



    ?> 

    </body> 
    </html>

  3. #3
    SitePoint Zealot
    Join Date
    May 2008
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for this, it will get me started playing around with php!

  4. #4
    SitePoint Zealot
    Join Date
    Dec 2008
    Posts
    120
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is better to use .htaccess

    You can protect directory, file, filetype with password and apache server will server that service.

  5. #5
    Non-Member adstiger's Avatar
    Join Date
    Nov 2008
    Location
    Canada
    Posts
    348
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if username = admin and password = test, check like this

    if($user=='admin' && $pass='test'){
    echo "welcome";
    }else{
    echo "wrong username or password";
    }


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
  •