473,757 Members | 10,007 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Login Page: Remember ME

Hi All,

This is my 1st posting to this group. Can any1 help me with the
"Remember Me" which is there in a login form. Im pasting the code
below. Im not able to set a cookie..

Thanks,
Shakun Vohra
<?php
// saving script
session_start() ;
displayLogin();
// connect to the server
$conn= mysql_connect( 'localhost', 'csci242', 'spring2006' )
or die( "Error! Could not connect to database: " . mysql_error()
);

// select the database
mysql_select_db ( 'blogtagz' )
or die( "Error! Could not select the database: " . mysql_error()
);
// get the variables from the URL request string

$uname = $_POST['uname'];
$password = base64_encode($ _POST['password']);
$reme=$_POST['rememberme'];

/**
* checkLogin - Checks if the user has already previously
* logged in, and a session with the user has already been
* established. Also checks to see if user has been remembered.
* If so, the database is queried to make sure of the user's
* authenticity. Returns true if the user has logged in.
*/

function checkLogin(){
/* Check if user has been remembered */
if(isset($_COOK IE['cookname']) && isset($_COOKIE['cookpass'])){
$_SESSION['uname'] = $_COOKIE['cookname'];
$_SESSION['password'] = $_COOKIE['cookpass'];
}

/* Username and password have been set */
if(isset($_SESS ION['uname']) && isset($_SESSION['password'])){
//if(confirmUser( $_SESSION['uname'], $_SESSION['password']) == 0){
/* Confirm that username and password are valid */
if(confirmUser( $_SESSION['uname'], $_SESSION['password']) != 0){
/* Variables are incorrect, user not logged in */
unset($_SESSION['uname']);
unset($_SESSION['password']);
return false;
}
return true;
}
/* User not logged in */
else{
return false;

}
}
function confirmUser($us ername, $password){
global $conn;
/* Add slashes if necessary (for query) */
if(!get_magic_q uotes_gpc()) {
$username = addslashes($use rname);
}

/* Verify that user is in database */
$q = "select password from users where UserID = '$username'";
$result = mysql_query($q, $conn);
if(!$result || (mysql_numrows( $result) < 1)){
return 1; //Indicates username failure
}

/* Retrieve password from result, strip slashes */
$dbarray = mysql_fetch_arr ay($result);
$dbarray['password'] = stripslashes($d barray['password']);
$password = stripslashes($p assword);

/* Validate that password is correct */
if($password == $dbarray['password'])
{
return 0; //Success! Username and password confirmed
}
else{
return 2; //Indicates password failure
}
}

/**
* Determines whether or not to display the login
* form or to show the user that he is logged in
* based on if the session variables are set.
*/
function displayLogin(){
global $logged_in;

if($logged_in){
echo "<h1>Logged In!</h1>";
echo "Welcome , you are logged in. <a
href=\"logout.p hp\">Logout</a>";
}
else{

?>

<h1>Login</h1>
<form action="" method="post">
<table align="left" border="0" cellspacing="0" cellpadding="3" >
<tr><td>Usernam e:</td><td><input type="text" name="uname"
maxlength="30"> </td></tr>
<tr><td>Passwor d:</td><td><input type="password" name="password"
maxlength="30"> </td></tr>
<tr><td colspan="2" align="left"><i nput type="checkbox"
name="rememberm e">
<font size="2">Rememb er me next time</td></tr>
<tr><td colspan="2" align="right">< input type="submit" name="sublogin"
value="Login"></td></tr>
<tr><td colspan="2" align="left"><a
href="User_Regi stration.php">J oin</a></td></tr>
</table>
</form>

<?

}
}
/**
* Checks to see if the user has submitted his
* username and password through the login form,
* if so, checks authenticity in database and
* creates session.
*/

