Page 1 of 1

Session: maintainstate

Posted: Tue Jun 27, 2006 5:20 pm
by trock74
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Need help, my session keeps ending everytime i click the next button. It takes me back to the login page, any suggestion on how to fix the problem. I have no clue what i'm doing wrong.

Code: Select all

<html>
<title>Test Calendar</title>
<head></head>
<body>
<?php
if (!isset($_SESSION['uid']))
include("session.php");
include("login.php");
$tester = $_REQUEST["tester"]; // goes to previous or next month
$nmon = $_REQUEST["nmon"]; // pull number of days of the month from sever
$nyear = $_REQUEST["nyear"]; // pull current year
$this = $_REQUEST["this"]; // test bigger than 12 or smailler than 1 to go to next or previous year

// this condition gives the next month
if ($tester == 1) {
  $nmon = $nmon + 1;
} elseif ($tester == 2) { // this gives the previous month
  $nmon = $nmon - 1;
} else {
// set numberic representation of a month
$nmon = date("n");
}
// change current month to jan and year to next year if the last month is dec
if ($nmon > 12) {
  $nmon = 1;
  $nyear = $nyear + 1;
  $this = 1;
}  elseif ($nmon < 1) { // change current month to dec and year to previous year if the last month is jan counting backwards
  $nmon = 12;
  $nyear = $nyear - 1;
  $this = 1;
} else {
// set full numeric representation of year, 4 digits
  if ($this != 1) // if we are not going to the next or the previous year, get the current year
     $nyear = date("Y");
}
// set number of days in the given month
$ndays = date("t", mktime(0,0,0,$nmon,1,$nyear));
// set Textual representation of a month
$tmon = date("F", mktime(0,0,0,$nmon,1,$nyear));
?>
<table>
<tr>
   <td><?php  echo "$username"; ?></td>
</tr>
<tr>
   <td>
      <table>
      <tr>
         <!-- link to previous month -->
         <td colspan="3" align=left><?php echo "<a href=\"blahblah/?tester=2&nmon=$nmon&nyear=$nyear&this=$this\"><<</a>\n"; ?></td>
         <!-- link to current month -->
         <td colspan="1" align=center><?php echo "<a href=\"blahblah/\">==</a>\n"; ?></td>
         <!-- link to next month -->
         <td colspan="3" align=right><?php echo "<a href=\"blahblah/?tester=1&nmon=$nmon&nyear=$nyear&this=$this\">>></a>\n"; ?></td>
      </tr>
      <tr>
         <td><?php echo "$tmon $nyear"; ?></td>
      </tr>
      <tr>
         <th>Sun</th>
         <th>Mon</th>
         <th>Tue</th>
         <th>Wed</th>
         <th>Thu</th>
         <th>Fri</th>
         <th>Sat</th>
      </tr>
      <?php
      // code to display dates here 
      ?>
            </table>
   </td>
</tr>
</table>
</body>
</html>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue Jun 27, 2006 5:29 pm
by RobertGonzalez
you need to include this line at the beginning of every session'ed page...

Code: Select all

<?php
session_start();
?>
This line needs to be called before any output sent to the browser.

EDIT | Fixed a stupid incorrect spelling that my IDE would have caught but my stupid eyes did not. Sorry.

Posted: Tue Jun 27, 2006 6:05 pm
by feyd
psst.. session_start().. typo. ;)

trock74, please don't try to highlight the code yourself.

Posted: Wed Jun 28, 2006 12:04 am
by RobertGonzalez
Fixed. And sorry. I was typing fast and didn't double-check.