Jump to content

Foray into sessions


e1seix

Recommended Posts

Hi-ho everyone.

 

Making my first steps in the world of sessions. It's only a one page section of my site, so i can keep all the coding on the one page without having to run an include file to carry on the session... The sesion itself is working... i'm not sure how to devise a log out button or a timeout function though without deviating away or creating a seperate page. can anyone advise?

 

$query = 'SELECT * FROM admin';
$results = mysql_query( $query ) or die(mysql_error());
while($row = mysql_fetch_array( $results )) {

  $username = $row["username"];
  $password = $row["password"]; }

    if ( $_POST["username"] == $username && $_POST["password"] == $password ) {

      include("rows/header.php");
      include("rows/main.php");
      include("rows/footer.php");
      include("closedb.php"); }

    elseif ( !isset( $_SESSION["'.$username.'"] ) ) {

      include("rows/header.php");
      include("rows/main.php");
      include("rows/footer.php");
      include("closedb.php"); }

    else { ?>

    <form action="/admin/" method="post" name="login">
      <input type="text" name="username" />
      <input type="password" name="password" />
      <input type="submit" value="Login" />
    </form><? } ?>

 

Much obliged.

Link to comment
https://forums.phpfreaks.com/topic/195891-foray-into-sessions/
Share on other sites

Try this:

 

<?php
$query = 'SELECT * FROM admin';
$results = mysql_query( $query ) or die(mysql_error());
while($row = mysql_fetch_array( $results )) {

  $username = $row["username"];
  $password = $row["password"]; }
    if($_POST["username"] == $username && $_POST["password"] == $password ) {

      include("rows/header.php");
      include("rows/main.php");
      include("rows/footer.php");
      include("closedb.php");
      
      session_start();
      $_SESSION['expire'] = "date('His', strtotime('+2 hours'))";
    }
    elseif($_SESSION['expire'] < date('His')) && (!isset( $_SESSION["'.$username.'"])){

      include("rows/header.php");
      include("rows/main.php");
      include("rows/footer.php");
      include("closedb.php");
    }
    else { ?>

    <form action="/admin/" method="post" name="login">
      <input type="text" name="username" />
      <input type="password" name="password" />
      <input type="submit" value="Login" />
    </form><? } ?>

Link to comment
https://forums.phpfreaks.com/topic/195891-foray-into-sessions/#findComment-1028956
Share on other sites

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.