Jump to content

[SOLVED] Session Login, header loaction issues?


matt.sisto

Recommended Posts

Hello,

 

I have sorted out my login, which when checked header:location to cal.php. For some when it reaches cal.ph it redirects to loginform1.php but if I change the header location it is ok?

 

logincheck1.php:
<?php
  
session_start();
require "dbconn2.php";

//Using the function mysql_real_escape_string() AFTER a connection
//has been established will clean incoming variables and prevent
//users from tampering with your SQL by inserting some of their own
$email_address = mysql_real_escape_string($_POST['email_address']);
$passwd = mysql_real_escape_string($_POST['passwd']);
$id = mysql_real_escape_string($_POST['id']);


if($id == 'client') {
   $sql = "SELECT * FROM client WHERE email_address='".$email_address
        ."' AND passwd='".$passwd."'";
   $result = mysql_query ($sql, $connection) or die ("Could not perform query $sql <br />".mysql_error());
   $row = mysql_fetch_row($result);
}
else if($id == 'consultant') {
   $sql = "SELECT * FROM consultant WHERE email_address='".$email_address
        ."' AND passwd='".$passwd."'";
   $result = mysql_query ($sql, $connection) or die ("Could not perform query $sql <br />".mysql_error());
   $row = mysql_fetch_row($result);
}
else if($id == 'organisation') {
    $sql = "SELECT * FROM organisation WHERE email_address='".$email_address
        ."' AND passwd='".$passwd."'";
   $result = mysql_query ($sql, $connection) or die ("Could not perform query $sql <br />".mysql_error());
   $row = mysql_fetch_row($result);
}
else{
   echo 'Incorrect type';
}

if ($row != null)

{
      $_SESSION['username'] = $row['first_name'];
      header("Location: index.html");
      exit();
}

else
{
	header("Location: loginform1.php");
	exit();
}
     
?>

<!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 http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>logincheck1.php</title>
</head>

<body>
</body>
</html>

 

cal.php
<?php
session_start();

  if (!isset($_SESSION['username']))
    {
header("Location: loginform1.php");
echo ("Welcome $session[username]");
exit();
    }
?>

<!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 http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>

<div align="center">
<?php
	if ((!isset($_GET["Month"])) && (!isset($_GET["Year"]))) {
	 $Month = date("m");
	 $Year = date("Y");
	} else {
	 $Month = $_GET["Month"];
	 $Year = $_GET["Year"];
	} 
	$Timestamp = mktime(0,0,0,$Month,1,$Year); 
	$MonthName = date("F", $Timestamp); 
?>

<?php

	echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"3\">";
	echo "<tr><td colspan=\"7\" align=\"left\">Calendar Table for $MonthName, $Year</td></tr>";
	echo "<tr bgcolor=\"#999999\">"; 

	$daysOfWeek = array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");

	foreach ($daysOfWeek as $value) {
	  echo "<td align=\"center\"><strong><font color=\"#ffffff\">$value</font></strong></td>";
	}
	echo "</tr>"; 

	$MonthStart = date("w", $Timestamp);
	if ($MonthStart == 0) { 
	  // if the month starts on a Sunday
	  $MonthStart = 7;
	} 


	$LastDay = date("d", mktime(0,0,0,$Month+1, 0, $Year)); 
	$StartDate = -$MonthStart; 


	for ($k=1;$k<=6;$k++){  //print six rows for six possible weeks
	  echo"<tr>"; 
	  for ($j=1;$j<=7;$j++){ //seven columns per row 
	    $StartDate++;
	    if($StartDate < $LastDay) { //blank calendar space
	      if($StartDate > 0) {
	        echo"<td>$StartDate</td> \n";  
	      } else {
			echo"<td bgcolor=\"#eeeeee\"></td> \n";  
		  }
	    } elseif (($StartDate <=1) && ($StartDate >= $LastDay)) { //date goes here
	      if($StartDate >= 0) {
	        echo"<td>$StartDate</td> \n";  
	      }	
	    }
	} 
	echo"</tr>"; 
	} //End Table Row 

	echo "</table>";
