[SOLVED] php Login page

This is a discussion on "[SOLVED] php Login page" within the PHP Forum section. This forum, and the thread "[SOLVED] php Login page are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Oct 16th, 2007, 13:54
Up'n'Coming Member
Join Date: Apr 2007
Location: Canada
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] php Login page

Hi Fellows!
I have a login page that check the database userid and password filed before log in. If match it allow them to log in and redirect that to a welcome page. It is working fine. Now what I want is ....it should check the table 'active' filed to verify whether user's activated or not their account. If it activated the field is empty. so if it was not activated they will get an messaga saying account is not activated. If the account is activated then it will check the userid and password filed. Iknow it sould very easy but I am kind of stuck. Here is my working login page code..........

PHP: Select all

include "include/session.php";
include "include/z_db.php";
//////////////////////////////
 
?>
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title>(Type a title for your page here)</title>
<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
</head>
<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
<?
$userid
=mysql_real_escape_string($userid);
$password=md5(mysql_real_escape_string($password));
if(
$rec=mysql_fetch_array(mysql_query("SELECT * FROM tbl_login WHERE userid='$userid' AND password = '$password'"))){
 if((
$rec['userid']==$userid)&&($rec['password']==$password)){
  include 
"include/newsession.php";
            echo 
"<p class=data> <center>Successfully,Logged in<br><br><a href='logout.php'> Log OUT </a><br><br><a href=welcome.php>Click here if your browser is not redirecting automatically or you don't want to wait.</a><br></center>";
     print 
"<script>";
       print 
" self.location='welcome.php';"// Comment this line if you don't want to redirect
          
print "</script>";
    } 
  } 
 else {
  
session_unset();
echo 
"<font face='Verdana' size='2' color=red>Wrong Login. Use your correct  Userid and Password and Try <br><center><input type='button' value='Retry' onClick='history.go(-1)'></center>";
 
 }
?>
</body>
</html>

Last edited by karinne; Oct 16th, 2007 at 14:05. Reason: Changed the [ code ] to [ php ] for readability
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Oct 16th, 2007, 14:25
Highly Reputable Member
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: php Login page

Just change your SQL query:
Code: Select all
SELECT * FROM tbl_login WHERE userid='$userid' AND password = '$password' AND active != ''
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Oct 16th, 2007, 14:47
Up'n'Coming Member
Join Date: Apr 2007
Location: Canada
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Re: php Login page

Hi c010depunkk,
Could u pls show me the code for the query, I am kind of novice ther?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Oct 16th, 2007, 14:52
Elite Veteran
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: php Login page

see the bold

