Results 1 to 9 of 9
  1. #1
    Join Date
    Nov 2007
    Posts
    753
    Tokens
    0

    Default Help annoying problem

    You may think this is simple. But im doing everything right and its not working.
    I want it so that only logged in members can see a page. But when i logout and go to the page the content turns up!
    Its sodding simple and its not working. Any ideas?

    Thanks
    - Luke
    Publishing free website designs, watch this space!
    Total number of designs published: 0
    Current work in progress: Landscape Design


  2. #2
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    Sessions:
    PHP Code:
    <?php
    session_start
    ();

    if(isset(
    $_SESSION['session_var']))
    {

    // Content goes here

    }
    else
    {

    die(); 
    // End html

    }
    ?>
    Cookies
    PHP Code:
    <?php
    ob_start
    ();

    if(isset(
    $_COOKIE['session_var']))
    {

        
    // Content goes here

    }
    else
    {

        die(); 
    // End html

    }
    ?>

  3. #3
    Join Date
    Nov 2007
    Posts
    753
    Tokens
    0

    Default

    right its working but it keeps showing me the content that the logged out person should see.
    Publishing free website designs, watch this space!
    Total number of designs published: 0
    Current work in progress: Landscape Design


  4. #4
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    Paste your code.

  5. #5
    Join Date
    Nov 2007
    Posts
    753
    Tokens
    0

    Default

    login.php
    <?php
    echo("
    <form action='validation.php' method='post'>
    Username: <input type='text' name='username' size='20'><br><br>
    Password: <input type='password' name='password' size='20'><br><br>
    <input type='submit' name='submit' value='login'>
    </form>
    ");
    ?>
    validation.php
    <?php
    require("includes/connect.php");
    $username=$_POST['username'];
    $password=$_POST['password'];
    $sql="SELECT * FROM $tbl_name WHERE username='$username' and password='$password'";
    $result=mysql_query($sql);
    $count=mysql_num_rows($result);
    if($count==1){
    session_register("username");
    session_register("password");
    echo("<meta HTTP-EQUIV='REFRESH' content='2; url=main.php'>");
    }
    else {
    echo "Wrong Username or Password";
    }
    ?>
    main.php
    <?php
    session_start();
    if(!session_is_registered("username"))
    {
    echo("user sees thus");
    }
    ?>
    Publishing free website designs, watch this space!
    Total number of designs published: 0
    Current work in progress: Landscape Design


  6. #6
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    Ew, ew, ew.

    PHP Code:
    <?php
    session_start
    ();
    require(
    "includes/connect.php");

    function 
    clean($var)
    {
        
        
    $var htmlspecialchars$varENT_QUOTES );

        if( 
    get_magic_quotes_gpc(   ) ) {

            
    $var stripslashes$var );
                    
        }
                
        
    $var htmlentities$var );
        
    $var mysql_real_escape_string$var );
        
        return 
    $var;

    }

    // Declare variables
    $username clean($_POST['username']);
    $password clean($_POST['password']);

    // Define SQL Query and execute it
    $sql "SELECT * FROM `".$tbl_name."` WHERE `username` = '".$username."' AND`password` = '".$password."'";
    $result mysql_query($sql) or die("MySQL could not execute the query: ".mysql_error());

    // Count the rows
    $count mysql_num_rows($result) or die("MySQL could not execute the query: ".mysql_error());

    if(
    $count === 1)
    {

        
    $_SESSION["username"] = $username;
        
    /* We're not making a session for the password as why is it needed?.. */
        
    echo("<meta HTTP-EQUIV='REFRESH' content='2; url=main.php'>");

    }
    else
    {

        echo 
    "Wrong Username or Password";

    }
    ?>
    PHP Code:
    <?php
    session_start
    ();

    if(isset(
    $_SESSION["username"]))
    {

        echo(
    "user sees thus");

    }

    ?>
    Last edited by Invent; 02-01-2008 at 03:35 PM.

  7. #7
    Join Date
    Nov 2007
    Posts
    753
    Tokens
    0

    Default

    Thanks for the help pal! Your a good un'
    +rep if i can
    Publishing free website designs, watch this space!
    Total number of designs published: 0
    Current work in progress: Landscape Design


  8. #8
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    No problem

    I hope your script works now ^^.

  9. #9
    Join Date
    Nov 2007
    Posts
    753
    Tokens
    0

    Default

    It doesnt lol but i know why now. Thanks again!
    Sorry cant rep you stupid vb
    Publishing free website designs, watch this space!
    Total number of designs published: 0
    Current work in progress: Landscape Design


Posting Permissions

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