SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Include Problem

Hybrid View

  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 when a user logs in correctly i have them sent to protected.php. In order to stop people from just going to protected.php, skipping the login, i used to following code: <?php include("accesscontrol.php"); ?>.

    But when i do this, and someone logs in correctly, it starts to take them to the page, but all it says is: connected to website, waiting for a reply, over and over and over again. What really confuses me though is when i remove the include function at the top of protected.php, it works. when the user logs in, it takes them to the page, but they could just go there any time they wanted, without logging in. could someone please tell me why it won't ever load protected.php with the include function at the top?

    accesscontrol.php

    <?php // accesscontrol.php
    include("common.php");
    include("db.php");
    session_start();
    if(!isset($uid)) {
    ?>

    <html>
    <head>
    <title>Login</title>
    </head>

    <body bgcolor="#FFFFFF" text="#000000">
    <h1>Login Required</h1>
    <p>You must log in to access this area of the site. If you are not a registered user, please
    <a href="signup.php">click here</a> to sign up for free, instant access!</p>
    <p><form method=post action="<?accesscontrol.php?>">
    User ID: <input type=text name=uid size=15><br>
    Password: <input type=password name=pwd size=15><br>
    <input type=submit value=Sign In>
    </form></p>
    </body>
    </html>
    <?php
    exit;
    }

    dbConnect("Members");
    $sql = "select * from members where username = '$uid' AND password = '$pwd'";
    $result = mysql_query($sql);
    if (!result) {
    error("A database error occured while processing your request.\\nIf this error persists, ".
    "contact trhynard@aol.com.");
    }
    if(mysql_num_rows($result) == 1) {
    session_register("uid");
    session_register("pwd");
    header ("Location: protected.php");
    }
    elseif(mysql_num_rows($result) ==0) {
    session_unregister("uid");
    session_unregister("pwd");
    echo("Username or password was not correct.");
    }
    else {
    echo("An error has occured. Please try again later");
    }
    ?>



    Protected.php

    <?php include("accesscontrol.php"); ?>
    <html>
    <head>
    <title> Members-Only Page </title>
    </head>
    <body>
    <p>Welcome <?=$uid?>! You have entered a members-only area
    of the site. Don't you feel special?</p>
    </body>
    </html>

    I would greatly appreciate any help!!!

  2. #2
    SitePoint Addict
    Join Date
    Apr 2001
    Location
    Michigan
    Posts
    284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Basicly the problem is that when i include accesscontrol.php in protected.php, the page never loads. But if i take out the include code, it works.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2001
    Location
    Rawalpindi, Pakistan
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    there can be some sort of indefinate loop in ur accesscontrol.php, not sure but it may be that u r including/calling accesscontrol.php in some of files which are included in accesscontrol.php, i.e. common.php or db.php.
    There may be any other reason for that...

    Aatif Malik


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
  •