PHP ending sessions(different ways) i dont understand
<p>Im trying to understand sessions and how some of the functions to end them work.
Ive gone to different sites/and even here on SO and........well essentially, nothing is working.</p>

<p>I have an app im trying to work on and when the user logs in, i store the username like so
(not going to paste the whole code but you get the idea)</p>

<pre><code>if($row == 1){
    session_start();
    $_SESSION['usrname'] = $login_usrname;
    $_SESSION['usrpass'] = $login_usrpass;
    header("Location:index.php");
    exit;
}
</code></pre>

<p>On the index page of said app i have a check like so</p>

<pre><code>session_start();
if(!isset($_SESSION['usrname']) &amp;&amp; !isset($_SESSION['usrpass'])){ 
    header("Location:login-acc.php");
    exit;
}
</code></pre>

<p>and it lets them in. I check the cookies in firefoxes web dev tools and i see it being generated so im going to say "its working" so far.</p>

<p>Now when i want to log out, Long story short i have a logout link that takes them to a page thats supposed to clear all session data and redirect them to the login page. When im testing the app and i click the logout link, i get redirected to the login page but when i go back and click the "index page" link. it lets me right in.</p>

<p>In the logout file, trying to <strong>FORCE</strong> the issue in overkill lol, i have this and nothing seems to work.</p>

<pre><code>unset($_SESSION['usrname']);
unset($_SESSION['usrpass']);

session_unset();

$_SESSION = array();
session_destroy();

setcookie('PHPSESSID', '', time()-3600,'/', '', 0, 0);

header("Location:login-acc.php");
exit;
</code></pre>

<p>It redirects me to the login page but again, when i manually go to index page it lets me right in. Or after being redirected to the login page, i hit the "back" button and lets me right in as well.</p>

<p>If i then go into FF Web developer tools app and delete all cookies etc, and navigate to the index page, then it locks me out.</p>

<p>As you can see above ive tried multiple things and in the end, i threw them all together which should do something.....My question is...since ive put in ALL those functions to try and delete/unset/remove in general the session...what else can i do? im a bit lost as to how its supposed to work.</p>

<p>Can someone steer me in the right direction?</p>

<p>thanks in advanced.</p>
