Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Authentication using username and password...

Status
Not open for further replies.

meenakshidhar

Programmer
Oct 19, 2001
77
MY
hello friends...
i want one authentication form..when user put his username and password, it will check his username and password from mysql database...if the information is correct, the next page will be displayed....
here's my coding...

<?php

if ((!$username ) and (!$password)) {

header(&quot;location: exit;
}

$db_name=&quot;meenakshi&quot;;

$table_name=&quot;authentication&quot;;
$connection=@mysql_connect( &quot;localhost&quot;, &quot;vivek&quot;, &quot;tarun150&quot; )
or die ( &quot;Unable to connect to server.&quot; );

$db=@mysql_select_db( $db_name,$connection )
or die ( &quot;Unable to select database.&quot; );



$sql = &quot;SELECT * FROM $table_name WHERE
username = \&quot;$username\&quot; AND
password = password(\&quot;$password\&quot;)&quot;;




$result =@mysql_query($sql)
or die(&quot;Unable to execute query.&quot;);



$num = mysql_numrows( $result );

if ( $num != 0 ) {

$msg=&quot;<p>congrats</p>&quot;;
}
else{
header(&quot;location: exit;
}
?>

Can anybody plss help me...
thanks in advance...
 
Looks fine to me, but you will need to replace 'localhost' with the full url if you want people to use this from anywhere other than your server. Also if I assume that your 'one.html' is the place to go to on successfully logging in then you need to rearrange your last few lines:
Code:
if ( $num != 0 ) {
  header(&quot;location:[URL unfurl="true"]http://yourdomain/meenakshi/one.html&quot;;);[/URL]
} else {
  header(&quot;location:[URL unfurl="true"]http://yourdomain/meenakshi/login1.html&quot;;);[/URL]
}
exit;
My only other concern is what method you are using to prevent someone just typing in the url of one.html, bypassing your authentication script entirely. Have you considered this?

-Rob
 
hi meena..
the way i have to stop people from going to a page without being logged in is, at the top of each page, have
<? php
session_start();
if(!$_SESSION['logged']){
header(&quot;location:}

and in your user authentication script have

if ( $num != 0 ) {
$_SESSION['logged']=true;
header(&quot;location:} else {
header(&quot;location:}


hope this helps.. i am a php newbie tho so there is probably a better way to do that.

take it easy
//jason
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top