Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.


Results 1 to 8 of 8

Thread: htaccess

  1. #1
    vini's Avatar
    Advance Motion Management

    Barcode htaccess

    Can anbody plz help me.. how to protect a directory or folder with "htaccess" in PHP?

    How to create a password protection page with sessions(start/expire) in Php to a SQL server or a particular page?

    Thanks in Advance
    Last edited by vini; January 21st, 2007 at 01:51 PM.

    Its in my blood to B+

  2. #2
    vini's Avatar
    Advance Motion Management

    Its in my blood to B+

  3. #3
    .htaccess and PHP password protection are two different things. Which are you looking for?

  4. #4
    vini's Avatar
    Advance Motion Management

    Fla Box

    Actually both.., What is the difference betwen the two and how do I use it, I am pretty new to PHP. Thanks for the replay

    Its in my blood to B+

  5. #5
    PHP is more dynamic but also requires a datasource (MySQL is good) I would say for a small site .htaccess is fine but for bigger ones PHP or ASP is a must!

  6. #6
    really anything where the amount of users will change you should use php.

    member #1 of the "XML-is-a-crutch-to-make-people-feel-elite-club"
    K-Emmys-06: Best Quote K-Emmys-06: Flash Genious

  7. #7
    if its a personal server and just you are going to be logging in to access the files or what ever, use .htaccess

    if its out there in userland, use a php/asp login system. you should be able to find what youre looking for on http://www.hotscripts.com

  8. #8
    session_start(); // start the session
    $_SESSION['login'] = (!isset($_SESSION['login'])) ? false : $_SESSION['login'];
    // if the session doesnt exist set it to false else take the current value
    // check if logout was requested
    if (isset($_GET['logout']) 
    AND $_GET['logout'] == 1
    AND $_SESSION['login'] === true
    $_SESSION['login'] = false;
    header('location: '.htmlspecialchars($_SERVER['PHP_SELF'])); // redirect 
    // check if the form was submitted
    {// there is posted
    if ( isset($_POST['username']) AND !empty($_POST['username']) // was the username entered
    isset($_POST['password']) AND !empty($_POST['password']) // was password entered
    AND strtolower($_POST['username']) == USERNAME // do username match
    AND strtolower($_POST['password']) == PASSWORD // do pass match
    $_SESSION['login'] = true; // set session to true
    header('location: '.htmlspecialchars($_SERVER['PHP_SELF'])); // redirect to
    // same page wit session to true
    exit(); // so the code dont continue to execute below
    // wasnt correct send back
    header('location: '.htmlspecialchars($_SERVER['PHP_SELF']).'?error=1'); // redirect to
    } // end of post block
    if ($_SESSION['login'] === true)
    // protected area
    echo 'youre in the protected area!<br />';
    echo ',<a href="?logout=1">Logout</a> here';
    // the form ?
    if (isset($_GET['error']) AND $_GET['error'] == 1) // ups an error
    echo '<center>Wrong pass etc</center><br />';
    echo '<form action="'.htmlspecialchars($_SERVER['PHP_SELF']).'" method="post">';
    echo '<label for="username">Username:</label><input type="text" name="username" id="username" /><br />';
    echo '<label for="password">Pass:</label><input type="password" name="password" id="password" /><br />';
    echo '<input type="submit" value="Login" /><br />';
    echo '</form>';
    This will get you on the way i hope,
    i just coded it here lol,
    so any question or prob lt me know
    Last edited by kenisfam; January 30th, 2007 at 01:04 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012