SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: Cookies

  1. #1
    SitePoint Zealot doca's Avatar
    Join Date
    Dec 2004
    Location
    Vienna, AT
    Posts
    168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Cookies

    I have Frustrating problem with cookies!
    I offer a free remotely hosted (shoutbox) but those cookies working properly only on my website
    Need features like to remember user name/URL

    setcookie
    PHP Code:
    <?php
    setcookie
    ("tagname",$tagname,time()+108000);
    If(
    $emurl){setcookie("emurl",$emurl,time()+108000);}
    ?>
    read cookie
    PHP Code:
    <?php
    If ($_COOKIE['tagname']) {
              print
    "<input onfocus=cleanit(this);refresh_nu() value='".$_COOKIE['tagname']."' name=\"tagname\" size=\"18\" maxlength=\"20\" style=\"border:0;background-color:$bottominput;color:$othertxtcolor;font-size:8pt; font-family:Verdana, Arial, Helvetica, sans-serif;\"><br>";
              } else {
              print
    "<input onfocus=cleanit(this);refresh_nu() value=\"$posternam_member\" name=\"tagname\" size=\"18\" maxlength=\"20\" style=\"border:0;background-color:$bottominput;color:$othertxtcolor;font-size:8pt; font-family:Verdana, Arial, Helvetica, sans-serif;\"><br>";
              }
              If (
    $_COOKIE['emurl']) {
              print
    "<input onfocus=cleanit(this);refresh_nu() value='".$_COOKIE['emurl']."' name=\"emurl\" size=\"18\" maxlength=\"60\" style=\"border:0;background-color:$bottominput;color:$othertxtcolor;font-size:8pt; font-family:Verdana, Arial, Helvetica, sans-serif;\"><br>";
              } else {
              print
    "<input onfocus=cleanit(this);refresh_nu() value=\"$posteruae_member\" name=\"emurl\" size=\"18\" maxlength=\"60\" style=\"border:0;background-color:$bottominput;color:$othertxtcolor;font-size:8pt; font-family:Verdana, Arial, Helvetica, sans-serif;\"><br>";
              }
    ?>

  2. #2
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you sure $tagname's defined onset? Is that the submit? You should be using $_POST['tagname'] unless I'm mistaken...

  3. #3
    SitePoint Zealot doca's Avatar
    Join Date
    Dec 2004
    Location
    Vienna, AT
    Posts
    168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am not sure but I try (post) thanks

    PHP Code:
    if ($tagname && $hdmsg && $id){
            
    $tagname addslashes($tagname);
            
    $emurl addslashes($emurl);
            
    $hdmsg strip_tags($hdmsg$allowedtags);
            
    $hdmsg addslashes($hdmsg);
            
    $poster str_replace("\""""$poster);
            
    $poster str_replace("'"""$poster);
            
    $emurl str_replace("\""""$emurl);
            
    $emurl str_replace("'"""$emurl);
            
    $emurl strip_tags($emurl);
            if (
    substr(strtolower($emurl),0,4)!="http" && !stristr($emurl"@")) $emurl "http://".$emurl;
            If(empty(
    $tagname) || $tagname=="$posternam_member") {
            
    $error="1";
            
    $error_text .= "$error_text1<EMBED SRC=\"data/error.wav\" autostart=\"true\" HIDDEN=\"TRUE\" NAME=\"sound1\" MASTERSOUND><br />";
            }
            If (empty(
    $hdmsg) || $hdmsg=="$postermes_member") {
            
    $error="1";
            
    $error_text .= "$error_text2<EMBED SRC=\"data/error.wav\" autostart=\"true\" HIDDEN=\"TRUE\" NAME=\"sound1\" MASTERSOUND><br />";
            }
            If (
    $error=="1") {
            
    $show_errors "<tr align=\"center\"><td><b>$error_text</b></td></tr>";
            }
            Else 
            {
            
    $sql "insert into $tableposts values('', '$id', '$tagname', '$emurl', '$hdmsg','$REMOTE_ADDR', now())";
            
    $result mysql_query($sql) or die("Failed: $sql");
            
    $sql "select totalposts from $tableusers where id='$id'";
            
    $result mysql_query($sql) or die("Failed: $sql");
            
    $resrow mysql_fetch_row($result);
            
    $totalposts $resrow[0];
            
    $totalposts++;
            
    $sql "update $tableusers set totalposts='$totalposts', lastpost=now() where id='$id'";
            
    $result mysql_query($sql) or die("Failed: $sql");
            
    setcookie("tagname",$tagname,time()+108000);
            If(
    $emurl){setcookie("emurl",$emurl,time()+108000);}
            
    Header("Location: $hotshoutfile?id=$id");
            exit;
    }

    form
    PHP Code:
    <form action=\"".$thurl."$shoutfile?id=$id\" method=\"post\" name=\"tagform\" target=\"tag\" onSubmit=\"submitonce(this)\"> 
              <input type=\"hidden\" name=\"tagform\" value=\"
    $validlogin\">$smilieslink
              <input type=\"hidden\" name=\"hdmsg\"><div id=\"progressbar1\" style=\"width: 0px; height: 12px; color: 
    $othertxtcolor; font-size: 10px; overflow: hidden; background-color: $linkcolor; padding-left: 5px;\"></div>";
              If (
    $_COOKIE['tagname']) {
              print
    "<input onfocus=cleanit(this);refresh_nu() value='".$_COOKIE['tagname']."' name=\"tagname\" size=\"18\" maxlength=\"20\" style=\"border:0;background-color:$bottominput;color:$othertxtcolor;font-size:8pt; font-family:Verdana, Arial, Helvetica, sans-serif;\"><br>";
              } else {
              print
    "<input onfocus=cleanit(this);refresh_nu() value=\"$posternam_member\" name=\"tagname\" size=\"18\" maxlength=\"20\" style=\"border:0;background-color:$bottominput;color:$othertxtcolor;font-size:8pt; font-family:Verdana, Arial, Helvetica, sans-serif;\"><br>";
              }
              If (
    $_COOKIE['emurl']) {
              print
    "<input onfocus=cleanit(this);refresh_nu() value='".$_COOKIE['emurl']."' name=\"emurl\" size=\"18\" maxlength=\"60\" style=\"border:0;background-color:$bottominput;color:$othertxtcolor;font-size:8pt; font-family:Verdana, Arial, Helvetica, sans-serif;\"><br>";
              } else {
              print
    "<input onfocus=cleanit(this);refresh_nu() value=\"$posteruae_member\" name=\"emurl\" size=\"18\" maxlength=\"60\" style=\"border:0;background-color:$bottominput;color:$othertxtcolor;font-size:8pt; font-family:Verdana, Arial, Helvetica, sans-serif;\"><br>";
              }
              print
    "<input onfocus=cleanit(this);refresh_nu() onKeyDown=\"textCounter(this,'progressbar1',100)\" onKeyUp=\"textCounter(this,'progressbar1',100)\" onFocus=\"textCounter(this,'progressbar1',100)\" value=\"$postermes_member\" name=\"message\" size=\"18\" maxlength=\"100\" wrap style=\"border:0;background-color:$bottominput;color:$othertxtcolor;font-size:8pt; font-family:Verdana, Arial, Helvetica, sans-serif;\"><br>";
              print
    "<input value=\"$send_member\" TYPE=submit alt=\"$send_member\" style=\"border:1px solid #274E75; FONT-WEIGHT: bold; FONT-SIZE: 9px; BACKGROUND-IMAGE: url('data/button/$button.gif'); COLOR: black; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; border-colordark: black; border-colorlight: black\" onClick=\"document.tagform.hdmsg.value = document.tagform.message.value;document.tagform.message.value = '';\"> <input value=\"$reset_member\" TYPE=reset alt=\"$reset_member\" name=reset style=\"border:1px solid #274E75; FONT-WEIGHT: bold; FONT-SIZE: 9px; BACKGROUND-IMAGE: url('data/button/$button.gif'); COLOR: black; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; border-colordark: black; border-colorlight: black\">";
              print
    "<script>textCounter(document.getElementById(\"maxcharfield\"),\"progressbar1\",100)</script></td>
      </tr>
    </table>
    <div style=\"padding-left: 2; padding-top: 1\">
    $htmlmsgs</div></form> 

  4. #4
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    What do you mean by "remotely hosted" and "working properly only on my website"? As far as I recall then the Cookies can only be read from the domain on which they were set. i.e. Your website can read cookies created on your website, but not cookies created on a remote website.
    Ian Anderson
    www.siteguru.co.uk

  5. #5
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by siteguru
    What do you mean by "remotely hosted" and "working properly only on my website"? As far as I recall then the Cookies can only be read from the domain on which they were set. i.e. Your website can read cookies created on your website, but not cookies created on a remote website.
    With the exception of third party cookies, which aren't supported by all browsers and are a bit strange at times.

  6. #6
    SitePoint Zealot doca's Avatar
    Join Date
    Dec 2004
    Location
    Vienna, AT
    Posts
    168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post

    Quote Originally Posted by siteguru
    What do you mean by "remotely hosted" and "working properly only on my website"? As far as I recall then the Cookies can only be read from the domain on which they were set. i.e. Your website can read cookies created on your website, but not cookies created on a remote website.
    You know I offer a free remotely hosted (shoutbox) service , each user has his own id and each user has a (link to my website) in an iframe on his homepage. cookies working fine on my domain but on another domain not
    soory about bad english I am german
    Last edited by doca; Dec 12, 2004 at 17:49.

  7. #7
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Which leads me to believe my thoughts on cookies and remote domains are correct - it works when on your server (domain) because everything is on your domain, but once someone else hosts the shoutbox (i.e. links to your site via an iframe) then the domain changes as far as cookies are concerned and so they are blocked.
    Ian Anderson
    www.siteguru.co.uk

  8. #8
    SitePoint Zealot doca's Avatar
    Join Date
    Dec 2004
    Location
    Vienna, AT
    Posts
    168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How can I resolve this problem ????
    I can use something like this but I dont how ( need flood protection for two minutes and not 24h) IPs are stored in db. IP based flood pretection is ok
    PHP Code:
    if ($owner && $message && $post=="1"){
        
    $today strftime("%Y-%m-%d"time());
        
    $sql "select id from $msgstable where dt rlike '$today' and owner='$owner' and ip='$REMOTE_ADDR'";
        
    $result mysql_query($sql) or die("Failed: $sql");
        
    $numrows mysql_num_rows($result);
        if (
    $numrows!=0){
            echo 
    "<div align=\"center\"><b><img src=\"$images_directory/error.gif\" border=\"0\" alt=\"$error9\"><br>$error9 $errormessage9</b></div>";
            exit;
        } 
    or something like this but this dont work

    PHP Code:
    $sql "SELECT dt FROM $tableposts WHERE owner='$id' order by dt desc";
            if (
    $dt date("YmdHis") - 60) { die("Error: You cannot post within 60 seconds of a previous post."); } 
    Last edited by doca; Dec 13, 2004 at 11:14.


Bookmarks

Posting Permissions

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