Memberscript issues
Posted: Sat Mar 31, 2007 7:53 pm
I'm having problems with a membership script I wrote.
It seems like the sessions aren't working properly, I don't know if it's something to do with using a different version of php or what, because I used this same code on another server and it worked fine.
on the index.php
then on the rest of the pages i have the following code to check to make sure they are still loged in
this is the info to get their theme for the site (getTheme just looks up their theme in the db and returns 'default.css' etc...)
The Errors
It seems like the sessions aren't working properly, I don't know if it's something to do with using a different version of php or what, because I used this same code on another server and it worked fine.
on the index.php
Code: Select all
if (!session_is_registered('id') && !isset($_COOKIE['fcms'])) {
if ((!$user) || (!$pass)) { displayHeader(); displayLogin(); exit(); }
$pass = md5($pass);
$result = mysql_query("SELECT * FROM fcms_users WHERE username='$user' AND password='$pass'");
$login_check = mysql_num_rows($result);
if($login_check > 0) {
while($row = mysql_fetch_array($result)) {
foreach( $row AS $key => $val ) { $$key = stripslashes( $val ); }
if($rem >= 1) { setcookie('fcms', $id, time() + (30*(24*3600)), '/'); } else { session_register('id'); $_SESSION['id'] = $id; }
mysql_query("UPDATE fcms_users SET activity=NOW() WHERE id=$id");
echo "<h3>Login Successfull.<h3><a href=\"portal.php\">Continue</a>.";
echo "<meta http-equiv='refresh' content='0;URL=portal.php'>";
}
} else {
displayHeader();
echo '<h3>Invalid Login</h3><p>You could not be logged in. Please check that your username and password are correct.</p>';
displayLogin();
}
} else {
$login_id = $_SESSION['id'] ? $_SESSION['id'] : $_COOKIE['fcms'];
mysql_query("UPDATE fcms_users SET activity=NOW() WHERE id=$login_id");
echo "<h3>Already Logged In.</h3><a href=\"portal.php\">Continue</a>.";
echo "<meta http-equiv='refresh' content='0;URL=portal.php'>";
}then on the rest of the pages i have the following code to check to make sure they are still loged in
Code: Select all
if (!session_is_registered('id') && !isset($_COOKIE['fcms'])) {
//redirect them to login
} else {
$login_id = $_SESSION['id'] ? $_SESSION['id'] : $_COOKIE['fcms'];
}this is the info to get their theme for the site
Code: Select all
<link rel="stylesheet" type="text/css" href="<?php getTheme($_SESSION['id'] ? $_SESSION['id'] : $_COOKIE['fcms']); ?>" />The Errors
[/quote]PHP Notice: A session had already been started - ignoring session_start() in /httpdocs/home.php on line 2
I was under the impression that you had to have session_start(); at the beginning of every php page?
PHP Notice: Undefined index: id in /httpdocs/home.php on line 11