Hi all,
I have successfully installed my forum onto my 'localhost' system and have tried to integrate the login system to work on an external page of my site. The article on this was very good, and I have adapted the default scripts to suit my needs. However, although the form variables for username and password are being passed to the comparison script, no cookie is being set - so instead of returning to the page I logged in from and displaying a welcome message - the log in form is still there. Here is my code:
Log in page:
<?php if(!isset($_SESSION['auth'] ) or !isset($_SESSION['ID'])){ // If the user isn't logged in, show them the form...
echo 'Please enter your log in details below, or</p> <form action="my_auth.php" method="POST" name="login"> <table id="login_website" summary="Log in to the Karting Days web site."> <tr> <th scope="col" abbr="login" class="nobg">login</th>
<th scope="col" abbr="login" class="nobg"><input type="text" name="login" size="27" value="" /></th> </tr> <tr> <th scope="col" abbr="Password" class="nobg">Password</th>
<th scope="col" abbr="Password" class="nobg"><input type="password" name="password" size="27" value="" /></th> </tr> <tr> <td></td> <th scope="col" abbr="go" class="inputButton"><input type="submit" name="go" value="go" /></th>
</tr> </table> </form>'; }
else {echo 'You are logged in as '.$_SESSION['auth'].' (ID: '.$_SESSION['ID'].') <a href="my_auth.php?logout=1">Logout</a>';}
?>
Now the Code for My_auth.php:
<?php /* Comparison script */
$page=$_SERVER['HTTP_REFERER'];
if(isset($_POST['login']) and isset($_POST['password'])){
mysql_connect('localhost:8888', 'root', 'root') or die ('<b>Database/configuration error.</b>'); mysql_select_db('karting') or die ('<b>Database/configuration error (DB is missing).</b>');
if(isset($_POST['login'])) $name=htmlspecialchars(trim($_POST['login']),ENT_QUOTES); else $name=''; if(isset($_POST['password'] )) $pass=htmlspecialchars(trim($_POST['password']),ENT_QUOTES); else $user_pwd='';
if($res=mysql_query("select ID, name, pass from my_users where name='{$name}' and pass='{$pass}'") and mysql_num_rows($res)>0 and $row=mysql_fetch_row($res)){
session_start(); $_SESSION['auth']=$row[1]; $_SESSION['ID']=$row[0];
}
} elseif(isset($_GET['logout'])){ session_start(); unset($_SESSION['auth']); unset($_SESSION['ID']); } header("Location: $page");
?>
Can anybody help? Is it because i'm using XAMPP/Mac and local server - or am i missing something obvious?
Any other topics on how to get this integrated?
Many thanks in advance!
Paul. |