You don't even need to set a cookie with PHP4. Use sessions instead to login the user. Something like this:
<?php
$link;
connectToDB();
function connectToDB()
{
global $link;
$link = mysql_connect( "localhost", "jhyers", "careinx" );
if ( ! $link )
die ("Couldn't connect to MySQL" );
mysql_select_db ( "careinternet", $link )
or die ( "Couldn't open $db: ".mysql_error() );
}
function getRow( $table, $fnm, $fval )
{
global $link;
$result = mysql_query( "SELECT * FROM $table WHERE $fnm='$fval'", $link );
if ( ! $result)
die ( "getRow fatal error: ".mysql_error() );
return mysql_fetch_array( $result );
}
function newUser ( $username, $pass )
{
global $link;
$result = mysql_query( "INSERT INTO login (username, password)
VALUES('$username', '$pass')", $link);
return mysql_insert_id( $link );
}
function checkPass( $username, $password )
{
global $link;
$result = mysql_query( "SELECT id, username, password FROM login
WHERE username='$username' and password='$password'",
$link );
if ( ! $result )
die ("checkPass fatal error: ".mysql_error() );
if ( mysql_num_rows( $result ) )
return mysql_fetch_array( $result );
return false;
}
session_start();
session_register( "session" );
function cleanMemberSession ( $id, $username, $pass )
{
global $session;
$session[id] = $id;
$session[username] = $username;
$session[password] = $pass;
$session[logged_in] = true;
}
function checkUser( )
{
global $session, $logged_in;
$session[logged_in] = false;
$club_row = getRow ( "login", "id", $session[id] );
if ( ! $club_row ||
$club_row[username] != $session[username] ||
$club_row[password] != $session[password] )
{
header( "location: http://www.careinternet.net/login.php" );
exit;
}
$session[logged_in] = true;
return $club_row;
}
$club_row = checkUser();
?>
You could use some code like this in an include file and then write your login and register page.
Some people might have cookies disabled with all of the privacy stuff going on. And if all you need is a user login and password sessions will work fine and you don't even need cookies. PHP4 is great in that respect.