How to detect offsite requrest in page loading??

Discussion in 'PHP' started by eyes_drinker, Oct 23, 2009.

  1. #1
    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 ???
     
    eyes_drinker, Oct 23, 2009 IP
  2. Dennis M.

    Dennis M. Active Member

    Messages:
    119
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #2
    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., Oct 23, 2009 IP
  3. eyes_drinker

    eyes_drinker Member

    Messages:
    224
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #3
    @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
     
    eyes_drinker, Oct 23, 2009 IP
  4. eyes_drinker

    eyes_drinker Member

    Messages:
    224
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #4
    eyes_drinker, Oct 23, 2009 IP
  5. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #5
    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.
     
    mastermunj, Oct 23, 2009 IP
  6. eyes_drinker

    eyes_drinker Member

    Messages:
    224
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #6
    anyone knows how to detect from browser end ??
     
    eyes_drinker, Oct 23, 2009 IP
  7. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #7
    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, Oct 23, 2009 IP
  8. eyes_drinker

    eyes_drinker Member

    Messages:
    224
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #8
    @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 :-(
     
    eyes_drinker, Oct 23, 2009 IP
  9. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #9
    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.
     
    mastermunj, Oct 23, 2009 IP
  10. eyes_drinker

    eyes_drinker Member

    Messages:
    224
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #10
    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
     
    eyes_drinker, Oct 23, 2009 IP
  11. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #11
    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:
     
    mastermunj, Oct 23, 2009 IP
  12. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #12
    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?
     
    mastermunj, Oct 23, 2009 IP
  13. eyes_drinker

    eyes_drinker Member

    Messages:
    224
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #13
    yep, i am doing some kind of stats script, so wants to know that to what external domains it sends request
     
    eyes_drinker, Oct 23, 2009 IP