WordPress.org

Support

Support » Plugins and Hacks » wordpress and cookies

wordpress and cookies

  • frederix1234
    Member

    @frederix1234

    hello there, i am a newbie to wordpress coding world and i have a question.
    i am making a single plugin like the following:

    – a username came to my blog using a url like the following:

    http://myblog.com/file.php

    if user go to my blog with that url file.php adds a cookie:

    setcookie(“Hosted”, $variable, time()+3600);

    after that file.php redirects or include(i tried boths) to index.php, blog is displayed and cookie is set propertly.

    Now, on my plugin i want to check if that cookie is there(and actually it is there), here is the code:

    add_filter(‘the_content’, ‘hosted’);

    function hosted($content) {

    if(isset($_COOKIE[“Hosted”])) {

    $content = “something”;

    return $content;
    }
    else {
    return $content;
    }
    }

    now, if the user cames to the blog from file.php the cookie will be set and the plugin should replace all posts to the string “something”.

    This works perfect on internet explorer but dont work propertly on firefox or opera.

    As i am a newbie i dont know if using a cookie is the best for this case, i am open to alternatives.

    Thanks in advance.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Pizdin Dim
    Member

    @pizdin_dim

    I’m kinda guessing a little bit here but what happens when you force the fourth parameter to the root of your domain like this:

    setcookie('hosted', $variable, time()+3600, '/');

    Does it make any difference?

    frederix1234
    Member

    @frederix1234

    thanks buddy for your reply.
    unfortunaly i tried but didnt work.

    i cant get how can works on ie and not in firefox, i also tried session variables with the same result.
    maybe is there a file i should add session_start?? i added on index.php in the wordpress root, on file.php and in the plugin php.

    i am sure the cookie is set, the problem is sometimes the plugin dont see it.

    more help or ideas will be apreciated.

    thanks again

    Pizdin Dim
    Member

    @pizdin_dim

    WP uses COOKIEPATH or SITECOOKIEPATH as the fourth parameter to register the cookies it usually needs. Perhaps try that instead of ‘/’ and see if that fixes it. Otherwise, I know that some browser configurations and client privacy software can interfere with cookies. See this Codex page for more.

    frederix1234
    Member

    @frederix1234

    thanks, i am going to try it on some minutes and ill let you know.

    wish me some luck 😉

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘wordpress and cookies’ is closed to new replies.