WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] RunPHP and cookies? (2 posts)

  1. tomkinsg
    Member
    Posted 7 years ago #

    Hi there .. i am a newbie to WordPress and am hoping to use it as a CMS. I have got it up and running and also installed RunPHP so I can do a little scripting on the site.

    Here is my problem .. i have two pages, one that links to the second. On the fisrst page there are many links to the second page and each link is slightly different. On my existing site which i am planning to use wordpress to replace, a parameter is passed to the second page as a query string eg....

    mysite/mysecondpage.php?parameter

    I figureed there was no way to do this (help me if i am wrong) and get to the querystring in WordPress so i instead decided to try using cookies.

    in my 1st page i have something like ... <A HREF="/wordpress/mysecondpage/" onclick="document.cookie='parameter; path=/'"

    But when i get to read the cookie variable in mysecondpage, the value is not changed by the onclick.

    I am sure i must be doign something highly stupid here or there is an alternative method for me to pass a parameter successfully from one page to the next.

    thanks
    TheImperial1

  2. tomkinsg
    Member
    Posted 7 years ago #

    I managed to get this working. I don't know what it was that i was doing wrong because it suddenly started to work.

    Here is what i am going. In my one wordpress page, I have a lbutton generated in PHP that links to another wordpress page (new-page) as follows:

    <A HREF="/wordpress/new-page/" onclick="var cookie_date = new Date();document.cookie = 'class=CLASSCODE1; path=/'">

    It sets cookie called "class" to the value CLASSCODE1.

    Then in New-page, I am using the RunPHP plug in and I have the following code:

    <?php
    print_r($_COOKIE);
    ?>

    Which produces the following output showing teh cookie is set:

    (
    [wordpressuser_bbfa5b726c6b7a9cf3cda9370be3ee91] => admin
    [wordpresspass_bbfa5b726c6b7a9cf3cda9370be3ee91] => efa8253fd02c8bfc71a3aa83dc159a9b
    [dbx-pagemeta] => grabit=0 ,1 ,2 ,3 ,4 ,5 &advancedstuff=0-
    [dbx-postmeta] => grabit=0 ,1 ,2 ,3 ,4 ,5 ,6 &advancedstuff=0-
    [class] => CLASSCODE1
    )

Topic Closed

This topic has been closed to new replies.

About this Topic