General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 7th, 2002, 04:31 AM
fakker fakker is offline
The calm b4 the storm
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Manchester, UK
Posts: 404 fakker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via Yahoo to fakker
Angry cookie problem...

hey everyone...

I have a login script (see below) which checks for the username and password stored in a text file.. eg: (usernameassoword). ... that all works perfectly, and if a match is made, it will redirect the user to the admin.php

the problem is, it's not setting the cookie at all! I've tried a test page, so the cookie script is right... but for some reason it is just not being set. Is there something wrong with the code? or is the cookie in the wrong place??

Cheers for any help....

PHP Code:
<?php
//do_login.php
//this will check the username and password supplied from the login form
//and check the details against those found in the "users.txt" file.

//read in the contents of the file to get all users/passwords

    
$filename "users.txt";
    
$fp fopen($filename"r");
    
$file_contents fread($fpfilesize($filename));
    
fclose($fp);

    
//seperate the file by carriage returns
    
$line explode("\r"$file_contents);

    
// loop for as long as $line has stuff in it
    
$a 0;
    
$lineCount sizeof($line);
    while(
$a <= ($lineCount)) {            

        
// explode to get username and password
        
$data_pair explode(":"$line[$a]);
        
        
$username trim($data_pair[0]);
        
$password trim($data_pair[1]);
        
        
// try to find a match
        
if (($username == $user) && ($password == $pass)) {
            
            
//set login cookies
            
setcookie("auth","ok",time()+3600);
            
            
//located once I know the cookie is working!!
            //header("Location: ../../admin.php");
            
            //output the cookies..
            
foreach($_COOKIE as $key=>$value
            echo 
"$key: $value<br>\n";
            
            break;
    
        
// if match doesn't exit, assign value of 0 to $auth
        
} else {
            
            echo 
"no such username";
            break;

            
        }

        
// increment to continue looping
        
$a++;
    }

?>
__________________
Matt 'Fakker' Facer

mattfacer.com

Reply With Quote
  #2  
Old November 7th, 2002, 05:39 PM
wAr-AnGeL wAr-AnGeL is offline
Forum Security
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Behind You
Posts: 479 wAr-AnGeL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 50 sec
Reputation Power: 7
Send a message via ICQ to wAr-AnGeL Send a message via AIM to wAr-AnGeL
setcookie("name", "value", time() + 31536000, "/", "domain.com");

this is the way i set my cookies, havent had a problem.

try adding the few extra parameters, maybe it will work.
__________________




"Only Linux users see the end of crashes."
- Pl4t0

Reply With Quote
  #3  
Old November 7th, 2002, 06:38 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
just to point something out:

time() + 31536000

you could make your time function like this

time() + 3600 * 24 * 14

that would last for 2 weeks, this way its easier to change the time, then to recalculate the time like 31536000 eheh

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > cookie problem...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT