473,396 Members | 1,996 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,396 software developers and data experts.

Autologin using cookie

Hello all,
I have an autologin feature in the login form.So if autologin selected once,it should work using cookies then.How to use it.Please help???
Mar 3 '08 #1
5 4214
hsriat
1,654 Expert 1GB
[php]<?php
//file name: index.php
if isset($_COOKIE['name_of_the_cookie']) //COOKIE YOU ALREADY SET
{
$p1 = $_COOKIE['saved_password_in_the_cookie']; //PASSWORD IN THE COOKIE
/*
FETCH FROM DATABASE, THE ROW (SAY $db_row)HAVING THAT ID
$sql = _____________________________ ;
*/
$p2 = $db_row['password']; //PASSWORD FETCHED FROM DB FOR THAT ID

if ($p1 == $p2) //COMPARE PASSWORDS
{
header ("location:home.php"); //REDIRECT IF COOKIE VERIFIED
}
}
else
{
header ("location:login.php"); //REDIRECT TO LOGIN PAGE
}
?>[/PHP]
Is this what you need?
Mar 3 '08 #2
Thanks,but an error comes,cannot modify header..
Mar 3 '08 #3
hsriat
1,654 Expert 1GB
Thanks,but an error comes,cannot modify header..
Are you using it as it is?....

Remove any space or line break before <?php if there.
Mar 3 '08 #4
Sorry for the late reply.
I used[php]
if(isset($_POST["autologin"]))
{
$inTwoMonths = 60 * 60 * 24 * 60 + time();
setcookie('username',$_POST["Password"], $inTwoMonths);
setcookie('password',$_POST["Password"], $inTwoMonths);
}
in login page and
if(isset($_COOKIE['username']) AND isset($_COOKIE['password']))
{
$_SESSION["ww_2"]=23;
$redir=$_GET["redir"]?$_GET["redir"]:$_POST["redir"];
$redir=($redir?$redir:"./?p=myaccount&s=dayplanner");
header ("location:home.php");
//echo "<script language='javascript'>window.location='$redir'</script>";
exit();

} [/php]
in index page.
Please tell wat is wrong??Again i have to login..
Mar 4 '08 #5
ronverdonk
4,258 Expert 4TB
Please enclose any code within the proper code tags. See the Posting Guidelines on how to do that.

moderator
Mar 4 '08 #6

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

Similar topics

3
by: Mandy Holmes | last post by:
Hi all (Newbie alert!) I am a bit stuck. I want to set a cookie when a hyperlink on my website is clicked. This cookie will then be used to determing which of 5 images is displayed on that page...
1
by: Jenn | last post by:
I have done alot of web work in all sorts of languages but I have never used the simple cookie. Question is How does one set and retrieve a simple session cookie. All it will do is have an image...
14
by: Alec S. | last post by:
Hi, I'm using JavaScript and Cookies for some customization in a web page. There may be several values in the cookie with names that are not known at runtime. I need a way of deleting them. ...
4
by: craigkenisston | last post by:
I have an asp.net application in which I sometimes store a persistent cookie once the user has logged in and this has been working great. However, I now add some user information like, username,...
5
by: Åženol Akbulak | last post by:
Hello; I use in my web application FormsAuthentication. Also I use Session state (InProc). When a user logged in, I can read Session parameters. (For example Session). Problem is that, when...
12
by: Don Juan | last post by:
I have a simple html document I have been using for some time on my (i.e.) abc.com domain that uses cookies. I recently purchased a new domain name and set up a service to redirect my new domain...
2
by: barrybevel | last post by:
Hi, I have a very small simple program below which does the following: 1) post a username & password to a website - THIS WORKS 2) follow a link - THIS WORKS 3) update values of 2 fields and...
0
by: hariadusumalli | last post by:
Hi, My desktop app needs to identify a cookie stored on the client and send it in a http request to the web server. So I need to get the cookie from the cookie files saved in the browser and...
14
victorduwon
by: victorduwon | last post by:
Hi guys and gals, I am using javascript to autologin to my google analytics account via a hyperlink. This is what the text looks like this <?xml version="1.0" encoding="utf-8"?>...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...
0
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...
0
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.