...

View Full Version : How do I pass QUERYSTRING VARIABLES from page to page without a FORM?



supaflyboy
05-19-2008, 10:06 AM
Hi. I am trying to pass querystring variables from page to page. Here is the senario.

A user is referred a page, example
http://www.stealthmoneymaker.com/index.php?cash=1381

We can see the string is cash=1381

Basically its an affiliate link, so this would be the exact link a user would be given, there is no form to be filled out.

Now when the user goes to the next page, the querystring is still passed along, even though there is no form submit or anything.

What is the method used to do this? You can go to the link i gave above for an exact example of what I am trying to do. The string is passed from each page, all the way to the paypal page.

Thanks for the help (this is not my affiliate link)

syosoft
05-19-2008, 10:58 AM
I swear I came across this the other day, and thought to myself, "how would this be useful?" so I disregarded it. I'm asking around in ##php on freenode but everyone thinks I'm crazy. Maybe I misunderstood or simply made the feature up. I'm looking thou...

syosoft
05-19-2008, 11:18 AM
Yea, I couldnt find anything.
Look into buffering all of the output into a variable, preg_match() for each link, and then replace all found links appending your querystring of choice.

Really isn't that much code, but if you're unfamiliar w/ the concept, it can seem daunting.



// This is completely untested and just a quick quick QUICK mockup
// It assumes $page_source is the full html source of your page to output
ob_start();
// build page.....
echo '<html><body><a href="http://google.com/">Go to google!</a></body></html>';
$page_source = ob_get_clean();
$qs = array('cash' => '1831');

if(preg_match_all('@href="(.*?)"@i', $page_source, $links)) :
foreach($links[1] as $find) :
$replace = $find.((!strstr($find, '?'))? '?' : '&amp;').http_build_query($qs, '&amp;');
$page_source = str_replace($find, $replace, $page_source);
endforeach;
endif;

echo $page_source;

therichboy
05-19-2008, 04:07 PM
Hey. Thanks but I honestly did not understand how to use the code you gave.

What am I supposed to append to my links?
The querystring will be different each time someone visits the page since they will be coming from different sources, each querystring representing and individual affiliate...would this still work in this case, and if so can you explain what I should add to the links.

Secondly, am i supposed to put the entire page source after ECHO or after $page_source

Vege
05-19-2008, 06:20 PM
Are you looking for a way to pass parameters from page to page?
Have u considered sessions?
http://www.tizag.com/phpT/phpsessions.php

ptmuldoon
05-20-2008, 12:20 AM
can't you use $_GET to the cash variable?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum