SEVIZ Posted June 17, 2009 Share Posted June 17, 2009 Here is my code <?php include('mobile_device_detect.php'); mobile_device_detect(true,true,true,true,true,true,'mobile.php',false); ?> <?php session_start();?> <?php $password = "hellothere"; // Modify Password to suit for access, Max 10 Char. ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="en-us" http-equiv="Content-Language" /> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>Text Tool</title> <style type="text/css"> .style1 { background-image: url('bg.jpg'); } .style2 { background-image: url('t_bg.jpg'); } .style3 { background-color: #FFFFFF; } .style4 { text-align: center; } .style5 { text-align: left; font-family: Arial, Helvetica, sans-serif; font-size: Large; font-weight: bold; } .style9 { text-align: left; font-family: Arial, Helvetica, sans-serif; font-size: Medium; font-weight: bold; color: red; } .style7 { font-family: Arial, Helvetica, sans-serif; font-size: small; } .hint { text-align: center; margin-top: 2px; border: 1px solid #a1a1a1; padding: 10px 10px; background-color: #e2e2e2; width: 98%; } .box { border: 1px solid #dcdbdb; padding: 2px 2px; background-color: #f0f0f0; text-align: left; font-family: Arial, Helvetica, sans-serif; font-size: Medium; } </style> </head> <body style="margin: 0; background-color: #000000"> <?php if(isset($_SESSION['errors'])) { echo $_SESSION['errors']; unset($_SESSION['errors']); } // output form ?> <?php // If password is valid let the user get access if (isset($_POST["password"]) && ($_POST["password"]=="$password") || ($_SESSION['login'])) { ?> <!-- START OF HIDDEN HTML - PLACE YOUR CONTENT HERE --> <form action="send.php" method="post"> <table width="98%" border="0" cellspacing="0" cellpadding="4" align="center"> <tr> <td valign="top" class="style5"> Who do you want to text?<br /></td></tr> <tr> <td valign="top"> <select name="recip" class="box"> <option value="none">--- General ---</option> <option value="all">All North and South</option> <option value="sl">All Sups and Leads</option> </select> </td> </tr> <tr> <td class="style5">What do you want to say?<br /></td></tr><tr><td class="style5"><textarea name=message wrap=physical" cols="47" rows="6" id="comment" maxlength="142" class="box"></textarea></td></tr><tr><td class="style7" align="right">Characters Remaining: <input readonly type=text name=remLen size=3 maxlength=3 value="142" /> </td> </tr> <tr> <td> <!-- Reply to email (If applicable):<br /> --><input name="email" type="hidden" id="email" size="20" value="[email protected]"></td> </tr> <tr> <td valign="top" align="center"><input type="submit" name="Submit" value="Send Your Text!"></td> </tr> </table> <!-- END OF HIDDEN HTML --> <?php } else { // Wrong password or no password entered display this message if (isset($_POST['password']) || $password == "") { print "<p align=\"center\"><font color=\"red\"><b>Enter Password</b><br>Please enter the correct password</font></p>";} print "<form method=\"post\"><p align=\"center\">Please enter your password for access<br>"; print "<input name=\"password\" type=\"password\" size=\"25\" maxlength=\"10\"><input value=\"Login\" type=\"submit\"></p></form>"; } ?> </form> </body> </html> When the user logs in it lets them fill out a form which submits to a second page. That page then auto reloads back to this page. When it does that it currently asks for the login again. I want it to know its the user and to not have them login again. Someone tried to offer some help with sessions but the code does not work. It doesn't even keep you logged in. Any help is appreciated. Link to comment https://forums.phpfreaks.com/topic/162498-use-session-to-keep-logged-in/ Share on other sites More sharing options...
ozestretch Posted June 17, 2009 Share Posted June 17, 2009 if (isset($_POST["password"]) && ($_POST["password"]=="$password") || ($_SESSION['login'])) I am no expert, but there would be no password posted if session is set for login. <?php $password = "hellothere"; // Modify Password to suit for access, Max 10 Char. if (isset($_POST['password']) && ($_POST['password']==$password)){ $_SESSION['login'] = 'whatiwantittobe'; header("Location: backtothispage.php"); // force reload of the page with login session }elseif(isset($_POST['password']) && ($_POST['password']!=$password)){ $_SESSION['errors'] = "Password Incorrect"; header("Location: backtothispage.php"); // force reload of the page with login session } ?> then if(isset($_SESSION["login"])){ // my private stuff here } should be enough but not tested. Link to comment https://forums.phpfreaks.com/topic/162498-use-session-to-keep-logged-in/#findComment-857755 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.