?>
<hr width="200">
<form action="cal.php" accept-charset="UNKNOWN" enctype="application/x-www-form-urlencoded" method="GET" > 
	<?php
		echo "<select name=\"Month\">";
		for($m=1;$m<=12;$m++){  
		  $selected = "";
		  $longDate = date("F", mktime(0,0,0,$m,1,$Year));
		  if ($Month==$m){ 
			$selected = "selected ";
		  }
		  echo "<option value=\"$m\" $selected>$longDate</option> \n";
		}
		echo "</select>";
		echo "<select name=\"Year\">";
		for($y=date;$y<=date+1;){  
		  $selected = "";
		  $longDate = date("Y", mktime(0,0,0,1,1,$y));
		  if ($Year==$y){ 
			$selected = "selected \n";
		  }
		  echo "<option value=\"$y\" $selected>$longDate</option> \n";
		}
		echo "</select>";
	?>
	<input type="submit" value="go">
</form>
</div>

</body>
</html>

 

Probably very simple but I can't work it out.

 

Appreciate any help.

 

Hi,

 

Where are you redirecting to cal.php?

Also, you're redirecting to a page called index.html before? HTML files cant contain php code (most of the time), so obviously you're not able to continue the session using session_start(); This could mean that you're session is being lost as soon as your code redirects to index.html

 

if ($row != null){
      $_SESSION['username'] = $row['first_name'];
      header("Location: index.html");
      exit();
}
else{
      header("Location: loginform1.php");
      exit();
}

if ($row != null){
      $_SESSION['username'] = $row['first_name'];
      header("Location: cal.php");
      exit();
}
else{
      header("Location: loginform1.php");
      exit();
}

 

Sorry My mistake, it works when the Header location is index.html, but when I change it to cal.php it just redirects to loginform1.php?

Well, for one thing you're referencing the first name column as $row['first_name'] when you had used mysql_fetch_row to get your resultset. WHen you use mysql_fetch_row, the result is returned as an array, starting from 0 to the number of columns in your db.

 

So, if you have a user_id column first, that will be $row[0]. If your first name column comes second, it will be $row[1], and so forth.

http://salmonsreach.org/index.html

 

login: [email protected]

password: password

 

waynewex if you go to the url, then login, I have a link to the cal page, but when activated u are just redirected to the login. ???

Try

 

logincheck1.php:
<?php
  
session_start();
require "dbconn2.php";

//Using the function mysql_real_escape_string() AFTER a connection
//has been established will clean incoming variables and prevent
//users from tampering with your SQL by inserting some of their own
$email_address = mysql_real_escape_string($_POST['email_address']);
$passwd = mysql_real_escape_string($_POST['passwd']);
$id = mysql_real_escape_string($_POST['id']);


if($id == 'client') {
   $sql = "SELECT * FROM client WHERE email_address='".$email_address
        ."' AND passwd='".$passwd."'";
   $result = mysql_query ($sql, $connection) or die ("Could not perform query $sql <br />".mysql_error());
   $row = mysql_fetch_assoc($result);
}
else if($id == 'consultant') {
   $sql = "SELECT * FROM consultant WHERE email_address='".$email_address
        ."' AND passwd='".$passwd."'";
   $result = mysql_query ($sql, $connection) or die ("Could not perform query $sql <br />".mysql_error());
   $row = mysql_fetch_assoc($result);
}
else if($id == 'organisation') {
    $sql = "SELECT * FROM organisation WHERE email_address='".$email_address
        ."' AND passwd='".$passwd."'";
   $result = mysql_query ($sql, $connection) or die ("Could not perform query $sql <br />".mysql_error());
   $row = mysql_fetch_assoc($result);
}
else{
   echo 'Incorrect type';
}

if ($row != null)

{
      $_SESSION['username'] = $row['first_name'];
      header("Location: index.html");
      exit();
}

else
{
	header("Location: loginform1.php");
	exit();
}
     
?>

<!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 http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>logincheck1.php</title>
</head>

<body>
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

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