Sessions sometimes work.
Posted: Fri Dec 23, 2005 11:11 am
I'm making my own multi-user blog in PHP.
I had it all working on my local server (PHP5), using session_start(); and $_SESSION[] in all the pages.
I uploaded it to the SourceForge server for the website and it all went downhill.
Here's the login script:
I login with no errors, but when It redirects me to the main blog page, it still thinks I haven't logged on.
If I refresh the page a couple of times, it logs on.
Anyone know what might be happening?
Here is the code of the main page:
Thanks in advance!
apg88
I had it all working on my local server (PHP5), using session_start(); and $_SESSION[] in all the pages.
I uploaded it to the SourceForge server for the website and it all went downhill.
Here's the login script:
Code: Select all
<?php
include_once "functions.php";
$user_info = getUserInfo($_POST['username']);
// Check if the username really exisits.
if(!($user_info) || ($user_info['active'] == 0) ){
echo "Username does not exist.";
} else {
// Check the passwords
if($user_info['password'] == crypt($_POST['password'],strrev($_POST['password']))) {
// Now, let's start the session.
session_name("ajaxofficeblog");
session_start();
$_SESSION['uid'] = $user_info['uid'];
$_SESSION['username'] = $user_info['username'];
$_SESSION['gid'] = $user_info['gid'];
header("Location: ../blog.php");
} else {
echo "Enter the correct password.";
}
}
?>If I refresh the page a couple of times, it logs on.
Anyone know what might be happening?
Here is the code of the main page:
Code: Select all
session_name("ajaxofficeblog");
session_start();
if($_SESSION['username']){
echo"<h2>Blog</h2><p>
<a href=\"blog/postnew.php\">Post New</a><br />
<a href=\"blog/changeinfo.php\">Edit User Info</a>
</p>";
if($_SESSION['gid'] == 9 || $_SESSION['gid'] == 1){
echo"<h2>Admin</h2><p>
<a href=\"blog/adm1n.php\">Admin Panel</a>
</p>";
}
} else {
echo '
<h2>Login</h2>
<form action="blog/login.php" method="POST">
<p>
Username: <br />
<input type="text" class="forms" name="username"/><br />
Password: <br />
<input type="password" class="forms" name="password"/><br /><br />
<input type="submit" value="Login" class="forms" />
</p>
</form>
';
}apg88