stormx Posted December 27, 2008 Share Posted December 27, 2008 Hey guys, I don't know if it's my server or my PHP script. I am having some session issues upon my login script. When I login the session ID is all fine for the page that initialises the login information but when I go to another page it requests me to login again. I'm guessing this is a session issue. Here is my script that sets the session: <?php $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); // Check the database... $login_sql = mysql_query("SELECT `id`, `password` FROM `users` WHERE `id` = '$username' AND `password` = '$password'"); $users = mysql_num_rows($login_sql); $users_array = mysql_fetch_array($login_sql); // Lets check if the user is found. if($users == 1) { $_SESSION['classofhsc_id'] = $users_array['id']; if(isset($_SESSION['classofhsc_id'])) { echo "Session Set ".$_SESSION['classofhsc_id']; } session_start(); ?> Logged In <?php } else { ?> Error In Username/Password <?php } ?> Here where the error takes place due to somehow no session: <?php $page = $_GET['page']; if($page) { if(file_exists($page.'.php')) { if($page == "index") { echo '<h1>Access Denied</h1>You cannot view this page directly.'; } else { if($page == "login_action") { include('login_action.php'); } else { if(isset($_SESSION['classofhsc_id'])) { include($page.'.php'); } else { include 'login_layout.php'; } } } } else { echo '<h1>404 Not Found</h1> </BR> <h4 class="special">Not Found</h4>'; } } else { include('login_layout.php'); } ?> As I said before, I think it may be a problem with sessions on my server so if you could give me any suggestions for my script and maybe also a tutorial to change my session temp directory. Thanks Link to comment https://forums.phpfreaks.com/topic/138534-solved-session-help/ Share on other sites More sharing options...
kenrbnsn Posted December 27, 2008 Share Posted December 27, 2008 You need to put the <?php session_start(); ?> at the start of your script before you use any $_SESSION variables. Ken Link to comment https://forums.phpfreaks.com/topic/138534-solved-session-help/#findComment-724334 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.