0

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

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Stefano Mtangoo
0

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>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.