WordPress.org

Ready to get started?Download WordPress

Forums

wordpress and cookies (5 posts)

  1. frederix1234
    Member
    Posted 7 years ago #

    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.

  2. pizdin_dim
    Member
    Posted 7 years ago #

    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?

  3. frederix1234
    Member
    Posted 7 years ago #

    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

  4. pizdin_dim
    Member
    Posted 7 years ago #

    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.

  5. frederix1234
    Member
    Posted 7 years ago #

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

    wish me some luck ;)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.