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.

URL String Variable Parameter?

March 29, 2011 9:09am

Subscribe [8]
  • #1 / Mar 29, 2011 9:09am

    28Bytes

    192 posts

    I have a unique situation with a project that I need to get some input on, to see if this is even possible with native functionally or add-ons.

    So if someone would visit your website from the url of http://www.yourwebsite.com/index.php?source=ppc is there some way in EE that the system can see that variable of ppc in the url string and show a conditional based on that parameter?

    If so how far can you go with it? If not is there a way with PHP or an add-on that you would know of?

    Thanks in advance,

    Brandon

  • #2 / Mar 29, 2011 6:10pm

    Greg Salt

    3988 posts

    Hi Brandon,

    Yes this possible. Your best bet to create an extension or plugin to do this but you can do it in a template as long as PHP parsing is on Input and Strict URLs are off:

    <?php
    $this->EE->config->_global_vars['source'] = $this->EE->input->get('source');
    ?>
    ...rest of my template code
    {if source == 'ppc'}
    PPC was passed in the source query string
    {/if}

    I stress though that this is best done in an addon. Hope that helps.

    Cheers

    Greg

  • #3 / Mar 29, 2011 9:39pm

    28Bytes

    192 posts

    Fantastic so say you were using the simple commerce module can you pass that variable through the whole process to track the sale based on that variable.

  • #4 / Mar 30, 2011 7:01am

    Mark Bowen

    12637 posts

    Sorry to butt in on this one but I was looking at doing something similar the other day and was going to create a plugin to do this when I came across this thread. I know how to create a plugin to access GET and POST variables and there are even a few out there already but I was trying to add in a variable to the end of a URL something like this :

    http://www.example.com/template_group/template_name?name=Me

    and I can’t get it to work. In fact what happens is that depending on what I use as the variable name then different templates from my template group start outputting to the page instead! All very weird.

    I definitely have Strict URLs turned off but I’m just wondering will this sort of thing only work on URLs such as http://www.example.com/index.php?name=Me or should it work with template_group/template_name?name=Me type URLs too?

    Thanks.

    Best wishes,

    Mark

  • #5 / Mar 31, 2011 9:51am

    kmgkid

    50 posts

    I’m having the same issue as Mark.  Mark, were you able to find a solution?

  • #6 / Mar 31, 2011 9:54am

    Mark Bowen

    12637 posts

    Nope not yet. As mentioned above I’m wondering if doing this sort of thing only works on the index.php of the site and not on any template_group/template_name places.

    Greg, any ideas on that one?

    Best wishes,

    Mark

  • #7 / Mar 31, 2011 11:25am

    Mark Bowen

    12637 posts

    This is very very very strange!!

    After having a discussion with a couple of fellow #eecms peeps on Twitter it is now all working again! The strange thing is though then only thing I did was to try, I stress try changing the uri_protocol in system->expressionengine->config->config.php to the other settings, all of which gave me loads of errors so to that end I reverted it back to AUTO which is where it was before I tried messing with that setting. Nothing else in the system, the templates or anywhere has changed but now it is working!!

    Anyone any ideas on that one then?

    Best wishes,

    Mark

  • #8 / Mar 31, 2011 12:38pm

    Lisa Wess

    20502 posts

    I’ve seen this with server-side caching. Sometimes forcing an error clears that cache, and then things “work” again.  We’ve had to do that on a few troubleshooting threads to get to the bottom of inexplicable issues.

    kmgkid - does that help you at all? If you force a PHP error in some way then fix it, does Greg’s solution work?

  • #9 / Mar 31, 2011 12:58pm

    Mark Bowen

    12637 posts

    Hi Lisa,

    I’ve seen this with server-side caching. Sometimes forcing an error clears that cache, and then things “work” again.  We’ve had to do that on a few troubleshooting threads to get to the bottom of inexplicable issues.

    Thanks for the information there. Will keep that in mind next time something like that crops up as I really wouldn’t know where else to look as I absolutely didn’t change anything else in the system at all so it was all very very weird. I’m happy to take that as an explanation though. I don’t know that it was that but anything to stop me from thinking I’m going mad will do for me 😉

    Best wishes,

    Mark

  • #10 / Mar 31, 2011 2:12pm

    kmgkid

    50 posts

    Hi Lisa,

    Unfortunately that did not work for me.

  • #11 / Mar 31, 2011 3:14pm

    kmgkid

    50 posts

    Update: I got the above example working using

    “&” instead of “?”

    http://www.example.com/template_group/template_name?name=Me

    http://www.example.com/template_group/template_name&name=Me

    I have $config[‘uri_protocol’]  = “AUTO”;

    Also in my .htaccess my rewrite rule to remove index.php is as follows (with a “?”)

    RewriteRule (.*) /index.php?/$1 [L]


    However my end goal is to pass a url like so

    http://www.example.com/template_group/template_name?url=http://domain.com
    http://www.example.com/template_group/template_name&url=http://domain.com

    Still working on getting this work.


    Thanks all for your help.

  • #12 / Apr 01, 2011 12:40am

    John Henry Donovan

    12339 posts

    kmgkid,

    Do you wish me to move this thread to the CodeShare Corner for some more community help?

    Always try these things first without a htaccess and your index.php in place

  • #13 / Apr 06, 2011 2:31pm

    kmgkid

    50 posts

    I resolved my issue so you can close.

    Thanks all.

  • #14 / Apr 06, 2011 3:10pm

    Sue Crocker

    26054 posts

    Hi, 28Bytes. What about you?

  • #15 / Apr 06, 2011 9:31pm

    Brett Gullan

    70 posts

    28bytes,

    Are you familiar with this plugin: http://devot-ee.com/add-ons/mo-variables/? Might be useful.

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

ExpressionEngine News!

#eecms, #events, #releases