e1seix Posted March 20, 2010 Share Posted March 20, 2010 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 More sharing options...
Ruzzas Posted March 20, 2010 Share Posted March 20, 2010 i think maybe $_SESSION['expire'] you will need to get the time and plus it to the amount of time you want that user logged in. if ($_SESSION['expire'] < time()) { echo "You need to relog"; } Link to comment https://forums.phpfreaks.com/topic/195891-foray-into-sessions/#findComment-1028939 Share on other sites More sharing options...
Ruzzas Posted March 20, 2010 Share Posted March 20, 2010 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 More sharing options...
trq Posted March 20, 2010 Share Posted March 20, 2010 [ot] This.... $_SESSION["'.$username.'"] should be.... $_SESSION[$username] [/ot] Link to comment https://forums.phpfreaks.com/topic/195891-foray-into-sessions/#findComment-1028958 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.