The MU forums have moved to WordPress.org

Adding PHP Code To Set Cookie (3 posts)

  1. johanhorak
    Member
    Posted 14 years ago #

    Hi I need to add some php to one of my mu blogs that was created at http://coffeenews.ilocals.info

    Here's the code:

    <?php
    if (!empty($_GET['jrox']))
    {
    $cookie_expires = 1 * 60 * 60 * 24 * 365;
    $cookie_domain = '.your_domain.com'; //DON'T FORGET THE . (dot) before the domain
    setcookie("jrox", $_GET['jrox'], time()+$cookie_expires,"/", $cookie_domain);
    }
    ?>

    Apparently I can create a cookiepage.php and place it at mudomain.com/cookiepage.php

    But how do I do it at

    http://coffeenews.ilocals.info/cookiepage.php
    ?

    There must be another solution where I just add this php code to one of my existing php pages.

    Thanks for helping.

    Johan

  2. cafespain
    Member
    Posted 14 years ago #

    create a file called cookiepage.php, put your code in it and upload it to your server.

  3. johanhorak
    Member
    Posted 14 years ago #

    Thanks cafespain That makes sense if it was not a mu blog that needs to set the cookie at the one subdomain. I cannot see how to upload this file to sub domain coffeenews.ilocals.info.

    Therefore:

    I have now decided to add the code to the theme I use for this sub domain only.

    If use my own logic I should add it to my header.php because then the cookie can be set for any page. The other option is index.php but then my limited experience tells me the cookie may only be set for the main url
    http://coffeenews.ilocals.info

About this Topic

  • Started 14 years ago by johanhorak
  • Latest reply from johanhorak