•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,528 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,752 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 872 | Replies: 3
![]() |
•
•
Join Date: Jul 2006
Posts: 66
Reputation:
Rep Power: 3
Solved Threads: 1
Hey friends I've a doubt regarding my password authentication code given below
If we use session _start function one need not use the cookies as $_SESSION['user'] = $username;
$_SESSION['password'] = $password;
functions do the same job that cookies would have done so my cookies code is just a clutter??
Here's my code
<?PHP
session_start();
?>
<?php
include "connect.php";
include 'var.php';
print "<link rel='stylesheet' href='http://127.0.0.1/styles/styles.css' type='text/css'>";
if (isset($_POST['submit'])) // name of submit button
{
$username = $_POST['username'];
$password = $_POST['password'];
$password = md5($hash . md5($password));
$query = "SELECT* from moderators where username='$username' and password='$password'";
$usercheck1 = mysql_query($query) or die(mysql_error());
$usercheck2 = mysql_num_rows($usercheck1);
if ($usercheck2)
{
$_SESSION['user'] = $username;
$_SESSION['password'] = $password;
if ($_POST['remember'])
{
$memberid = $result2[username];
$passkey = $result2[password];
$cookie1 = "[0]";
$cookie2 = "[1]";
$cookie3 = "$cookiename$cookie1";
$cookie4 = "$cookiename$cookie2";
setcookie("$cookie3", "$memberid", time() + 7776000);
setcookie("$cookie4", "$passkey", time() + 7776000);
}
print "<center>";
print "<table class='tborder' cellpadding='6' cellspacing='1' border='0'>";
print "<tr><td class='panelsurround' align='center'><center>Logged In</center></td></tr></table></center>";
print "<META HTTP-EQUIV = 'Refresh' Content = '2; URL =http://127.0.0.1/register.php'></center>";
}
else
{
print "<center>";
print "<table class='tborder' cellpadding='6' cellspacing='1' border='0'>";
print "<tr><td class='panelsurround' align='center'><center>Invalid username or password</center></td></tr></table></center>";
//print "<META HTTP-EQUIV = 'Refresh' Content = '2; URL =http://127.0.0.1/login.php'></center>";
}
}
?>
If we use session _start function one need not use the cookies as $_SESSION['user'] = $username;
$_SESSION['password'] = $password;
functions do the same job that cookies would have done so my cookies code is just a clutter??
Here's my code
<?PHP
session_start();
?>
<?php
include "connect.php";
include 'var.php';
print "<link rel='stylesheet' href='http://127.0.0.1/styles/styles.css' type='text/css'>";
if (isset($_POST['submit'])) // name of submit button
{
$username = $_POST['username'];
$password = $_POST['password'];
$password = md5($hash . md5($password));
$query = "SELECT* from moderators where username='$username' and password='$password'";
$usercheck1 = mysql_query($query) or die(mysql_error());
$usercheck2 = mysql_num_rows($usercheck1);
if ($usercheck2)
{
$_SESSION['user'] = $username;
$_SESSION['password'] = $password;
if ($_POST['remember'])
{
$memberid = $result2[username];
$passkey = $result2[password];
$cookie1 = "[0]";
$cookie2 = "[1]";
$cookie3 = "$cookiename$cookie1";
$cookie4 = "$cookiename$cookie2";
setcookie("$cookie3", "$memberid", time() + 7776000);
setcookie("$cookie4", "$passkey", time() + 7776000);
}
print "<center>";
print "<table class='tborder' cellpadding='6' cellspacing='1' border='0'>";
print "<tr><td class='panelsurround' align='center'><center>Logged In</center></td></tr></table></center>";
print "<META HTTP-EQUIV = 'Refresh' Content = '2; URL =http://127.0.0.1/register.php'></center>";
}
else
{
print "<center>";
print "<table class='tborder' cellpadding='6' cellspacing='1' border='0'>";
print "<tr><td class='panelsurround' align='center'><center>Invalid username or password</center></td></tr></table></center>";
//print "<META HTTP-EQUIV = 'Refresh' Content = '2; URL =http://127.0.0.1/login.php'></center>";
}
}
?>
•
•
Join Date: Aug 2007
Location: Cavite,Philippines
Posts: 508
Reputation:
Rep Power: 3
Solved Threads: 68
I think it's better to use sessions rather than cookies because cookies can be deleted by the user while sessions can not be deleted.
Me,I don't use cookies anymore.
Just my opinion....
Me,I don't use cookies anymore.
Just my opinion....
"death is the cure of all diseases..."
http://ryantetek.wordpress.com
http://ryantetek.wordpress.com
•
•
Join Date: Jul 2006
Posts: 66
Reputation:
Rep Power: 3
Solved Threads: 1
Thanx a lot Mr.ryan_vietnow I also in the same shoes
•
•
Join Date: Jul 2004
Location: North East Indiana
Posts: 491
Reputation:
Rep Power: 5
Solved Threads: 20
Cookies are bits of information that will remain accessible to the browser across many openings and closings of the browser. For example, the "Remember me" functions of websites use sessions. Sessions, OTOH, are only remembered while the browser is opened. If the browser is closed, the session ID will be different and the user will have to do things like log in again.
For the record, Mozilla lets me delete the session ID when I want to. It's just another cookie in Mozilla's point of view.
For the record, Mozilla lets me delete the session ID when I want to. It's just another cookie in Mozilla's point of view.
www.uncreativelabs.net
Old computers are getting to be a lost art. Here at Uncreative Labs, we still enjoy using the old computers. Sometimes we want to see how far a particular system can go, other times we use a stock system to remind ourselves of what we once had.
Old computers are getting to be a lost art. Here at Uncreative Labs, we still enjoy using the old computers. Sometimes we want to see how far a particular system can go, other times we use a stock system to remind ourselves of what we once had.
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- session_start(): Cannot send session cache limiter - (PHP)
- session_start(): Cannot send session cache limiter - (PHP)
- Netscape 7.1, Hotmail login problem - cookies 'disabled" (Windows NT / 2000 / XP / 2003)
- how can i used session and cookies ??? (PHP)
- Help me trouble with saving cookies win xp (Windows NT / 2000 / XP / 2003)
- Troubles with cookies win. xp (Windows NT / 2000 / XP / 2003)
- Cookies makers? (HTML and CSS)
Other Threads in the PHP Forum
- Previous Thread: php mssql connectivity error
- Next Thread: Never used PHP before and would need ALL YOUR HELP


Linear Mode