Jump to content

Sessions, Is this will work correctly?


apol

Recommended Posts

1. User submit a from with his "userName" and his "password".
2. "sign_in_check.php" checks if user exist in the data base and if exist then set : $_SESSION['userPass']="go";
3. When user want to sign out the sign_out.php file executed when user click on sign_out link, follows the sign_out.php:

<?php
    session_start();
    $_SESSION[]=array();

    if (isset($_COOKIE[session_name()])) {
              setcookie(session_name(), '', 0, '/');
    }
    session_unset();
    session_destroy();
    header("Location: http://localhost/project/forms/display/sign_in_form.php");
    exit();
?>


Is this logic will work ? Because when i am sign_in in my system with a valid userName & passwd and after i sign_out from the system if i press 2 times Back button in the IE browser it creates  the session again and displayes me the system index page again.

I am using to send form fields the $_GET variable and wamp5. Does anyone have any idea?

thanks
Link to comment
Share on other sites

As I understand you need to make a log out function, correct? you don't need to check if(isset), just wrtite something like this and it will delete the last session:

[code]<?php
session_start();
session_destroy();
header("Location: http://localhost/project/forms/display/sign_in_form.php");
?>[/code]
Link to comment
Share on other sites

[quote author=Gruzin link=topic=111180.msg450374#msg450374 date=1160561962]
As I understand you need to make a log out function, correct? you don't need to check if(isset), just wrtite something like this and it will delete the last session:

[code]<?php
session_start();
session_destroy();
header("Location: http://localhost/project/forms/display/sign_in_form.php");
?>[/code]
[/quote]

I did it but the problem remains. I checked the session it has deleted when i press sig_out link but when i press 2 times browsers (IE) Back button it creates the session again...I can't understand why this is happening.
Link to comment
Share on other sites

[quote author=Gruzin link=topic=111180.msg450380#msg450380 date=1160562599]
Can I see the code of that page which sets the session again?
[/quote]

Sorry this is the page...:


<?php
session_start();
if($_SESSION['adminPass']!="go"){
/*
if (isset($_COOKIE[session_name()])) {
  setcookie(session_name(), '', 0, '/');
}
session_destroy();
*/
header("Location: http://localhost/project/forms/display/sign_in_form.php");
exit();
}
?>


some html followes

thanks
Link to comment
Share on other sites

ok, try to check if the session is set, something like this:
[code]<?php
session_start();
if(isset($_SESSION['userPass'])){
?>

...some code..

<?php
}
else{
header ('Location: index.php'); // check if session is not set redirect to login page
}
?>
</body>
</html>[/code]
Link to comment
Share on other sites

[quote author=Gruzin link=topic=111180.msg450386#msg450386 date=1160563711]
ok, try to check if the session is set, something like this:
[code]<?php
session_start();
if(isset($_SESSION['userPass'])){
?>

...some code..

<?php
}
else{
header ('Location: index.php'); // check if session is not set redirect to login page
}
?>
</body>
</html>[/code]
[/quote]




I changed it to that :

<?php
session_start();
if(isset($_SESSION['adminPass'])&&$_SESSION['adminPass']!='go'){
header("Location: http://localhost/project/forms/display/sign_in_form.php");
exit();
}
?>

and if click one time the Back button it inserts me in the system index page....I am confused....
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.