Jump to content

[SOLVED] Session Help


stormx

Recommended Posts

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

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.