Hi

I am looking for a script to register new users using MySql and a script to log them in and assign cookies to remember them. I have found a few scripts but nothing completely suitable as I want it to check that there is no username already in table, to send email verification link, and then a login script that checks they aren't already logged and assigns them a cookie.

So far I have a registration script that works the way I want but am struggling to combine it with a login script. If anyone knows of any that are free that would be amazing, I am willing to pay but not too much as well if anyone has anything suitable?

Thanks

try:

<?php
session_start();
$redirectTo='http://yoursite.com/page.php';
$DEBUG=true;

$SELF=basename(__FILE__);
$err='';
$match=0;

if(isset($_POST['username']) && !empty($_POST['username']) && isset($_POST['password']) && !empty($_POST['password']))
{  
	$link = mysql_connect('localhost', 'username', 'password') or die('Could not connect: ' . mysql_error()); 

	mysql_select_db('database') or die(mysql_error()); 

    $username = mysql_real_escape_string($_POST['username']);  
    $password = mysql_real_escape_string($_POST['password']);  

	$sql="SELECT `active` FROM `users` WHERE `username`='".$username."' AND `password`='".$password."'";
    $search = mysql_query($sql) or die(mysql_error());  
    $match  = mysql_num_rows($search);  

	if($DEBUG)
	{
		$msg.='<br />Executed: '.htmlspecialchars($sql,ENT_QUOTES);
		$msg.='<br />Total Matches: '.$match;
	}
}  

if(1==$match)
{
    $msg='<p>Login Complete! Thanks</p>';  
	$row=mysql_fetch_assoc($search);
    $_SESSION['username']=$_POST['username'];
    $_SESSION['active']=$row['active'];
	if(!empty($redirectTo))
	{
		header('Location: '.$redirectTo);
		exit;
	}
	else
	{
		$msg='<p>Congratulations, you managed to login successfully.  Now you can to go your <a href="account.php">account</a>.</p>';
	}
}
else
{ 
	$msg='<p>Login Failed! Please make sure that you enter the correct details and that you have activated your account.</p>';  
}  
?>          
<html>
<body>
<?php
if( !empty($msg) )
{
	echo $msg;
}

if(0==$match)
{
?>
        
        <h3>Login Form</h3>  
        <p>Please enter your name and password to login</p>  

        <!-- start sign up form -->  
        <form action="<?php echo $SELF; ?>" method="post">  
            <label for="name">Name:</label>  
            <input type="text" name="username" value="" />  
            <label for="password">Password:</label>  
            <input type="password" name="password" value="" />  
  
            <input type="submit" class="submit_button" value="Login" />  
        </form>  
<?php
}
?>
</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.