Command To Stop downloading images

Discussion in 'PHP' started by GARANTI, Oct 27, 2008.

?

Can i find a command in php to stop image downloading before the page loaded ?

  1. Yes

    1 vote(s)
    50.0%
  2. No

    1 vote(s)
    50.0%
  1. #1
    Hi, dear friends
    I need a command to stop downloading all my document images.

    for example: If a=1 then {don't download all images of the document}

    How can i find the command for stop downloading all images ?

    Thank you
     
    GARANTI, Oct 27, 2008 IP
    keyaa likes this.
  2. keyaa

    keyaa Peon

    Messages:
    137
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #2
    No, there's no "command" to do this. If your PHP pipes out html containing img tags, the client's browser most likely will request these images.

    You could do several things:

    1. prevent the server / your PHP script from returning img tags.
    For this to work, you should call a custom function to render you img tags. Instead of using
    <img src="myfile.jpg" width="100" height="200" alt="alt text" />
    Code (markup):
    , from now on write this:
    <?php html_img("myfile.jpg", 100, 200, "alt text"); ?>
    Code (markup):
    , the corresponding function could look like this:
    function html_img($url, $width, $height, $alt) {
      global $show_img;
      if($show_img) {
        echo '<img src="'.$url.'" width="'.$width.'" height="'.$height.'" alt="'.$alt.'" />';
      }
    }
    PHP:
    before using it, you should set $show_img to true or false (<?php $show_img = true; ?>)

    2. "Stop" the images via PHP/CSS.
    This is a bit hacky. Put this in your <head> tag:
    <?php
      if(!$show_img) {
        echo '<style type="text/css">img{display:none;visibility:hidden;}</style>';
      }
    ?>
    PHP:
    like before, set $show_img to either true or false before using it.

    3. "Stop" the images via PHP/JavaScript.
    Messiest way I can think of right now, won't even go into the gory details, would be writing out JavaScript code that either applies the CSS or removes the img elements from your pages DOM tree... BUT it has the nice plus of being able to "stop" loading of further img's "on the fly" in case your webapp uses flush() alot

    Out of curiosity, why do you need this?
     
    keyaa, Oct 27, 2008 IP
  3. GARANTI

    GARANTI Peon

    Messages:
    75
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    very thank you dear keyaa. i used it on my website.
    i needed it for my website >>> YMG.IR

    I hide an iframe into it linked to my 2nd website: www.abzarha.com.
    I wanted to up it's ranking but without loading it's images.

    Thank you again for your help
     
    GARANTI, Oct 28, 2008 IP
  4. keyaa

    keyaa Peon

    Messages:
    137
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Ah, I see, nice idea. Does that actually work, does the ranking increase?

    I just looked at your sites and see that your iframe points to "http://www.abzarha.com/index.php?ni=1". I suppose "ni" is your "no images" variable? ;) However, you're not upping "http://www.abzarha.com/" but ".../index.php?ni=1". Here's an idea:

    - don't point your iframe to "../index.php?ni=1", just point it to "http://www.abzarha.com/". Now, perform this check to see if the referer was your ymg.ir site - if it was, disable the images:

    <?php 
    if(strstr($_SERVER['HTTP_REFERER'], 'ymg.ir')) {
      $show_img = false;
    }
    ?>
    PHP:
    Also, you may also want to disable background images to further decrease the load. Updated code:
    <?php
      if(!$show_img) {
        echo '<style type="text/css">img{display:none;visibility:hidden;}*{background:none;}</style>';
      }
    ?>
    PHP:
    enjoy :)
     
    keyaa, Oct 28, 2008 IP
  5. GARANTI

    GARANTI Peon

    Messages:
    75
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    wow, very good dear keyya. i'll change it :)
    do you have information about cURL function in php ?
    I have a little problem on it.
     
    GARANTI, Oct 28, 2008 IP
  6. keyaa

    keyaa Peon

    Messages:
    137
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You're welcome.
    Yeah, I've worked with cURL/libcurl. Maybe I can help - although my production server is restoring RAID disks at the moment and I can't access my code. Well, nothing better to do, though, go ahead.. :D
     
    keyaa, Oct 28, 2008 IP
  7. GARANTI

    GARANTI Peon

    Messages:
    75
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thank you :)

    i bought a code for yahoo invisible checker and designed it for www.ymg.ir

    but i think there is a technical problem on my code about cURL.
    i designed a chart about my question because my english is not very well :(
    please open the picture i attached. and my codes are as follows:

    
    
    <?
    function cURL($url, $header, $cookie, $p)
    {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, $header);
    //curl_setopt($ch, CURLOPT_NOBODY, $header);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    //curl_setopt($ch, CURLOPT_COOKIE, $cookie);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt($ch,CURLOPT_REFERER,"http://test.com/");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    if ($p) {
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $p);
    }
    ;
    $result = curl_exec($ch);
    curl_close($ch);
    if ($result) {
    return $result;
    } else {
    return curl_error($ch);
    }
    ;
    }
    ;
    set_time_limit(0);
    $uid = $_POST['yid'];
    $souvik = cURL("http://test.com/status.php?yahooid=".$uid, null, null, 0);
    //echo $souvik;
    $avartar= "http://test.com/avatar.php?yids=".$uid;
    
    $lol1 = explode("<b>",$souvik);
    $lol2 = explode("</b>",$lol1[1]);
    $status = $lol2[0];
    $statusimg = "";
    if ($status == "offline") 
    $statusimg = "img/ofline.gif";
    else if ($status == "INVISIBLE")
    $statusimg = "img/invisible.gif";
    else if ($status == "online")
    $statusimg = "img/online.gif";
    else
    $statusimg = "img/lol.png";
    if($uid == "")
    {
    ?>
    
    
    Code (markup):
    please see the attached photo for more details about the problem

    Thank you :rolleyes:
     

    Attached Files:

    GARANTI, Oct 28, 2008 IP
  8. keyaa

    keyaa Peon

    Messages:
    137
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Wait.. so you just paid for the above code, and the actual invisibility checker is hosted elsewhere, somewhere you don't have access to?
     
    keyaa, Oct 28, 2008 IP
  9. keyaa

    keyaa Peon

    Messages:
    137
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #9
    The server's behaviour your image is describing seems to have nothing to do with your code, I don't see how you can work around the ddos protection if you don't have access to that server and only few IPs available.
     
    keyaa, Oct 28, 2008 IP
  10. GARANTI

    GARANTI Peon

    Messages:
    75
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    No, i have complete source of it. but i replaced the site addressed with (test.com) for security.

    Before i asked about this problem from the seller and he said:

    To redirect visitors ip to cURL command (and source site) i have to change the code to:

    
    
    curl_setopt($ch, CURLOPT_INTERFACE, $_SERVER["REMOTE_ADDR"])
    
    
    Code (markup):
    he said cURL is able to connect to an address with specifying visitor ip like above.
    but i tested on my code and finally i didn't get any good repond. because the above code didn't work :(

    how can we change cURL command for connecting to a website with visitors ip ?
    Do you know ?
     
    GARANTI, Oct 28, 2008 IP
  11. keyaa

    keyaa Peon

    Messages:
    137
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #11
    You mean IP spoofing? AFAIK not possible nowadays if you want any data to be returned to you.

    To be honest, I don't understand your full architecture and how exactly your code works. My guess is if the real invisibility-checker-script resides on your server, change/disable the ddos protection and you're good to go
     
    keyaa, Oct 28, 2008 IP
  12. GARANTI

    GARANTI Peon

    Messages:
    75
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #12
    No, i don't need ddos protection. the source website that i get info. from my site. mybe have ddos protection. but i wanted to know can i use cURL request with my website visitors ip ?

    because (the source site:secret site) will block my site access if my hosting ip have more >> retries per minute to it. (it thinks i'm a ddos attacker, if my curl do more pings with only 1 ip(my hosting ip) )
     
    GARANTI, Oct 28, 2008 IP
  13. keyaa

    keyaa Peon

    Messages:
    137
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #13
    So the source site/secret site is not your site?
     
    keyaa, Oct 28, 2008 IP
  14. GARANTI

    GARANTI Peon

    Messages:
    75
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #14
    I sent you, complete code of it as a private message to you.
    Thank you for your help and your time :)
     
    GARANTI, Oct 28, 2008 IP