Jump to content

Use session to keep logged in


SEVIZ

Recommended Posts

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="sys@sys.com"></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
Share on other sites

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
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.