Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 04-29-2009, 03:14 AM   #1 (permalink)
murdocsvan's Avatar
 
Ultra Techie

Join Date: Jun 2007

Location: Surrey, UK

Posts: 849

murdocsvan is on a distinguished road

Default Problem with PHP cookies

For some reason im having a great deal of problems with using cookies on my website. I have a login system which i initially set to use sessions, but decided to use cookies as sessions was a bit glitchy. The order of my website goes:

Login form > Check Login Script > Login Success Script > index.htm

on the first script, this is code that sets the cookie:

PHP Code:
        // Register $myusername, $mypassword and redirect to file "login_success.php"
        
$expire=time()+60*60*24*5;
        
setcookie('user'$username$expire);
        
header("location:login_success.php"); 
And this is the piece of code on each page that checks that the cookie is there:

PHP Code:
<?php

if(!isset($_COOKIE['user']))
    {
    
header("location:login/main_login.htm");
    }

?>

Now for some reason, it will go to the Login Success page, and not have a problem even though that page has the cookie checking code on it. However, when the Login Success page then redirects to the index.htm page, it goes straight back to the login form, thinking the cookie's not there. The second bit of code is identical on all the pages i have protected by the login system.

Thanks in advance.
__________________

murdocsvan is offline  
Old 04-29-2009, 03:26 PM   #2 (permalink)
CrazeD's Avatar
 
Wizard Techie

Join Date: Feb 2006

Location: Maine

Posts: 3,683

CrazeD will become famous soon enough

Send a message via AIM to CrazeD Send a message via MSN to CrazeD
Default Re: Problem with PHP cookies

Try the Cookie Editor plugin for Firefox to make sure the cookie is actually being set, and with the right parameters.
__________________

Need website help? PM me!
CrazeD is offline  
Old 05-25-2009, 07:53 PM   #3 (permalink)
 
Ultra Techie

Join Date: Sep 2005

Posts: 638

tommyboy123x is on a distinguished road

Send a message via AIM to tommyboy123x
Default Re: Problem with PHP cookies

Its probably because on every page you MUST use
session_start();
even when you are not using the sessions / variables on that page. Otherwise they are lost.

Make sure session_start(); is on top of each page BEFORE any output is made

__________________

Some real (as in actual) surveys that pay money!
tommyboy123x is offline  
Old 05-25-2009, 08:42 PM   #4 (permalink)
CrazeD's Avatar
 
Wizard Techie

Join Date: Feb 2006

Location: Maine

Posts: 3,683

CrazeD will become famous soon enough

Send a message via AIM to CrazeD Send a message via MSN to CrazeD
Default Re: Problem with PHP cookies

He's using cookies, not sessions.
__________________

Need website help? PM me!
CrazeD is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hard to diagnose internet problem theorigamist Computer Networking & Internet Access 2 02-18-2009 12:32 AM
Problem with 3D graphics mordi05 Windows Operating Systems and Software 6 12-10-2007 11:37 PM
Serious computer problem. HeeRoMaKi Hardware Troubleshooting 71 07-28-2007 11:42 PM
Dhcp leasing problem Kloppstock Computer Networking & Internet Access 12 05-13-2007 07:13 PM
cant find the problem... Jhill1 Hardware Troubleshooting 13 05-07-2007 04:51 PM