Jump to content

[SOLVED] check to see if user is activated


yobo

Recommended Posts

hey all

 

i am very close at getting my login script complete however i having problems in the login section becuase it lets the user login even if they have not activated there account and i wanted o know how would i do this so that only activated users can login

 

my table has a colunm called activated with yes or no, no being not activated and yes being activated

 

my login code

 

<?php

 

include("config.php");

 

// connect to the mysql server

$link = mysql_connect($server, $db_user, $db_pass)

or die ("Could not connect to mysql because ".mysql_error());

 

// select the database

mysql_select_db($database)

or die ("Could not select database because ".mysql_error());

 

$match = "SELECT userid FROM users WHERE username = '".$_POST['username']."'

and password = '".$_POST['password']."';";

 

 

$qry = mysql_query($match)

or die ("Could not match data because ".mysql_error());

$num_rows = mysql_num_rows($qry);

 

if ($num_rows <= 0) {

echo "Sorry, there is no username $username with the specified password.<br>";

echo "<a href=login.php>Try again</a>";

exit;

} else {

 

setcookie("loggedin", "TRUE", time()+(3600 * 24));

setcookie("username", "$username");

echo "You are now logged in!<br>";

echo "Continue to the <a href=members.php>members</a> section.";

}

?>

Link to comment
Share on other sites

<?php

include("config.php"); 

// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());

// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());

$match = "SELECT userid FROM users WHERE username = '".$_POST['username']."'
and password = '".$_POST['password']."';"; 


$qry = mysql_query($match)
or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry); 

if ($num_rows <= 0) { 
echo "Sorry, there is no username $username with the specified password.
";
echo "<a href=login.php>Try again[/url]";
exit;
} else {

$row=mysql_fetch_assoc($qry);
$status=$row['status'];

if ($status=='activate'){

setcookie("loggedin", "TRUE", time()+(3600 * 24));
setcookie("username", "$username");
echo "You are now logged in!
"; 
echo "Continue to the <a href=members.php>members[/url] section.";
}else{

echo "Your account is inactive. Please activate your account before proceed";
}
?>

try this

Link to comment
Share on other sites

ok i have done what you suggested and i have got further than when i tried but it says that your account is inactive even when it is active

 

<?php

 

include("config.php");

 

// connect to the mysql server

$link = mysql_connect($server, $db_user, $db_pass)

or die ("Could not connect to mysql because ".mysql_error());

 

// select the database

mysql_select_db($database)

or die ("Could not select database because ".mysql_error());

 

$match = "SELECT userid FROM users WHERE username = '".$_POST['username']."'

and password = '".$_POST['password']."';";

 

 

$qry = mysql_query($match)

or die ("Could not match data because ".mysql_error());

$num_rows = mysql_num_rows($qry);

 

if ($num_rows <= 0) {

echo "Sorry, there is no username $username with the specified password.<br>";

echo "<a href=login.php>Try again</a>";

exit;

} else {

 

$row=mysql_fetch_assoc($qry);

$status=$row['activated'];

 

if ($status=='yes'){

 

setcookie("loggedin", "TRUE", time()+(3600 * 24));

setcookie("username", "$username");

echo "You are now logged in!";

echo "Continue to the <a href=members.php>members[/url] section.";

}else{

echo "Your account is inactive. Please activate your account before proceed";

}

}

?>

Link to comment
Share on other sites

<?php

include("config.php"); 

// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());

// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());

$match = "SELECT userid FROM users WHERE username = '".$_POST['username']."'
and password = '".$_POST['password']."';"; 


$qry = mysql_query($match)
or die ("Could not match data because ".mysql_error());
//$num_rows = mysql_num_rows($qry); 

if (!$qry) { 
echo "Sorry, there is no username $username with the specified password.
";
echo "<a href=login.php>Try again[/url]";
exit;
} else {

$row=mysql_fetch_assoc($qry);
$status=$row['status'];

if ($status=='activate'){

setcookie("loggedin", "TRUE", time()+(3600 * 24));
setcookie("username", "$username");
echo "You are now logged in!
"; 
echo "Continue to the <a href=members.php>members[/url] section.";
}
else{

echo "Your account is inactive. Please activate your account before proceed";
}
}
?>



Link to comment
Share on other sites

<?php

include("config.php"); 

// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());

// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());

$match = "SELECT userid FROM users WHERE username = '".$_POST['username']."'
and password = '".$_POST['password']."';"; 


$qry = mysql_query($match)
or die ("Could not match data because ".mysql_error());
//$num_rows = mysql_num_rows($qry); 

if (!$qry) { 
echo "Sorry, there is no username $username with the specified password.
";
echo "<a href=login.php>Try again[/url]";
exit;
} 

if (mysql_num_rows($qry)>1){
$row=mysql_fetch_assoc($qry);
$status=$row['status'];

if ($status=='activate'){

setcookie("loggedin", "TRUE", time()+(3600 * 24));
setcookie("username", "$username");
echo "You are now logged in!
"; 
echo "Continue to the <a href=members.php>members[/url] section.";
}
else{

echo "Your account is inactive. Please activate your account before proceed";
}
}
?>




 

try this..haha

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.