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
Share on other sites

ok.. i'll give that shot.. took me sometime to find my post ... :(

 

You can always see your topics and posts from your profile and you can click the "Show new replies to your posts" to check if there are any new replies in topics you've posted in.

Link to comment
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?

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

anyone?  any suggestions are appreciated thanks,

 

Not sure why but after login sessions are correct yet when naving back to index.php they are set back to 0 i duno how that is happening.. its like the session is not being carried over to the next page..

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.