473,387 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

problem with sign in page

Hi,
I created the sign in page with username,password fields.and along with those fields i put the check box remember and select that one untill we sign out the page the username and password are remains.For that sign page i wrote the code like this [php]<?php
// The database connection.
$con = mysql_connect($db_host, $db_user, $db_pass);
if(!$con) {
die("Cannot connect. " . mysql_error());
}
$dbselect = mysql_select_db($db_name);
if(!$dbselect) {
die("Cannot select database " . mysql_error());
}
// Start a session. Session is explained below.
session_start();
// Same checking stuff all over again.
if(isset($_POST['submit'])) {
if(empty($_POST['user_name']) || empty($_POST['password'])) {
echo "Sorry, you have to fill in all forms";
exit;
}
// Create the variables again.
$user_name = $_POST['user_name'];
$password = $_POST['password'];
// Store the SQL query inside a variable.
// ONLY the username you have filled in is retrieved from the database.
$query = "SELECT user_name,password
FROM `registered_members`
WHERE user_name='$user_name'";
$result = mysql_query($query);
if(!$result) {
// Gives an error if the username given does not exist.
// or if something else is wrong.
echo "The query failed " . mysql_error();
} else {
// Now create an object from the data you've retrieved.
$row = mysql_fetch_object($result);
// You've now created an object containing the data.
// You can call data by using -> after $row.
// For example now the password is checked if they're equal.
if($row->password != $password)
{
echo "<center>";
echo "<h2>I am sorry , please enter correct password.</h2>";
echo "<br>";
echo "<a href=forgot.php><h4> Forgot Password?</h4></a>";
echo "<a href=index.html><h3> Home </h3></a>";
echo "</center>";
exit;
}
// By storing data inside the $_SESSION superglobal,
// you stay logged in until you close your browser.
$_SESSION['user_name'] = $user_name;
$_SESSION['sid'] = session_id();
// Make it more secure by storing the user's IP address.
$_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
// Now give the success message.
// $_SESSION['user_name'] should print out your username.
}
}
if(isset($_POST['remember'])){
echo "hello";
setcookie("cookname", $_SESSION['user_name'], time()+60*60*24*100, "/");
// ae_put_cookie('cookname', $_SESSION['user_name'], "forever");
echo $_COOKIE["user_name"];
// ae_put_cookie('cookpass', $_POST['password'], "forever");
setcookie("cookpass", $_POST['password'], time()+60*60*24*100, "/");
}

echo "<br><b>&nbsp;&nbsp;&nbsp;&nbsp;";
echo "Welcome " . $_SESSION['user_name'];
echo "</b>";
include("login1.php");
?>[/php]In that remember field can't work properly.plz tell that what's the problem in that code.
Apr 23 '08 #1
3 1669
Markus
6,050 Expert 4TB
[php]
<?php
// The database connection.
$con = mysql_connect($db_host, $db_user, $db_pass);
if(!$con) {
die("Cannot connect. " . mysql_error());
}
$dbselect = mysql_select_db($db_name);
if(!$dbselect) {
die("Cannot select database " . mysql_error());
}

// Start a session. Session is explained below.
session_start();

// Same checking stuff all over again.
if(isset($_POST['submit'])) {
if(empty($_POST['user_name']) || empty($_POST['password'])) {
echo "Sorry, you have to fill in all forms";
exit;
}
// Create the variables again.
$user_name = $_POST['user_name'];
$password = $_POST['password'];

// Store the SQL query inside a variable.
// ONLY the username you have filled in is retrieved from the database.
$query = "SELECT user_name,password
FROM `registered_members`
WHERE user_name='$user_name'";

$result = mysql_query($query);
if(!$result) {
// Gives an error if the username given does not exist.
// or if something else is wrong.
echo "The query failed " . mysql_error();
} else {
// Now create an object from the data you've retrieved.
$row = mysql_fetch_object($result);
// You've now created an object containing the data.
// You can call data by using -> after $row.
// For example now the password is checked if they're equal.
if($row->password != $password)
{
echo "<center>";
echo "<h2>I am sorry , please enter correct password.</h2>";
echo "<br>";
echo "<a href=forgot.php><h4> Forgot Password?</h4></a>";
echo "<a href=index.html><h3> Home </h3></a>";
echo "</center>";
exit;
}



// By storing data inside the $_SESSION superglobal,
// you stay logged in until you close your browser.
$_SESSION['user_name'] = $user_name;

$_SESSION['sid'] = session_id();
// Make it more secure by storing the user's IP address.
$_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
// Now give the success message.
// $_SESSION['user_name'] should print out your username.
}
}
if(isset($_POST['remember'])){
echo "hello";
setcookie("cookname", $_SESSION['user_name'], time()+60*60*24*100, "/");
// ae_put_cookie('cookname', $_SESSION['user_name'], "forever");
echo $_COOKIE["user_name"];
// ae_put_cookie('cookpass', $_POST['password'], "forever");
setcookie("cookpass", $_POST['password'], time()+60*60*24*100, "/");
}

echo "<br><b>&nbsp;&nbsp;&nbsp;&nbsp;";
echo "Welcome " . $_SESSION['user_name'];
echo "</b>";
include("login1.php");

?>
[/php]
Please use code tags.
Apr 23 '08 #2
Markus
6,050 Expert 4TB
lines 68 and 70 should be something like
[php]
setcookie("remember_me", $_SESSION['username'], time() + ... ");
echo $_COOKIE["remember_me"];
[/php]
Apr 23 '08 #3
ronverdonk
4,258 Expert 4TB
WARNING:
Please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

MODERATOR
Apr 24 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: george | last post by:
(driving me nuts) Hi there. I wonder if anyone can help? I'm including a page from Google in search.php, passing some parameters. So far so good. Then I'm asking to look through that Google...
4
by: ben | last post by:
Hi all, I have a simple PHP page that takes values from a form and puts them in a database (MySQL). The code is in a file test.php, which I have typed in at the bottom of this post (please...
4
by: Trond Meistad | last post by:
I have a website where I run a simple asp.net web application. On Sunday night, requests to this webapplication started to time out. After much debuggeing with no result, I created a new...
5
by: Vishal | last post by:
Hello, I already asked this question in the ASP.NET forums, but no help came. So I am hoping that somebody can help me out. This is really very URGENT me. For my e-commerce application, I...
3
by: David | last post by:
Hi all, I am having a slight issue with FormsAuthentication. I need to authenticate a user and while the page is still being processed, need to work with that authenticated user. I have set up...
3
by: Joe Fawcett | last post by:
Dear All We have an application where users login, their name/password details are stored in a table, and now we want to add a third party bulletin board that lives in its own virtual directory....
7
by: kingski | last post by:
Any idea about this ? http://www.developerfusion.co.uk/forums/thread/114379/#114379 "Can any one help me as i am building a shopping cart and it supports multiple currencies but while sending...
4
by: Dan | last post by:
I'm using asp.net c# in my code behind I coded the following: ButtonAsynchronous.Attributes.Add("onclick", @" setTimeout( ""UpdateImg('AnimatedProgress','images/running.gif');"" , 50); "); ...
0
by: Rasika WIJAYARATNE | last post by:
Hello everyone, We have a forum system on our website. The main web application is running in a virutal directory called /t7 and the forum system is on / t7/forums/. When someone wants to post...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.