Jump to content

Recommended Posts

Does anybody know why my cal.php does not work with the session, it just redirects to the loginform1.php.

 

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>

 

appreciate any help

Obviously, you're not properly logged in.

 

Just for the moment, copy and paste this data at the VERY TOP of your cal.php script.

<?php
session_start();
echo "<PRE>"; var_dump($_SESSION); echo "</PRE>";
exit();
?>

 

What output does it give?

Where are you setting the session?

Also, there's no need to echo stuff to the user, or exit() after you've redirected them to login.php. They won't even see it so there's not much point...

 

Unless of course the re-direct fails..

I'm setting the session in the logincheck1.php script

 

<?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.php");
      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>

 

 

if ($row != null)

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

 

You might change these lines of code to this (just for testing purposes):

if ($row != null)

{
      $_SESSION['username'] = $row['first_name'];
echo "<PRE>" . var_dump($row) . "</PRE>";
/*      header("Location: index.php");
      exit();*/
}

 

Post the output of that.

array(10) { [0]=>  string(1) "7" [1]=>  string(1) "1" [2]=>  string(7) "Malcolm" [3]=>  string(1) "X" [4]=>  string(0) "" [5]=>  string(0) "" [6]=>  string(19) "[email protected]" [7]=>  string(0) "" [8]=>  string(10) "0000-00-00" [9]=>  string( "password" } 

Here's the answer:

$row = mysql_fetch_row($result);

 

If you change that to mysql_fetch_array, you should get your desired results.

 

You can also change this line:

      $_SESSION['username'] = $row['first_name'];

to this:

      $_SESSION['username'] = $row[2]; // assuming Malcolm is in the first_name column per your example

 

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.