English 中文(简体)
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





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签