Jump to content

Login on same page


graham23s

Recommended Posts

Hi Guys,

 

in my login page i redirect to a second page logincheck.php to check the details then redirect to the myaccount.php page when all is well, but i'm not sure how to put the code in the 1 page, because headers can't be sent twice error

 

login.php

 

<?php
  echo ("<table width=\"100%\"  border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#FF0000\"> 
         <tr> 
         <td valign=\"top\">");
   
  ## login
  echo ("<form action=\"logincheck.php\" method=\"POST\">");
  echo ("<table class=\"tablesmain\" align=\"left\" width=\"300\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\">");
  echo ("<tr>");
  echo ("<td class=\"header_boxes\" colspan=\"2\" align=\"left\"><span class=\"header_txt\">Members Login</span></td>");
  echo ("</tr>");
  echo ("<tr>");
  echo ("<td align=\"right\"><b>Username:</b></td><td align=\"left\"><input type=\"text\" name=\"username\"></td>");
  echo ("</tr>");
  echo ("<tr>");
  echo ("<td align=\"right\"><b>Password:</b></td><td align=\"left\"><input type=\"password\" name=\"password\"></td>");
  echo ("</tr>");
  echo ("<tr>");
  echo ("<td colspan=\"2\" align=\"right\">[<a class=\"foot_links\" href=\"recoverpassword.php\">FORGOT PASSWORD</a>]  <input type=\"submit\" class=\"btn\" name=\"submit\" value=\"Login\"></td>");
  echo ("</tr>");
  echo ("</table></form>");
  
  ## new table cell data
  echo ("</td>");
  echo ("<td valign=\"top\" align=\"left\">");
  echo ("<ul>");
  echo ("<li>Search performers by location</li>");
  echo ("<li>Send unlimited messages</li>");
  echo ("<li>Leave comments on performers profiles</li>");
  echo ("<li>Rate your fellow members</li>");
  echo ("<li>Write your own blog</li>");
  echo ("<li><b>Plus MUCH more join today!</b></li>");
  echo ("<li><a class=\"foot_links\" href=\"register.php\">Not a member yet? sign up here!</a></li>");
  echo ("</ul>");
  //echo ("<br />");
  echo ("<img src=\"images/placeholder.jpg\">");
  
  ## end html tables
  echo ("</td> 
         </tr> 
         </table>");
?>
<?php
     // include the footer...////////////////////////////////////////////////////////////
     include("includes/footer.php");
?>

 

 

logincheck.php

 

<?php
  require("includes/db_connection.php");
  
  ## The all important post variables
  $var_username = mysql_real_escape_string(trim($_POST['username']));
  $var_password = mysql_real_escape_string(trim($_POST['password']));
  
  ## blank submission
  if(empty($var_username) || empty($var_password)) {
  
  echo '<div align="center" style="border: 1px solid black;padding:10px; background: yellow; color: #000000; font-size: 14px;"><b>You never filled in both fields, please fill them both in.</b></div><br />';
  exit;	
  
  }
  
  $q = "SELECT `id`,`username`,`password` FROM `users` WHERE `username`='$var_username' AND `password`='$var_password' LIMIT 1";
  $r = mysql_query($q);
  $row = mysql_fetch_array($r);
  
  $any_results = mysql_num_rows($r);
  
  if($any_results != 1) {
  
  echo '<div align="center" style="border: 1px solid black;padding:10px; background: yellow; color: #000000; font-size: 14px;"><b>We can\'t find that username/password combination in the database, please re-check your login details.</b></div><br />';
  exit;	
     
 } else {

  ## update the login timer
  $var_update_time_query = mysql_query("UPDATE `users` SET `lastlogin` = now() WHERE `username`='$var_username' AND `password`='$var_password'");

  ## There was a result back
  session_start(); 
  $_SESSION['id'] = $row['id'];
  $_SESSION['username'] = $row['username'];
  $_SESSION['loggedin'] = 'yes'; 
  
  ## redirect to members page
  header("Location:myaccount.php"); 

  }
?>

 

is there any way around this or will i just need to stick with the 2 pages?

 

thanks guys

 

Graham

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.