We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Custom plugin to capture and store variable from referring URL

Development and Programming

radar77's avatar
radar77
28 posts
17 years ago
radar77's avatar radar77

I did make some changes to the plugin, which is perhaps why the error line wasn’t matching up.

Here is the latest error message I receive, which corresponds with the last line of the plugin:

Warning: Cannot modify header information - headers already sent by (output started at /home/xxxxx/domains/mydomain.com/html/_sys/plugins/pi.radar.php:66) in /home/xxxxx/domains/mydomain.com/html/_sys/core/core.functions.php on line 726

.zip file attached.

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

Yep, you have one space after the closing PHP tag, which is the source of the error.

       
radar77's avatar
radar77
28 posts
17 years ago
radar77's avatar radar77

Ah, silly mistake!

Ok, so now that I know cookies are the way to go, I want to make sure that I am going about capturing the “web_alias” value the best way.

I need to capture the “ID” value, which only exists in the referring URL:

http://www.mydomain.com/page.aspx?ID=web_alias

So, my question is, is there a better way to capture this value than what I am doing in the code below?

<?php

global $IN, $FNS;

$seconds = 60;

//Grab the referring URL, which includes ID=web_alias
$fs_refer = $IN->GBL('HTTP_REFERER', 'SERVER');
$fs_refer = explode("=", $fs_refer); //Is there a better way to capture the "ID" value from a referring URL?
$web_alias = $fs_refer[1]; //Sets the web_alias based on the referring URL
$FNS->set_cookie('web_alias', $web_alias, $seconds); //Finally, store the web_alias in a cookie

//This will grab the host, which I will use later on
$host_refer = parse_url($IN->GBL('HTTP_REFERER', 'SERVER'));
$host_refer = $host_refer['host'];

?>

Or is this only reliable way to rewrite links to include the “ID” value in the URL?

Cheers

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

It seems fine with me, though I’m still not seeing all of the pieces of how or why you need to do this, so I can’t say for instance whether or not this is an approach I would use. The only comment I have is that a sixty second cookie expiry is mighty short.

       
Jamie Poitra's avatar
Jamie Poitra
409 posts
17 years ago
Jamie Poitra's avatar Jamie Poitra

Yeah the 60 seconds was just me putting something in there in my hurry to figure something that should work instead of the session cache.

I still don’t get why you are getting the ID value that way. Why not just the $IN->GBL(‘ID’) like one would normally do?

There is nothing stopping you from using the HTTP_REFERER thing to see where they are coming from. Just seems like a lot of steps to get one value when you can do it in one step.

Jamie

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

Unless I’m confused, these URLs are not the landing URLs, so he needs to get it from the referrer data; it won’t be in GET or POST. Note that I’m not eliminating the possibility of being confused.

       
Jamie Poitra's avatar
Jamie Poitra
409 posts
17 years ago
Jamie Poitra's avatar Jamie Poitra

Oh gosh. Yeah, I’m the one confused it would seem.

Jamie

       
radar77's avatar
radar77
28 posts
17 years ago
radar77's avatar radar77

@Derek You’re not confused, that’s exactly right! I will adjust the cookie expiry time as well.

@Jamie No big deal, I thought I maybe wasn’t being clear, but yeah, the “ID” only exists in the referring URL. I just wasn’t sure if there was a better way to grab that value, but it appears not.

       
1 2

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.