SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Apr 2001
    Location
    Michigan
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a login page, and it works, but when someone logs in correctly, the page just sits there, i want it to go to protected2.php. I know i should use the header("Location: http://localhost/protected2.php"); but i don't know where i should put it in the code. Could someone please help me? My login file is included below:

    <?php //accesscontrol2.php

    include("common.php");
    include("db.php");

    session_start();
    if(!isset($uid)) {
    ?>
    <html>
    <head>
    <title>Please Log In For Access</title>
    </head>

    <body>
    <h1>Login Required</h1>
    <p>You must log in to access this area of the site. If you are not a registered
    user, <a href="signup.php">click here</a> to sign up for instant access!</p>
    <p><form method="post" action="<?=$php_self?>">
    User ID: <input type="text" name="uid" size="20"><br>
    Password: <input type="password" name="pwd" size="20"><br>
    <input type="submit" value="Log In">
    </form>
    </body>
    </html>
    <?php
    exit;
    }
    session_register("uid");
    session_register("pwd");
    dbconnect("members");
    $sql = "select * from members where username = '$uid' and password = '$pwd'";
    $result = mysql_query($sql);
    if(!$result) {
    error("A database error has occured while processing your request.\\nIf this problem
    persists, please contact trhynard@aol.com.");
    }
    if(mysql_num_rows($result) == 0) {
    session_unregister("uid");
    session_unregister("pwd");
    ?>
    <html>
    <head>
    <title>Access denied</title>
    </head>
    <body>
    <h1>Access Denied</h1>
    <p>Your user id or password were incorrect, or you are not a registered user.
    To try logging in again, click <a href="<a href="$php_self">here</a>
    If you are not registered, click <a href="signup.php">here</a> to sign up.</p>
    </body>
    </html>
    <?php
    exit;
    }
    ?>

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    lol....You don't have much choice. It has to go in here:

    <?php //accesscontrol2.php

    include("common.php");
    include("db.php");

    session_start();
    if(!isset($uid)) {
    ?>

    I would suggest you rewrite your script. It does not follow very good programming style, and I don't think you understand what the "exit" command does. It should generally be avoided. See www.php.net for details. When you have to start using break, continue or exit commands, your script's logic is flawed. Some tips for improving your script: Why should a user continually have to click links? If they login in and they are an invalid user, the script should present the login form again automatically. If they login correctly, then the script should take them to another page. That can be accomplished with an if-else structure.
    Last edited by 7stud; May 6, 2001 at 18:20.

  3. #3
    SitePoint Addict
    Join Date
    Apr 2001
    Location
    Michigan
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok thanks. I got that from the login tutorial from the tutorial on the site. I don't really know what half the stuff does, but I will try to rewrite the code without the exit; commands.


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
  •