PHP GET question - calling from a POST call
I have a quick question i hope you guys can answer, i've got a search system that uses POST to do searches, now i want to track queries using Google Analytics but it requires using GET url parameters to pull parameters out the URL开发者_开发知识库, what i don't want to do is rewrite the entire search system to use GET instead of POST. Is there any way around this? I was thinking maybe i can make a GET call to a new page from the page that recieves the search POSTs, but i don't want it to redirect, i merely want it to "hit" the url without actually redirecting?
Is this possible?
Any other solutions would also be appreciated.
Thanks for the help
You can specify an abritrary URL when you add your GA code. For example, all our different checkout pages go through validate.php, so this is the URL that the person would see, however, we put in some extra code to give a specific tracking URL to google.
For example:-
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-XXXXX-1");
pageTracker._setDomainName("example.com");
pageTracker._trackPageview("/checkout/login/");
} catch(err) {}
</script>
Would make google track this as being /checkout/login/
even though the page in the browser actually shows /validate.php
You can output (as we do) this page variable from different PHP variables
$searchterm = $_POST['search'];
echo 'pageTracker._trackPageview("/search/' . urlencode($searchterm) . '");';
Sure, use the apache mod_rewrite module to create a fancy, seo friendly url and pass the user keywords in the url.
Something like "www.yoursite.com/search/what+a+user+searches+for/"
In a .htaccess file you create a rule
RewriteRule ^search/(.*)/$ /search.php?keywords=$1
You're orignal script keeps working with your postvalues and you provide an URL with GET variables. With explode("+", $_GET["keywords"])
you can extract the searchvalues.
With the array $_REQUEST you can access all request parameters GET and POST.
The only way you will be able to do this, is re-set the forms method to GET and just changed the $_POST requests to $_GET
Thats not such a huge change?
You should be able to do that with HTTPRequest:
http://php.net/manual/en/class.httprequest.php
You can just alter your Google Analytics code - see Tracking Custom Variables
精彩评论