| | |
Session destroy not working....
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
auth.php
logout.php
The codes above working fine, after I log out, if I paste the direct link to the admin.php, it won't go. But the problem is, when I log out, if I press the back button on the browser (firefox), it will back to admin.php.*
Please help.
* echo part in both codes was temporarily changed to save page.
php Syntax (Toggle Plain Text)
<?php // start session session_start(); // convert username and password from _POST or _SESSION if($_POST){ $_SESSION['username']=$_POST['username']; $_SESSION['password']=$_POST['password']; } // query for a user/pass match $result = mysql_query("SELECT * FROM users WHERE username='" . $_SESSION['username'] . "' and password='" . $_SESSION['password'] . "'"); // retrieve number of rows resulted $user = mysql_num_rows($result); // print login form and exit if failed. if($user < 1){ echo " Please login"; ?>
logout.php
php Syntax (Toggle Plain Text)
<?php // logout.php // you must start session before destroying it session_start(); session_unset(); session_destroy(); //} //echo "You have been successfully logged out. echo " logged. Out."; ?>
The codes above working fine, after I log out, if I paste the direct link to the admin.php, it won't go. But the problem is, when I log out, if I press the back button on the browser (firefox), it will back to admin.php.*
Please help.
* echo part in both codes was temporarily changed to save page.
Last edited by lordx78; Mar 11th, 2008 at 3:00 am.
"I might not be the BEST but I'm not like the REST!"
redirect your page to somewhere so that when back button is clicked he cannot go back to the auth.php.
change this:
to:
change this:
php Syntax (Toggle Plain Text)
echo " logged. Out.";
to:
php Syntax (Toggle Plain Text)
header('Location:index.php');
What's in your admin.php page ? Are you checking if the session is valid or it has expired ? The best way to completely destroy the session is to redirect the page after you destroy the session. When the user clicks on the logout link, I do it this way.
Edit: Or you can do as ryan_vietnow has mentioned..
Its much easier way.
php Syntax (Toggle Plain Text)
<a href="index.php?logout=true">Logout</a> ..... //in index.php session_start(); .... if(isset($_REQUEST['logout']) && $_REQUEST['logout']=='true')){ session_destroy(); }
Its much easier way. Last edited by nav33n; Mar 11th, 2008 at 3:11 am.
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
* echo part in both codes was temporarily changed to save page.
the actual echo was;
*ignore the <?php and ?>
the actual echo was;
php Syntax (Toggle Plain Text)
<?php //echo "You have been successfully logged out. echo " <html> <head> <title>Cycle Tracks Portal</title> <style type='text/css' media='all'>@import 'images/style.css'; </style> <link rel='alternate' type='application/rss+xml' title='RSS 2.0' href='rss/' /> </head> <body> <div class='content'> <div class='topmenu'> <div class='date_'>"; echo date('l dS \of F Y'); echo "</div> </div> <div id='submenu'> <form action='#'> </form> <br> </div> <div class='cycle1'> <div class='title' style='text-align: center; width: 179px'> </div> <div class='slogan' style='width: 223px; height: 11px'></div> </div>"; echo "<div><br> <p style='font-family:Calibri; color:#0066FF; font-size: large; text-align:center'>You have been <span style='color:green'>Successfully</span> logged out.</p> </div>"; echo " <marquee style=' width: 100%; height: 10%; behavior: scroll' direction='up' scrollamount='7'><p style='font-family:Calibri; color:#0066FF; font-size: large; text-align:center'>You will be now returned to the Main page.</p></marquee> <div class='footer'> <div class='padding'> © Copyright Cycle Tracks <span>®</span> </div> </div> </div> </body> </html> <META HTTP-EQUIV=\"refresh\" content=\"5; URL=index.html\"> "; ?>
*ignore the <?php and ?>
"I might not be the BEST but I'm not like the REST!"
just make this actual echo a separate page(e.g. redirect.php) then change the header location as I mentioned earlier as redirect.php
•
•
Join Date: Dec 2007
Posts: 205
Reputation:
Solved Threads: 11
•
•
•
•
auth.php
php Syntax (Toggle Plain Text)
<?php // start session session_start(); // convert username and password from _POST or _SESSION if($_POST){ $_SESSION['username']=$_POST['username']; $_SESSION['password']=$_POST['password']; } // query for a user/pass match $result = mysql_query("SELECT * FROM users WHERE username='" . $_SESSION['username'] . "' and password='" . $_SESSION['password'] . "'"); // retrieve number of rows resulted $user = mysql_num_rows($result); // print login form and exit if failed. if($user < 1){ echo " Please login"; ?>
$_SESSION['views']=1;
Initially keep the session variable as 0
$_SESSION['views']=0;
•
•
•
•
logout.php
php Syntax (Toggle Plain Text)
<?php // logout.php // you must start session before destroying it session_start(); session_unset(); session_destroy(); //} //echo "You have been successfully logged out. echo " logged. Out."; ?>
The codes above working fine, after I log out, if I paste the direct link to the admin.php, it won't go. But the problem is, when I log out, if I press the back button on the browser (firefox), it will back to admin.php.*
Please help.
* echo part in both codes was temporarily changed to save page.
$_SESSION['views']=0;
In all other pages check whether your $_SESSION['views'] is set or not . if not set direct the user to any warning page
[code=php]
<?php
ob_start();
session_start();
if($_SESSION['views']==0)
header("Location:error.php");
ob_flush();
?>
Last edited by carobee; Mar 11th, 2008 at 4:02 am.
•
•
Join Date: Apr 2006
Posts: 66
Reputation:
Solved Threads: 11
First of all, session_destroy() deletes everything you have stored on your session. if you only want to logout some user, simply use unset($_SESSION['user']) and after that redirect to the login page (or your index page). For this you can also use javascript to force redirect.
![]() |
Similar Threads
- How to create a web page? (PHP)
- Maintaining SESSIONS (PHP)
- Antivirus Gold/SpySheriff/Smitfraud Problems (Viruses, Spyware and other Nasties)
Other Threads in the PHP Forum
- Previous Thread: php salary field
- Next Thread: WAMP Server
Views: 6127 | Replies: 7
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic ebooks echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla jquery js limit link login loop mail mediawiki menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select server sessions sms soap source space speed sql stored structure subdomain syntax system table tutorial update updates upload url validation validator variable video web xml youtube






