www.webdeveloper.com
Results 1 to 4 of 4

Thread: cookies

  1. #1
    Join Date
    Aug 2003
    Posts
    1,576

    cookies

    I can't get cookies working for me in this script... I check in firefox's list, and the cookie is definately being set, so I'd bet that the problem is being caused by the $_COOKIE line... heres my code:
    PHP Code:
    <?php
    $ip
    =$_SERVER['REMOTE_ADDR'];
    $poster=$_POST['name'];
    $message=htmlspecialchars($_POST['msg']);
    $message=preg_replace("/\n/","<br />",$message);
    if(isset(
    $_COOKIE['antispam'])){
        
    header("Location:http://www.samingle.com/newtag/timeout.php");
    }
    else{
        
    setcookie("antispam""true"time()+60);
    }
    if(
    strlen(trim($poster))>1&&strlen(trim($message))>0)
    {
    $file=getcwd() . "/tags.php";
    $handle=fopen($file,"r");
    $string=fread($handle,filesize($file));
    fclose($handle);
    $string="<span class=\"poster\">" $poster ": </span>" "<span class=\"message\">" $message "</span><br />\n" $string;
    $handle fopen($file,"w");
    fwrite($handle,$string);
    fclose($handle);
    $file=getcwd() . "/aoiahsdnnvasaovcah.dat";
    $handle=fopen($file,"r");
    $ips=fread($handle,filesize($file));
    fclose($handle);
    $handle fopen($file,"w");
    fwrite($handle,$ip " | " $poster " | " $message "\n" $ips);
    fclose($handle);
    }
    header("Location:" $_SERVER['HTTP_REFERER']);
    ?>

  2. #2
    Join Date
    Oct 2003
    Location
    The Dryer
    Posts
    538
    are you sure somethings wrong with the cookie?

    I simplified the cookie part of your script down to this:

    PHP Code:
    <?php

    if(isset($_COOKIE['antispam'])){
        echo 
    "cookie is set";
    }
    else{
        
    setcookie("antispam""true"time()+60);
        echo 
    "cookie wasn't set, but it is now set";
    }

    ?>
    and it works just fine for me.

  3. #3
    Join Date
    Aug 2003
    Posts
    1,576
    Ah, I figured out the problem, I forgot my exit() after the header in the cookies if statement... thanks for your help cheat...

  4. #4
    Join Date
    Oct 2003
    Location
    The Dryer
    Posts
    538
    sure

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles