To allow users to login to my site I currently use:
<?
// TouringNet - Login
include("_config.php");
$md5pw = md5($_POST['password']);
mysql_connect($db_host, $db_user, $db_pass) or die ('ERROR: cannot connect to database');
mysql_select_db($db_name) or die ('ERROR: cannot select the database "'.$db_name.'"');
$query = "SELECT * FROM users WHERE username='".$_POST['username']."' AND password='$md5pw'" or die( "Unable to find user");
$result = mysql_query($query) or die(mysql_error().'<br> SQL:'.$query);
$num = mysql_num_rows($result);
if ($num==0) {
echo("Either your username and/or password are incorrect! Please try again.");
} else {
$id=mysql_result($result,"id");
setcookie("TouringNetName", "".$_POST['username']."", time()+36000);
setcookie("TouringID", "$id", time()+36000);
echo("<meta http-equiv=\"refresh\" content=\"0;URL=./?q=\">");
}
?>
Would it be better to use the "setcookie" or some sort of SESSION?