Results 1 to 3 of 3

Thread: PHP form redirect

  1. #1
    Join Date
    Aug 2007
    Posts
    22
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default PHP form redirect

    Basically I wanna set up a form where the user is required to enter in a username and a password. It then searches for any criteria (in php code) that matches. For example if the username is "name" and password is "1234", if this statement is met, then it redirects to a certain folder. I haven't worked with php much but in C++ its a couple lines of code and fairly simple. I was hoping someone can help me here. The idea of this being, where the redirection occurs, the folder is protected by .htaccess and the user then enters in another pass/username. I know how to set up .htaccess but just need help with php.

    Seems like if and else statements. I don't know whether or not php has switch statements or something of this sort...

  2. #2
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    I know this is not quite what you are looking for, but it is a start.

    www.mysite.com/login1.php has this:
    Code:
      <form action='http://www.mysite.com/login2.php' method='POST'><p><br>
      <input type='password' name='pasword' value='ee'>
      <input type='submit' value='Go to Next Page'>
      </form>
    www.mysite.com/login2.php has this
    Code:
    <?php
      session_start();
    $pasword=$_POST['pasword'];
      $_SESSION['pasword'] = "$pasword";
    if ( @$_SESSION['pasword']  != "secret" )
    {
    header("location: login1.php");
    exit();
    }else header("location: http://www.mysite.com/private/index.php");
    ?>
    The protected pages have this code at the beginning of the page
    Code:
    <?php
      session_start();
    if ( @$_SESSION['pasword']  != "secret" )
    {
    header("location: ../login1.php");
    exit();
    }
    This version uses one password only. It can be modified to use other passwords as well or multiple ones depending on your needs. Another version could get the info from a database, which sounds to me more along the lines of what you are wanting to do although as I am the only person on my site in need of logging in I use the above script and I use the .htaccess files as well for added protection.
    Last edited by james438; 02-07-2008 at 12:31 AM. Reason: tiny code error

  3. #3
    Join Date
    Aug 2007
    Posts
    22
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    Thanks alot. I also found another interesting plugin for wordpress so I might use WP for CMS but thanks alot. I think i'm gonna implant the code you gave me and if later on I want to upgrade, i'll use WP.

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
  •