ag3nt42 Posted June 20, 2008 Share Posted June 20, 2008 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.. Quote Link to comment https://forums.phpfreaks.com/topic/111111-solved-session-problems/ Share on other sites More sharing options...
Daniel0 Posted June 20, 2008 Share Posted June 20, 2008 It has been requested that your post be split from the topic you posted it in. Quote Link to comment https://forums.phpfreaks.com/topic/111111-solved-session-problems/#findComment-570150 Share on other sites More sharing options...
dmccabe Posted June 20, 2008 Share Posted June 20, 2008 I am no expert, but does you logout page, not need session_start(); at the top? Quote Link to comment https://forums.phpfreaks.com/topic/111111-solved-session-problems/#findComment-570152 Share on other sites More sharing options...
peranha Posted June 20, 2008 Share Posted June 20, 2008 Yes, you need session_start(); at the top of the page before you can destroy it. Quote Link to comment https://forums.phpfreaks.com/topic/111111-solved-session-problems/#findComment-570153 Share on other sites More sharing options...
ag3nt42 Posted June 20, 2008 Author Share Posted June 20, 2008 ok.. i'll give that shot.. took me sometime to find my post ... Quote Link to comment https://forums.phpfreaks.com/topic/111111-solved-session-problems/#findComment-570245 Share on other sites More sharing options...
Daniel0 Posted June 20, 2008 Share Posted June 20, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/111111-solved-session-problems/#findComment-570247 Share on other sites More sharing options...
ag3nt42 Posted June 20, 2008 Author Share Posted June 20, 2008 Thanks.. ya i got it working. thanks guys Quote Link to comment https://forums.phpfreaks.com/topic/111111-solved-session-problems/#findComment-570250 Share on other sites More sharing options...
ag3nt42 Posted June 20, 2008 Author Share Posted June 20, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/111111-solved-session-problems/#findComment-570329 Share on other sites More sharing options...
DarkWater Posted June 20, 2008 Share Posted June 20, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/111111-solved-session-problems/#findComment-570334 Share on other sites More sharing options...
ag3nt42 Posted June 20, 2008 Author Share Posted June 20, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/111111-solved-session-problems/#findComment-570345 Share on other sites More sharing options...
ag3nt42 Posted June 20, 2008 Author Share Posted June 20, 2008 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.. Quote Link to comment https://forums.phpfreaks.com/topic/111111-solved-session-problems/#findComment-570394 Share on other sites More sharing options...
ag3nt42 Posted June 20, 2008 Author Share Posted June 20, 2008 nvrmd i just helped myself... if anyone is wondering its because ['Permish'] is not the same as ['permish'] (not because of logic ) still thank you for your suggestions DarkWater. Quote Link to comment https://forums.phpfreaks.com/topic/111111-solved-session-problems/#findComment-570401 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.