Jump to content

help me on user authentication


optiplex

Recommended Posts

dear friends.. the username and password is correct but the sistem display Wrong Username or Password.

 

this is the checking coding..

<?php
ob_start();
$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password="root"; // Mysql password 
$db_name="account"; // Database name 
$tbl_name="members"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// Define $t_nick and $password 
$t_nick=$_POST['t_nick']; 
$t_password=$_POST['t_password'];

// To protect MySQL injection (more detail about MySQL injection)
$t_nick = stripslashes($t_nick);
$t_password = stripslashes($t_password);
$t_nick = mysql_real_escape_string($t_nick);
$t_password = mysql_real_escape_string($t_password);

$sql="SELECT * FROM $tbl_name WHERE t_nick='$t_nick' and t_password='$t_password'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $t_nick and $password, table row must be 1 row

if($count==1){
// Register $t_nick, $password and redirect to file "login_success.php"
session_register("t_nick");
session_register("t_password"); 
header("location:list_details.php");
}
else {
echo "Wrong Username or Password";
}

ob_end_flush();
?>

 

and ive put this syntax at the top of list_details.php

session_start();
if(!session_is_registered(t_nick)){
header("location:login.php");
}

 

tq

Link to comment
https://forums.phpfreaks.com/topic/167017-help-me-on-user-authentication/
Share on other sites

now, i can access the list_details.php but this error was came out..

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at Z:\www\algebra\user\list_details.php:2) in Z:\www\algebra\user\list_details.php on line 3

 

tq

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.