Hello, is there a way to detect the off site requests a page make while loading. example: i have a site www.domain.com/abc.html is there a way to know if abc.html make requests to other sites while loading ... if i have images or videos etc embedded in my abc.html from other sites then definitely it will make requests to those sites... so my question is that is there a way to detect it ???
Try using the $_SERVER['HTTP_REFERER'] variable and see if that works properly. If it doesn't match $_SERVER['HTTP_HOST'] (in most cases your domain, if not will have to tweak the procedure a bit) then it's not coming from your site. Unfortunately, today I have to leave so don't have a lot of time to create examples, but if you need more help feel free to ask and I can write one up for you that's a little more complex. Here is a mockup (untested): <?php if(preg_match("/".$_SERVER['HTTP_HOST']."/",$_SERVER['HTTP_REFERER'])){ // Page stuff } else { exit(); } ?> PHP: Note, you will not be able to access this page directly unless you also set the condition if(preg_match()... AND $_SERVER['HTTP_REFERER'] == NULL){} The regular expression needs to be tweaked as well to make sure it's not SOMESITE.COM/YOURSITE_URL.COM to try to trick the system. But this should be a good starting point for you and/or anyone else who wants to help here on DP! Sorry I have to go and couldn't totally resolve your problem, but no one else is responding so I decided to take a look. Best of luck! Regards, Dennis M.
@Dennis M. thank you so much for sparing some time to write.. well, i couldn't get whole idea, i will write you more and specific details, might you can help me, Thanks
OK, i am precising my question more.. lets say... i have a page www.domain.com/abc.html i am using 3 images on this page from 3 different sites www.domain1.com/images/1.jpg www.domain2.com/images/2.jpg www.domain3.com/images/3.jpg then for sure while loading abc.html it will generate requests to domain1, domain2, domain3 to get images. i just want to know in a series that ... request sent to domain1 request sent to domain2 request sent to domain3 hopefully you can understand more
these requests are sent from browser and not from server. so this detection can either be done at browser level or at the hosting server level where image is kept.
Here is a sample javascript which can tell you when images are uploaded: <html> <body> <img id="img1" src="http://forums.digitalpoint.com/images/misc/dps_logo.gif"> <img id="img2" src="http://forums.digitalpoint.com/images/buttons/newthread.gif"> <img id="img3" src="http://forums.digitalpoint.com/images/buttons/reply.gif"> <div id='img_status'> </div> <script type="text/javascript"> document.onload = doImageLoadCheck; function doImageLoadCheck() { var img = document.getElementsByTagName('img'); for(var i = 0; i < img.length; i++) { img[i].onload = doImageLoadUpdate(img[i].id, img[i].src); } } function doImageLoadUpdate(id, src) { document.getElementById('img_status').innerHTML += '<br/>image ' + src + ' - (' + id + ') is loaded successfully.'; } </script> </body> </html> HTML:
@mastermunj Thank you so much and i really appreciate it... but that is specific for images, my question is to check that whether Request made to external domains OR not ... like in your example i want to check that whether requested made to forums.digitalpoint.com OR not... i think i am not good to make understand :-(
my friend, if image is loaded means request was sent and it is successfully completed. javascript can be modified to filter output from the list and give only images that are loaded from particular domain.
You are right, but my target is not to check with images only, i have to check it with text files too and some time have not to display the out put, that's why i am looking for only verifying request.... Thanks again
below is the modified code.. <html> <body> <img id="img1" src="http://forums.digitalpoint.com/images/misc/dps_logo.gif"> <img id="img2" src="http://forums.digitalpoint.com/images/buttons/newthread.gif"> <img id="img3" src="http://forums.digitalpoint.com/images/buttons/reply.gif"> <img id="img4" src="http://www.google.co.in/images/nav_logo7.png"> <div id='img_status'> </div> <script type="text/javascript"> document.onload = doImageLoadCheck; function doImageLoadCheck() { var img = document.getElementsByTagName('img'); for(var i = 0; i < img.length; i++) { if(img[i].src.indexOf('forums.digitalpoint.com') >= 0) img[i].onload = doImageLoadUpdate(img[i].id, img[i].src); } } function doImageLoadUpdate(id, src) { document.getElementById('img_status').innerHTML += '<br/>image ' + src + ' - (' + id + ') is loaded successfully.'; } </script> </body> </html> HTML:
well, only verifying requests seems tough job. never came across such scenario. do you have any practical use after knowing that image request was sent to some other domain?
yep, i am doing some kind of stats script, so wants to know that to what external domains it sends request