Jump to content

New help on Session and ending session....


DigitalGuard

Recommended Posts

Hello,

 

I'm using the following script to login in to my member area

pass.php

 

<?php if ($_POST["username"]=="") { ?> 
    <html>
    <title>Our private pages</title>
    <body>
    In order to access this pages fill the form below:<BR>
    <form method="post" action="pass.php">
    Username: <input type="text" name="username" size="20"><BR>
    Password: <input type="password" name="password" size="15"><BR> 
    <input type="Submit" value="Submit">
    </form>
    </body>
    </html>

<?php }else{ 
    $username=$_POST["username"];
    $password=$_POST["password"];

    session_start();
   if ($username=="Joe" AND $password=="hi"){ $permission="yes";}
   if ($username=="Peter" AND $password=="hello"){ $permission="yes";}

   $username=$_POST["username"];
    session_register("permission");   
    session_register("username");  

    if ($permission=="yes"){
   ?> 
        <html>
        <title>Our private pages</title>
        <body>   
        Hi, you are allow to see these pages: <BR>
        <A HREF="page1.php">Page 1</A><BR>
        <A HREF="page2.php">Page 2</A><br>
<a href="destroy.php">Log Off</a>

        </body>
        </html>

    <?php }else{ ?>

    Error in username or password

    <?php } ?>
<?php } ?> 

 

 

 

My page1 has the following code:

 

<?php 
session_start();
if ($permission=="yes") { 
?> 
    <html>
    <title>Page 1</title>
    <body>
    
    Hi, welcome to Page 1 <BR> 
    This page is empty at the moment, but it will be very interesting in the next future

    </body>
    </html>

<?php }else{ ?> 
    You are not allowed to access this page

<?php } ?>

I have a page called destroy.php and it has the following:

 

<?php
   session_destroy();
   unset($_SESSION['permission']);
   echo "Session Died";
?> 

 

My problem is, I can log in and see the page1, after loggin in but when i want to log off the session, i tried unset & destroy, and it just wont log off, on the login page, it goes to the page and i can type in user: (anything) password (anything) and it will still log in and page1 wont even check security cause it thinks its logged.

 

Thanks

DigitalGuard

Link to comment
Share on other sites

on the first script dont use session register,

 

just do $_SESSION['permission'] = "yes";

and do that for the rest of your session variables

 

and on the second page when you're checking for the

permission do use $permission do it like this:

 

if($_SESSION['permission'] == "yes"){

// execute code....

} else{

// execute code

}

Link to comment
Share on other sites

on the first script dont use session register,

 

just do $_SESSION['permission'] = "yes";

and do that for the rest of your session variables

 

and on the second page when you're checking for the

permission do use $permission do it like this:

 

if($_SESSION['permission'] == "yes"){

// execute code....

} else{

// execute code

}

 

Tried this, but not page1.php wont even see the session, it always says not allowed....

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.