Code: Select all
$userid=mysql_real_escape_string($userid);
$password=md5(mysql_real_escape_string($password));
if($rec=mysql_fetch_array(mysql_query("SELECT * FROM tbl_login WHERE userid='$userid' AND password = '$password'"))){
 if(($rec['userid']==$userid)&&($rec['password']==$password)){
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Oct 16th, 2007, 15:01
Up'n'Coming Member
Join Date: Apr 2007
Location: Canada
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Re: php Login page

Hi C010,
Thanks for our quick reponse but you are not giving me the corrected code that it should be you just showed me where to change but I need to know the changed code to incorporate my objective. Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Oct 16th, 2007, 15:05
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: php Login page

He did change it Dhossai.
He changed:
Code: Select all
SELECT * FROM tbl_login WHERE userid='$userid' AND password = '$password'

to:
Code: Select all
SELECT * FROM tbl_login WHERE userid='$userid' AND password = '$password' AND active != ''
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Oct 16th, 2007, 15:08
Up'n'Coming Member
Join Date: Apr 2007
Location: Canada
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Re: php Login page

Hi alexgeek,
where it got change? I don't see where it check the 'active' filed from the table to verify whether it was activated or not? Pls explain a bit.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Oct 16th, 2007, 15:41
Elite Veteran
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: php Login page

Oh dear!

See the green part in alexgeek's code
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old Oct 16th, 2007, 15:49
Up'n'Coming Member
Join Date: Apr 2007
Location: Canada
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Re: php Login page

Hi Karinne,

Could u pls check my original post and check the code, I do not see any changes it is exactly same as I had. Pls let me know.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old Oct 16th, 2007, 15:52
Elite Veteran
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: php Login page

In your code you have

SELECT * FROM tbl_login WHERE userid='$userid' AND password = '$password'

and c010depunkk added AND active != '' at the end

Now ... if you don't understand this ... I don't know how else to explain the simplicity of this thread.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old Oct 16th, 2007, 16:06
Up'n'Coming Member
Join Date: Apr 2007
Location: Canada
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Re: php Login page

Hi Karrine,
Thanks for this. Now I can see the text but I still can not see any text on Alexe's post anywhere. I don't know it might be my browser is not allowing me to see this or what? It is interesting!!!!! Anyway, How to echo the notice if account was not activated. In my database it it was activated the 'active' field would be empty. Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old Oct 16th, 2007, 16:07
Elite Veteran
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: php Login page

What platform and browser are you in?

Quote:
In my database it it was activated the 'active' field would be empty.
and that's what the != ' ' is for
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #13  
Old Oct 16th, 2007, 16:35
Highly Reputable Member
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: php Login page

OK, back for round two. Here's your code, modified. This should work:
PHP: Select all

include "include/session.php";
include "include/z_db.php";
//////////////////////////////

?>
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title>(Type a title for your page here)</title>
<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
</head>
<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
<?
$userid
=mysql_real_escape_string($userid);
$password=md5(mysql_real_escape_string($password));
if(
$rec=mysql_fetch_object(mysql_query("SELECT * FROM tbl_login WHERE userid='$userid'"))){
    if(
$rec->active!='') {
        if(
$password==$rec->password) {
            include 
"include/newsession.php";
            echo 
"<p class=data> <center>Successfully,Logged in<br><br><a href='logout.php'> Log OUT </a><br><br><a href=welcome.php>Click here if your browser is not redirecting automatically or you don't want to wait.</a><br></center>";
            print 
"<script>";
            print 
" self.location='welcome.php';"// Comment this line if you don't want to redirect
            
print "</script>";
        } else {
            
// password wrong
        
}
    } else {
        
// account not activated
    
}
}else {
    
session_unset();
    echo 
"<font face='Verdana' size='2' color=red>Wrong Login. Use your correct  Userid and Password and Try <br><center><input type='button' value='Retry' onClick='history.go(-1)'></center>";
}
?>
</body>
</html>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #14  
Old Oct 16th, 2007, 16:48
Up'n'Coming Member
Join Date: Apr 2007
Location: Canada
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Re: php Login page

Hi karrine,
In the table field active is populated with number, with this new code I still can log in. User should only be allowed to if the active filed is empty. If the field active is populated I should not be allowed to log in and should get the error messase account is not activated. I am using MySql database.
I am using this....

if($rec=mysql_fetch_array(mysql_query("SELECT * FROM tbl_login WHERE userid='$userid' AND password = '$password' AND active !=' '"))){
if((
$rec['userid']==$userid)&&($rec['password']==$password)){
include
"include/newsession.php";
if($rec=mysql_fetch_array(mysql_query("SELECT * FROM tbl_login WHERE userid='$userid' AND password = '$password'"))){
if((
$rec['userid']==$userid)&&($rec['password']==$password)){
include
"include/newsession.php";
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #15  
Old Oct 16th, 2007, 17:20
Up'n'Coming Member
Join Date: Apr 2007
Location: Canada
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Re: php Login page

Hi C010,

Thanks for the code. I tried but user can still log in if the active filed still populated means user did not activate the account. My active field is a m5f enrypted filed which is hidden and generate automatically when user register to the site using " $a = md5(uniqid(rand(), true)); " this. Hope this will help to solve it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #16  
Old Oct 16th, 2007, 18:39
Highly Reputable Member
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: php Login page

I've provided two methods so far.... Both could work, but you are also going to have to try and understand the code or all the help we give you is useless!

Or try wording your question a bit more coherently and provide a bit more info about what you are exactly trying to do....
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #17  
Old Oct 16th, 2007, 20:05
Up'n'Coming Member
Join Date: Apr 2007
Location: Canada
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Re: php Login page

Hi c010,
Well I don't know how much i have to explain to get it out. Ok, here I go again, in my 'tbl_login' table i have a field called "ctive". If the filed is empty that means user have activated the account. How user activate it? When user signup, active field in tbl_login got populated with random number whis is md5 encrypted using ----$a = md5(uniqid(rand(), true)); --- this methond. user get an email with activation link. When user click that link account is activated and active field in tbl_login become empty. So I want to make sure that user can not log on to unless they activate the account and if they try they will get an error message saying account is not activated. And if account is activated then it will check the userid and password. I hope I was able to explain so that you understand. Thanks for your time.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #18  
Old Oct 16th, 2007, 21:05