A
Anonymous
Guest
this code is to authenticate users who visit a site and to start a session. however the code generates errors. errors relating to php not being able to send the session variables because the header has already been sent. what would you advise to solve this problem?
thanks in advance for your help
Code:
<?php
// import variables to be read from form
import_request_variables("p", "s_");
// set variables to connect to database
$db_host = "localhost";
$db_user = "******";
$db_pass = "******";
$db_name = "jamison_id";
// connect to database
$connection = mysql_connect($db_host, $db_user, $db_pass) or die ("Unable to connect!");
mysql_select_db($db_name);
$query = "SELECT id_num from login WHERE user = '$s_user_id' AND passwd = '$s_passwd'";
$result = mysql_query($query, $connection) or die ("Error in query: '$query' ." . mysql_error());
// if row exists -> user/pass combination is correct
if (mysql_num_rows($result) == 1)
{
$valid = 1;
}
// else
// {
// print($s_user_id);
// print($s_passwd);
// }
// }
// $valid = authenticate($s_user_id, $s_passwd);
// print($valid);
if ($valid == 1)
{
// initiate a session
session_start();
// register some session variables
// session_register("SESSION");
// including the username
// session_register("SESSION_UNAME");
// $SESSION_UNAME = $f_user;
}
?>
thanks in advance for your help