Jump to content

[SOLVED] Session problems


ag3nt42

Recommended Posts

I also am having a sessions problem... I can't seem to destroy my sessions.

I have it started and holding variables and what not.. but then when I click on my "logout" button.

your sent to a logout page with this code on it...

 

<?php
session_destroy();

echo("<h1>LOGGING OUT..</h1><br /><script>logoutwindow.close();</script>");

?>

 

but it only gives back this error msg:

 

Warning: session_destroy() [function.session-destroy]: Trying to destroy uninitialized session in logout.php on line 2

LOGGING OUT..

Link to comment
https://forums.phpfreaks.com/topic/111111-solved-session-problems/
Share on other sites

OK.. so for some reason I cannot stay logged in..

 

When on index.php a check is ran to see if i'm logged in.. here is the code for that:

 

if(!(isset($_SESSION['permish'])))
{
$_SESSION['permish']="0";
}
else
{
$_SESSION['permish']=$_SESSION['permish'];
}


if(!(isset($_SESSION['permish'])))
{
echo('');
}
else
{
if($_SESSION['permish']=='1'||$_SESSION['permish']=='42')
{
	echo('<a title="Logout" href="javascript:destroy();" onclick="destroy();"><img alt="" onmouseout="this.src=\'imgs/Logout-1.png\'" onmouseover="this.src=\'imgs/Logout-2.png\'" src="imgs/Logout-1.png" /></a>');
}
elseif($_SESSION['permish']=='0')
{
	echo('<a title="Login" href="javascript:openLogin();" onclick="openLogin();"><img alt="" onmouseout="this.src=\'imgs/Login-1.png\'" onmouseover="this.src=\'imgs/Login-2.png\'" src="imgs/Login-1.png" /></a>');
}
}

 

on my login page. is this code:

 

////////////////////////////
///* COLLECT LOGIN INFO *///
////////////////////////////

if(!(isset($_POST['username'])))
{
$Fusername="";
}
else
{
$Fusername=$_POST['username'];
}

if(!(isset($_POST['password'])))
{
$Fpassword="";
}
else
{
$Fpassword=$_POST['password'];
}

/////////////////////////////////////
///* CHECK THE DATABASE FOR USER *///
/////////////////////////////////////
$datatable=$tblpre."Users";

//* Encrypt Pass *//
$Epassword=bin2hex($Fpassword);

$UserSQL="SELECT Username FROM [".$datatable."] WHERE Username='".$Fusername."'";
$UpasSQL="SELECT Password FROM [".$datatable."] WHERE Username='".$Fusername."'";
$UPerSQL="SELECT Permissions FROM [".$datatable."] WHERE Username='".$Fusername."'";

//USER
$Userresult = mssql_query($UserSQL) or die(mssql_error());
$Usercount=mssql_num_rows(mssql_query($UserSQL));
while($Userrow=mssql_fetch_row($Userresult))
{
$ZUser=$Userrow[0];
}

//Pass
$Upasresult = mssql_query($UpasSQL) or die(mssql_error());
$Upascount=mssql_num_rows(mssql_query($UpasSQL));
while($Upasrow=mssql_fetch_row($Upasresult))
{
$ZUpas=$Upasrow[0];
}

//Permissions
$UPerresult=mssql_query($UPerSQL)or die(mssql_error());
$UPercount=mssql_num_rows(mssql_query($UPerSQL));
while($UPerrow=mssql_fetch_row($UPerresult))
{
$ZPer=$UPerrow[0];
}

if(!(isset($_POST['username'])))
{
echo('');
}
else
{
//////////////////////////////////
///** VALIDATE THE USER INFO **///
//////////////////////////////////

//* DOES USER EXIST?
if($ZUser==$Fusername){$UserUser='Yes';}else{$UserUser='No';}

//* IS PASS CORRECT?
if($ZUpas==$Epassword){$UserPass='Yes';}else{$UserPass='No';}

if($UserUser=='Yes'&&$UserPass='Yes')
{
echo('<center><span class="Logged">You have been successfully logged in!</span></center><br />');
$logged='Yes';
$_SESSION['Permish']=$ZPer;
echo('<br />'.$ZPer."<br />");
echo('Welcome back to Lotus '.$ZUser);
}
}

 

now on the index.php page it looks for the session variable permish.. and if its  1 or 42 then your logged in. otherwise your not. so my question is why am i not logged on only on the index page?

Your logic makes no sense.

 

If it's not set, make it 1.  Otherwise make it itself.

Then right after:

If it's not set, echo '', else, echo some other stuff.

 

But it'll always be set because you set it to 1 before.  And it'll never be:

elseif($_SESSION['permish']=='0')

 

Because that loop only occurs if permish ISN'T set.  You need to rewrite your logic. 

sry i believe you are reading my code incorrectly.. If its not set the its being set to 0 which 0 is the same as not being logged on.. if it is set then the its = to watever its already set as.

 

the logic is fine. and its echoing out as 0 so.. i duno wat yur talking about.

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.