supermerc Posted March 7, 2007 Share Posted March 7, 2007 Hey, Im trying to make it so that when someone goes to my website on the right there will be a login form if they arnt logged in, and if they are, I include a little welcome page. <?php if($_SESSION['s_logged_n'] = 'true'){ include'welcome.php'; } else{ echo'<form method="post" action="login.php"> <p align="center"><span class="style15">Username:<br> <input name="username" type="text" class="textBox" id="username" size="20"> <br> Password:<br> <input name="password" type="password" class="textBox" id="password" size="20"> <br> Click <a href="register.php" target="main">Here</a> To Register </span><br> <input name="login" type="submit" class="textBox" id="login" value="Submit"> </form>'; } ?> But right now, as soon as you go on my page, http://random.awardspace.biz/ It includes welcome.php even when you arnt logged in. If you want to test it out use test as username and testtest as password. Link to comment https://forums.phpfreaks.com/topic/41543-solved-if-ane-else-statements/ Share on other sites More sharing options...
redarrow Posted March 7, 2007 Share Posted March 7, 2007 if($_SESSION['s_logged_n'] == 'true'){ Link to comment https://forums.phpfreaks.com/topic/41543-solved-if-ane-else-statements/#findComment-201309 Share on other sites More sharing options...
supermerc Posted March 7, 2007 Author Share Posted March 7, 2007 It still doesnt work :-( Link to comment https://forums.phpfreaks.com/topic/41543-solved-if-ane-else-statements/#findComment-201310 Share on other sites More sharing options...
SharkBait Posted March 7, 2007 Share Posted March 7, 2007 Check to see you're setting the session? <?php if(isset($_SESSION['s_logged_in'])) { // Woo I'm in } ?> Link to comment https://forums.phpfreaks.com/topic/41543-solved-if-ane-else-statements/#findComment-201338 Share on other sites More sharing options...
Archadian Posted March 7, 2007 Share Posted March 7, 2007 setting a cookie when they login and deleting it when they log out then: if (isset($_COOKIE['test'])) { // Welcome.php } else { // login script } Don't use sessions because they get deleted once they close the web browser, unless you want them to login each time the visit. But cookies are the best way to go either way. Link to comment https://forums.phpfreaks.com/topic/41543-solved-if-ane-else-statements/#findComment-201341 Share on other sites More sharing options...
redarrow Posted March 7, 2007 Share Posted March 7, 2007 try mine agin and use <?php session_start(); ?> on every page that has sessions on it. Link to comment https://forums.phpfreaks.com/topic/41543-solved-if-ane-else-statements/#findComment-201346 Share on other sites More sharing options...
supermerc Posted March 7, 2007 Author Share Posted March 7, 2007 try mine agin and use <?php session_start(); ?> on every page that has sessions on it. I already have session start, here is my full code: <?php session_start(); require("config.php"); require("functions.php"); ?> <html> <head> <style type="text/css"> body{ margin: 0; } </style> <title>My Site</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <!-- DO NOT DELETE THE MARGIN TAGS, THESE STOP WHITE GAPS ON ALL EDGES OF THE PAGE --> <?php include 'header.php'; ?> <!-- START OF MAIN CONTENT AREA --> <tr><table width="100%" border="0"> <tr> <td valign="top" width="220"><!-- START OF NAVIGATION --><table width="200" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="4%"><img src="images/lborder.gif" width="21" height="24"></td> <td width="90%" background="images/bgborder.gif"><div align="center"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Main Navigation</font></div></td> <td width="6%"><img src="images/rborder.gif" width="6" height="24"></td> </tr> <tr> <td colspan="3"><table width="195" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000" style="border-collapse: collapse"> <tr> <td> <!-- START OF CONTENT BOX CONTENT --> <font size="1" face="Verdana, Arial, Helvetica, sans-serif"><?php include'navigation.php'; ?> </font> <!-- END OF CONTENT BOX CONTENT --> </td> </tr> </table></td> </tr> </table><!-- END OF NAVIGATION --><br><!-- START OF NAVIGATION --><table width="200" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="4%"><img src="images/lborder.gif" width="21" height="24"></td> <td width="90%" background="images/bgborder.gif"><div align="center"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Main Navigation</font></div></td> <td width="6%"><img src="images/rborder.gif" width="6" height="24"></td> </tr> <tr> <td colspan="3"><table width="195" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000" style="border-collapse: collapse"> <tr> <td> <!-- START OF CONTENT BOX CONTENT --> <font size="1" face="Verdana, Arial, Helvetica, sans-serif">text etc here</font> <!-- END OF CONTENT BOX CONTENT --> </td> </tr> </table></td> </tr> </table><!-- END OF NAVIGATION --></td> <td width="100%" valign="top"><!--MAIN CENTER CONTENT AREA START--> <table width="95%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td><img src="images/lborder.gif" width="21" height="24"></td> <td width="100%" background="images/bgborder.gif"><div align="center"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">News</font></div></td> <td><img src="images/rborder.gif" width="6" height="24"></td> </tr> <tr> <td colspan="3"><table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000" style="border-collapse: collapse"> <tr> <td> <div align="center"> <font size="2" face="Verdana, Arial, Helvetica, sans-serif">News will go here. </font> </div></td> </tr> </table></td> </tr> </table><br><table width="95%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td><img src="images/lborder.gif" width="21" height="24"></td> <td width="100%" background="images/bgborder.gif"><div align="center"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Main Content Area</font></div></td> <td><img src="images/rborder.gif" width="6" height="24"></td> </tr> <tr> <td colspan="3"><table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000" style="border-collapse: collapse"> <tr> <td> <div align="center"> <font size="2" face="Verdana, Arial, Helvetica, sans-serif">Your Content! </font> </div></td> </tr> <tr> <td bgcolor="#E8E8E8"><div align="center"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Copyright 2005 - Random - All Rights Reserved </font></div></td> </tr> </table></td> </tr> </table> <!--MAIN CENTER CONTENT AREA END--></td> <td width="220" valign="top"><!-- START OF NAVIGATION --> <table width="200" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="4%"><img src="images/lborder.gif" width="21" height="24"></td> <td width="90%" background="images/bgborder.gif"><div align="center"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Members Area</font></div></td> <td width="6%"><img src="images/rborder.gif" width="6" height="24"></td> </tr> <tr> <td colspan="3"><table width="195" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000" style="border-collapse: collapse"> <tr> <td><!-- START OF CONTENT BOX CONTENT --> <font size="1" face="Verdana, Arial, Helvetica, sans-serif"> <?php if($_SESSION['s_logged_n'] == 'true'){ include'welcome.php'; } else{ echo'<form method="post" action="login.php"> <p align="center"><span class="style15">Username:<br> <input name="username" type="text" class="textBox" id="username" size="20"> <br> Password:<br> <input name="password" type="password" class="textBox" id="password" size="20"> <br> Click <a href="register.php" target="main">Here</a> To Register </span><br> <input name="login" type="submit" class="textBox" id="login" value="Submit"> </form>'; } ?> </font> <!-- END OF CONTENT BOX CONTENT --> </td> </tr> </table></td> </tr> </table> <!-- END OF NAVIGATION --></td> </tr> </table> <td colspan="2"> </td> </tr> <!-- END OF MAIN CONTENT AREA --> </table> </html> Link to comment https://forums.phpfreaks.com/topic/41543-solved-if-ane-else-statements/#findComment-201351 Share on other sites More sharing options...
redarrow Posted March 7, 2007 Share Posted March 7, 2007 <?php if($_SESSION['s_logged_n']){ include'welcome.php'; } else{ echo'<form method="post" action="login.php"> <p align="center"><span class="style15">Username:<br> <input name="username" type="text" class="textBox" id="username" size="20"> <br> Password:<br> <input name="password" type="password" class="textBox" id="password" size="20"> <br> Click <a href="register.php" target="main">Here</a> To Register </span><br> <input name="login" type="submit" class="textBox" id="login" value="Submit"> </form>'; } ?> Link to comment https://forums.phpfreaks.com/topic/41543-solved-if-ane-else-statements/#findComment-201355 Share on other sites More sharing options...
supermerc Posted March 7, 2007 Author Share Posted March 7, 2007 Thanks i think it works! Link to comment https://forums.phpfreaks.com/topic/41543-solved-if-ane-else-statements/#findComment-201358 Share on other sites More sharing options...
redarrow Posted March 7, 2007 Share Posted March 7, 2007 yes it works just checked your site ok? Link to comment https://forums.phpfreaks.com/topic/41543-solved-if-ane-else-statements/#findComment-201368 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.