ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Show content based on URL/cookie

April 25, 2011 2:25pm

Subscribe [3]
  • #1 / Apr 25, 2011 2:25pm

    marcxdid

    2 posts

    Hello,

    I’m not sure if this is possible with an Expression Engine plugin or if it has to be custom made with PHP.

    I’m looking for a way to store a cookie based on a url variable, and if the cookie is present display certain information.

    So for example my URL would be http://www.website.com/eletters/helloworld/?eletter, if the “?eletter” part is present a cookie is stored on the users computer, and certain content on the website is shown.

    I know CookiePlus can help me with the cookie part and using conditionals to show the content, but how would I go about the url variable? Is there a piece of custom PHP code I can use?

    Does anyone have any idea how I could do this? Thanks.

  • #2 / Apr 25, 2011 7:05pm

    Brandon Jones

    5500 posts

    Hi marcxdid,

    There are some interesting cookie add-ons, and set_cookie is a function available to all EE add-ons. I’ll move this over to the CodeShare Corner for further discussion.

  • #3 / Apr 25, 2011 7:35pm

    the3mus1can

    426 posts

    Try something along the lines of:

    <?php $cookie_value = ($this->EE->input->get('eletter') !== FALSE) ? 'yes': 'no'; ?>
    
    {exp:cookie_plus:set name="mycookie" value="<?php echo $cookie_value ?>" seconds="3600"}

    With PHP set to parse on input not output.

  • #4 / May 03, 2011 8:47am

    marcxdid

    2 posts

    Try something along the lines of:

    <?php $cookie_value = ($this->EE->input->get('eletter') !== FALSE) ? 'yes': 'no'; ?>
    
    {exp:cookie_plus:set name="mycookie" value="<?php echo $cookie_value ?>" seconds="3600"}

    With PHP set to parse on input not output.

    I’ve been tinkering with this but I can’t get it to work. I always get this error:

    Fatal error: Call to a member function on a non-object in /home/pathfinder/domains/mywebsite/public_html/EE/core/core.functions.php(637) : eval()'d code on line 1

    Could this be caused by the plugin LG htaccess generator?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases