Help
Search
Login
Register
Home
Forum: web design and graphics community
Celestial Star Forum
>
Web Development
>
Coding
>
Cookie Problems
Pages: [
1
]
« previous
next »
Print
Author
Topic: Cookie Problems (Read 815 times)
Blackstone
Administrator
Valkyrie Randgris
Posts: 821
Oh look! People!
Cookie Problems
«
on:
August 31, 2006, 10:20:21 AM »
Okay, I'm trying to create an administration panel for my site, which I've been longing to do for a while now but I just kept putting off. Now I've finally started working on it, and I can't get the cookies to work on the login page. I've looked over the code millions of times, and I can't find anything wrong, a reason why it shouldn't be working, so I decided I would get some extra help and see if someone else could find something I missed.
The code:
Code:
<?php
/*
This page processes the log in form the information entered into the log in form. If the information matches a row in the database,
then it will log in a redirect to the index page. Otherwise, it will show an error.
*/
//Include the databse information so we can access the database.
include&
#40;'database.php');
//Store the information given in the form into easier-to-type variables.
$Username
=
$_REQUEST
[
'username'
&
#93;;
$Password
=
$_REQUEST
[
'password'
&
#93;;
$Length
=
$_REQUEST
[
'length'
&
#93;;
//Search for the user in the database.
$Query
=
"SELECT * FROM `xxxxxx` WHERE `username` = '$Username' AND `password` = '$Password' LIMIT 1"
;
$Result
=
mysql_query
&
#40;$Query) or die('Failed to execute query: $Query. '.mysql_error());
if&
#40;mysql_fetch_array($Result)) {
//We have a successful match! Grab some information about the user and then stick some cookies into the Temp files. ^^
while&
#40;$info = mysql_fetch_array($Result)) {
$UserID
=
$info
[
'ID'
&
#93;;
$Name
=
$info
[
'name'
&
#93;;
&
#125;
//COOKIES! I wanna cookie!
setcookie
&
#40;'ValeniaAdmin_UserID', $UserID, time()+3600*24*30, '/');
setcookie
&
#40;'ValeniaAdmin_User', $Username, time()+3600*24*30, '/');
setcookie
&
#40;'ValeniaAdmin_Name', $Name, time()+3600*24*30, '/');
setcookie
&
#40;'ValeniaAdmin_Logged', true, time()+3600*24*30, '/');
//Redirect to the index page.
header
&
#40;'Location: http://xxxxxxxx/success/');
&
#125; else {
//Otherwise, since the log in was unsuccessful, we redirect to an error stating the problem.
header
&
#40;'Location: http://xxxxxxxx/loginerror/');
&
#125;
?>
I filtered some stuff for secrecy, so that's why you see random 'x's.
The strange thing with this is, the header redirect (the first one redirecting to the success page) works whenever I try to log in, but I keep on checking my cookies and I never see anything from this location.
Also, if you find anything that I could improve that isn't just about the cookies, I'd appreciate it if you told me. ^^ Thanks!
Logged
Blackstone
Administrator
Valkyrie Randgris
Posts: 821
Oh look! People!
Cookie Problems
«
Reply #1 on:
August 31, 2006, 11:33:46 AM »
Oy... I think I've lowered the problem down to something with my time functions. So... yeah, any help on that is still appreciated, as well as any suggestions with making the log-in more secure.
Logged
Vangs
Administrator
Valkyrie Randgris
Posts: 525
Cookie Problems
«
Reply #2 on:
August 31, 2006, 04:21:07 PM »
I doubt this will make much of a difference, but try setting the cookies with double quotes instead of single quotes. Also to make the script more secure, you'll need to set a cookie with your password hash in it. Then on every page in the admin section check the username and password in the cookies matches those in the database, and deny access if they don't. With your current setup it seems anyone can create a false cookie and get access.
Logged
Blackstone
Administrator
Valkyrie Randgris
Posts: 821
Oh look! People!
Cookie Problems
«
Reply #3 on:
August 31, 2006, 04:45:54 PM »
Okay, thanks. I shall try both of those suggestions. ^^
Logged
Pages: [
1
]
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
General
-----------------------------
=> General
=> New Members
=> Announcements
=> Support / Suggestions
-----------------------------
Contests
-----------------------------
=> Archive
===> Contests
===> Blend Challenges
===> SOTW
-----------------------------
Art Boards
-----------------------------
=> Creative mediums
=> Requests & offers
=> Tutorials
===> Celestial Star Tutorials
-----------------------------
Web Development
-----------------------------
=> Coding
=> Web Design
=> Advertisements / Affiliation
-----------------------------
Off-topic
-----------------------------
=> Entertainment
-----------------------------
Español (Spanish Only)
-----------------------------
=> General / Bienvenida
=> Anuncios / Ayuda
=> Código / Desarrollo web
Welcome,
Guest
Members login
Register for free
General
General
New members
Announcements
Support / Suggestions
Art boards
Creative mediums
Requests and offers
Tutorials
Celestial Star tutorials
Web development
Coding
Web design
Advertisements / affiliation
Off-topic
The non-sense
Ententainment
Loading...