Jump to content

Session destroy and restart


matthew798

Recommended Posts

hola.

 

So ive got my whole admin system working (if any of you have been following the compendium of posts i've been making, you'll know what i'm up to.)

 

The only thing that ISNT working, is the logout. Or it is, i just cant start up a session after i log out.

 

This is the logout script

<?php
session_start();
session_destroy();
?>

 

Now it works. Only when i try to login again with ANY credentials (of course only ones in the DB) NONE of the variables get defined. It's like the session cant register anything anymore. Did i end it right? It worked fine BEFORE i destroyed it, then after, everything is undefined...

Link to comment
https://forums.phpfreaks.com/topic/123698-session-destroy-and-restart/
Share on other sites

exact same amount of characters but anyways lol...

 

Like i said, NOTHING is registering. For some reason, no global variables are registering AT ALL. Not even ones from the DB... WTF IS GOING ON!!?!?

 

This is what processes login and assaign vars to the $_SESSION

 

<?php
session_start();
include 'dbconnect.php';
$username = ($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);

$sql="SELECT * FROM users WHERE username='$username' and password='$password'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count==1){
session_register("$username"); 
header("location:admin.html");
}
else {
echo "Wrong Username or Password. Use the back button. If you think this message is incorrect, contact the webmaster.";
}
?>

I had that problem too, what i did to get round it was send the sid to the browser,

 

login.php

<?php
require 'sessions.inc.php';
session_start();
// same as your code roughly

 

logout.php

<?php
require 'sessions.inc.php';
session_start();
unset($_SESSION);
session_destroy();
echo "you are now logged out";

 

BUT i also use a line

ini_set("session.cookie_domain", ".mysite.com");

 

That goes before the session start, and mysite replace with your site name of course.

 

Im new to php and thats what worked for me, my globals are set to off - and safe mode is on, and my browser doesnt really like cookies, so i echoed the session id which the browser then happily accepts, once I log out, and then click any link on any page i get in the address bar

http://somesite.com/page.php?PHPSID=ad399dodc

for example, maybe that would work for you too.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.