1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Setcookie problem in non-FF browsers

Discussion in 'PHP' started by lpc11, Jul 25, 2010.

  1. #1
    I have a script for a basic login, and it only seems to work in Firefox. I've searched for a long time on this problem, and can't find a solution that works in IE or Safari (my other test browsers).

    I've pulled the cookie part out of my main login script, which explains why I'm being lazy and using GET.

    <?
    ini_set('display_errors',1);
    error_reporting(E_ALL|E_STRICT);
    
    $user = $_GET['1'];
    $pass = $_GET['2'];
    
    
    setcookie("username", $user, time()+36000000, "/xyz/", ".xxx.com", 1);
    setcookie("password", $pass, time()+36000000, "/xyz/", ".xxx.com", 1);
    
    
    ?>
    PHP:
    Every variation of this code seems to work in FF, but it absolutely will not work in IE or Safari. There is no cookie file being created. I have everything as unsecure as possible, and still the cookie isn't being created. I've tried every solution I could find on Google, but nothing changes. The correct values are in the 2 variables.
    SEMrush
    halp:<
     
    lpc11, Jul 25, 2010 IP
    SEMrush
  2. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #2
    Try this:
    
    <?php
    ini_set('display_errors',1);
    error_reporting(E_ALL|E_STRICT);
    
    $user = $_GET['1'];
    
    
    setcookie("username", $user, time()+36000000);
    echo $_COOKIE["username"];
    
    ?>
    
    PHP:
    I tested it myself, and it works in IE, I haven't tried it on Safari though.

    If it still doesn't work, you should try a better (and secure) alternative, PHP sessions.
     
    Rainulf, Jul 25, 2010 IP
  3. killerj

    killerj Active Member

    Messages:
    765
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    95
    #3
    Rainulf's code should work. But remember,its never a good idea to store passwords as cookies. Try storing something unique like a user ID as cookie instead. You can still retrieve username and password using the stored unique ID whenever required.
     
    killerj, Jul 27, 2010 IP
  4. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #4
    Also hash the pass.
     
    danx10, Jul 27, 2010 IP