if(isset($_POST['sublogin'])){
/* Check that all fields were typed in */
if(!$_POST['uname'] || !$_POST['password']){
die('You didn\'t fill in a required field.');
}
/* Spruce up username, check length */
$_POST['uname'] = trim($_POST['uname']);
if(strlen($_POS T['uname']) > 30){
die("Sorry, the username is longer than 30 characters, please
shorten it.");
}

/* Checks that username is in database and password is correct */
$pass = base64_encode($ _POST['password']);
$result = confirmUser($_P OST['uname'], $pass);

/* Check error codes */
if($result == 1){
die('That username doesn\'t exist in our database.');
}
else if($result == 2){
die('Incorrect password, please try again.');
}

/* Username and password correct, register session variables */
$_POST['uname'] = stripslashes($_ POST['uname']);
$_SESSION['uname'] = $_POST['uname'];
$_SESSION['password'] = $pass;

/**
* Here the user has requested that we remember that
* he's logged in, so we set two cookies. One to hold his username,
* and one to hold his encrypted password. We set them both to
* expire in 100 days. Now, next time he comes to our site, we will
* log him in automatically.
*/
if(isset($_POST['rememberme'])){
setcookie("cook name", $_SESSION['uname'], time()+60*60*24 *100,
"/",0);
setcookie("cook pass", $_SESSION['password'], time()+60*60*24 *100,
"/",0);

}

/* Quick self-redirect to avoid resending data on refresh */
// echo "<meta http-equiv=\"Refresh \"
content=\"0;url =$HTTP_SERVER_V ARS[PHP_SELF]\">";
// echo("hello without remem");
// echo(isset($_PO ST['rememberme']));
return;
}

/* Sets the value of the logged_in variable, which can be used in your
code */
$logged_in = checkLogin();

?>

Apr 6 '06 #1
2 3564
Shakun wrote:
Hi All,

This is my 1st posting to this group. Can any1 help me with the
"Remember Me" which is there in a login form. Im pasting the code
below. Im not able to set a cookie..

Thanks,
Shakun Vohra


<code snipped>

Are cookies enabled on your browser? Does your browser delete cookies at the
end of its session?

What error messages do you get? If you don't get any - try displaying all errors:

ini_set('displa y_errors', 1);
display_errors( E_ALL);

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Apr 6 '06 #2
everything was enabled... and there was no error message coming.. it
didnt go to the next page once i logged in.

But its WORKING now... I just copied the code and made a new file. I
dont know how it worked with the new file name and the same code.

Thanks anyways for your reply. Appreciated!

Shakun Vohra

Apr 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2212
by: Sniffer-Dog | last post by:
Hi I just wondered if anyone can spot anything wrong with the following? I have now added the session_start(); as the first command in the code to all the pages needing it. When I click on a webpage that is restricted, it takes me to the login page fine. When I login though instead of taking me to the page I clicked previous to that, it always takes me to the index file, and when I try to then click on the page I wanted to go to, it...
1
5510
by: Wayne Smith | last post by:
Applies to: Microsoft FrontPage 2000, Microsoft Access 2000, IIS 5.0 Operating System: Microsoft Windows 2000 Professional I am trying to protect a portion of a web site by allowing users to register a username and password & then login with those details, but so far I am having only marginal success. I am far from an expert on ASP programming, indeed the code I am using comes from "Sams Teach Yourself E-Commerce Programming with ASP" but it...
14
2271
by: frizzle | last post by:
Hi Group, I have a site with a MySQL backend. It has a member-system. Members login with a small login-form that appears on every page (via include()) If members are logged in, the form disappears and a few extra links appear instead of the form. - If members log in, i want to redirect them, if succesful, back to the page they logged in from.
1
2548
by: Dabbler | last post by:
I have a login page which requires all users to login everytime they visit, the remember me feature isn't working. We all have cookies and js enabled. Any suggestions on how to diagnose this? My login aspx: <asp:Login ID="Login1" runat="server" BackColor="#FFFFCC" BorderColor="#5400A8" BorderPadding="4" BorderStyle="Solid" BorderWidth="1px"
6
3359
by: AppleBag | last post by:
I'm having the worst time trying to login to myspace through code. Can someone tell me how to do this? Please try it yourself before replying, only because I have asked this a couple of times in the past in other places, and while the help was much appreciated, it seemed everyone just wanted to 'theoretically' explain how to do it, but when I tried to do it myself, I couldn't login. I want to simply pass the email address and password to...
4
8591
by: Freedolen | last post by:
Hi All, I had a perl script which is used to login in a web page, but it gives the error as "301 Moved Permanently". What does this means and how can it be rectified? Can anyone help on this? Code Snippet: use HTTP::Cookies; use HTTP::Request;
1
2338
by: =?Utf-8?B?QW1pciBUb2hpZGk=?= | last post by:
Hello The site I am working on redirects the user to a "session timed out" page when: - the user's session has expired AND - the user action results in a postback to the server I then need to redirect the user to either the Login page or the Welcome page depending on whether the user logged in and checked the Remember Me
1
3324
by: =?Utf-8?B?VEo=?= | last post by:
Hi, Environment : Asp.net 2.0 / C# As you know, there is a "Remember me" check box in Login control is VS.NET 2005. It allows you to get in the page without logging it if user closes browser, instead of logging out. It works...however, in the authenticate event, what if session is used?
0
1157
by: Anup Daware | last post by:
Hi All, I am facing this very weird issue, for every server request my control is redirecting to the login page and again coming back to the actual page from where the request was initiated when I set my custom Remember be cookie on the login page. Following are the details: 1. Authentication mode is ‘Forms’ 2. This issue is reproducible only in deployed applications, I found this using my trace and remote debugging 3. This issue occurs...
0
9489
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9298
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10072
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9906
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3829
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2698
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.