That works fine only if the files are not in separate domains.
In separate domains means, location of track.php is http://www.example_1.com/track.php and location of index.php is http://www.example_2.com/index.php. Now you may ask, "why?, what is the problem, if the files are is in a separate domains? Can't we still send an AJAX request?". The answer is, if you send an AJAX request in this situation from index.php to track.php, the browser will raise a Security Exception and the AJAX request will fail, since you are making a cros domain request.
So what is the easiest way to get this done? The simplest solution is say the browser "you don't worry, http://www.example_1.com/track.php is an image, just load it". Confuced?? What we do is adding following HTML code to the index.php.
The poor browser doesn't know the source of image is a tracking page and it will load the image even if it is in a separate domain.So, you can track the page in example_2 domain, from example_1 domain. In addition, if you want to send additional data to the example_1 domain, just pass URL variables as follows.
<img src="http://www.example_1.com/track.php?clientIP=1921021253062" height=1 width=1/>
In both above cases it is better if you response with an actual image with white pixel. To do that you can use following PHP code.
- <?php
- // Create a blank image and add some text
- // Sets color to white
- // Set the content type header - in this case image/jpeg
- // Skip the filename parameter using NULL, then set the quality to 75%
- // Free up memory
- ?>
No comments:
Post a Comment