Wudhead Posted January 19, 2010 Share Posted January 19, 2010 Basically i have a simple login system that just uses sessions, but the code that I have used on certain pages (so that only a logged in member can access the page) doesn't seem to be working properly. Here is the code: <?php session_start(); if (isset($_SESSION['myusername'])){ echo ("boo!"); } else { echo ("meh!"); } ?> The actual sessions work fine, as when I have actually logged in it displays the "boo!" message, and doesn't when not logged in. However, when the IF statement doesn't apply, it doesn't seem to want to go to the ELSE statement. I do appologise if this is something stupid or simple - but I am new to php! Cheers! Link to comment https://forums.phpfreaks.com/topic/189029-wont-process-else-even-when-if-doesnt-apply/ Share on other sites More sharing options...
Buddski Posted January 19, 2010 Share Posted January 19, 2010 What you have there SHOULD work. I am going to say that there could be something else at fault.. Is this the only output you see or is there HTML somewhere... I am thinking you might have an error stopping script execution when that session var is not there.. ensure error_reporting(E_ALL); ini_set('display_errors',1); Link to comment https://forums.phpfreaks.com/topic/189029-wont-process-else-even-when-if-doesnt-apply/#findComment-998050 Share on other sites More sharing options...
Wudhead Posted January 19, 2010 Author Share Posted January 19, 2010 Yes that is the opening script, the HTML is as follows: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>page</title> <link rel="stylesheet" type="text/css" href="style.css"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body text="#FFFFFF" style="background-color:#000000"> <table width="1024" height="768" border="0"> <tr background="images/page_template_01.gif"> <td width="1024" height="200" colspan="2"></td> </tr> <tr> <td width="400" height="68" background="images/page_template_02.gif"></td> <td width="624" height="68" background="images/page_template_03.gif"></td> </tr> <tr> <td width="400" align="center" valign="top" background="images/page_template_04.gif"><p><font face="Verdana, Arial, Helvetica, sans-serif"><a href="index.htm">Home</a></font></p> <p><font face="Verdana, Arial, Helvetica, sans-serif"><a href="register.htm">Register</a></font></p> <p><font face="Verdana, Arial, Helvetica, sans-serif"><a href="login.htm">Login</a></font></p> <p><font face="Verdana, Arial, Helvetica, sans-serif"><a href="post_blog.htm">Post Blog</a></font></p> <p><font face="Verdana, Arial, Helvetica, sans-serif"><a href="search.htm">Search</a></font></p> <p><font face="Verdana, Arial, Helvetica, sans-serif"><a href="browse.htm">Browse Blogs</a></font></p></td> <td width="624" align="left" valign="top" background="images/page_template_05.jpg"> <br> <form action="blog_insert.php" method="get"> Title: <input type="text" name="title"/><br> <br> Message:<br> <textarea name="msg" cols="60" rows="10"></textarea> <br> <br> <input type="Submit" value="Submit Message"> </form> </td> </tr> </table> </body> Link to comment https://forums.phpfreaks.com/topic/189029-wont-process-else-even-when-if-doesnt-apply/#findComment-998054 Share on other sites More sharing options...
ChemicalBliss Posted January 19, 2010 Share Posted January 19, 2010 Please confirm this script does what it says: test.php <?php session_start(); // Session Start if(isset($_GET['make'])){ $_SESSION['myusername'] = true; }else{ unset($_SESSION['myusername']); } if (isset($_SESSION['myusername'])){ echo ("boo!"); } else { echo ("meh!"); } echo("<br /><a href='test.php?make=boo'>Make me Boo!</a><Br /> <a href='test.php?'>Make me Meh!</a><Br />"); ?> If it does, you have an error in your script. You need to debug your code. Please provide the entire php script (mark out any sensitive data, but leave all code). Debugging code consists of outputting variables at specific points, or forcing variables to hold specific data that should work. This way you can pin-point the location or in-fact, offending characters that are preventing expected results. -CB- Link to comment https://forums.phpfreaks.com/topic/189029-wont-process-else-even-when-if-doesnt-apply/#findComment-998067 Share on other sites More sharing options...
Wudhead Posted January 19, 2010 Author Share Posted January 19, 2010 Right basically, i've tested my script abit more, and the loop does work, but it only seems to work when coming from the login page - even if I haven't actually submitted anything to the script. I think I need to just go over every page and apply the session rules. If anyone has any ideas from what i've just said i'm all ears - but to be honest I think i might be able to fix this myself with abit more time now. Thanks for the swift replies guys! Link to comment https://forums.phpfreaks.com/topic/189029-wont-process-else-even-when-if-doesnt-apply/#findComment-998072 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.