SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    Ex-SitePointer silver trophy
    Patrick's Avatar
    Join Date
    Oct 2000
    Location
    Harbinger, NC, U.S.A.
    Posts
    4,126
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Images Accessed Directly Sent to a Page with Image on It

    Hello,

    I'm not exactly sure how to word this, but what I want is to install something on my server that makes it that when people access an image directly (.gif, .jpg) on my server, they are redirected to a page with that image on it, but with an ad above the image and a counter code below it. I recall seeing something like this before where it was automatic. You could link people directly to images and it automatically served these sort of pages...

    If anyone knows how that might be accomplished or what they are called or whatever, I'd appreciate any input.

    Thanks.

    Patrick

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    Apache

    Couldn't this be done with Apache? Something like
    HTTP direct request for image
    regex portions sent to "image display.php?img=regex_portion"
    display.php shows page with the "pulled" image in it (and other stuff).

  3. #3
    SitePoint Wizard masm50's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    2,508
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I would like to know this as well - could be very useful

    Tim

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    Apache and images

    I came across this other SP thread today. The technique involves having Apache have PHP parse php files with the png extension. The "png.php" file uses REQUEST_URI to get the original file name.
    http://www.sitepoint.com/forums/showthread.php?t=418260

  5. #5
    Ex-SitePointer silver trophy
    Patrick's Avatar
    Join Date
    Oct 2000
    Location
    Harbinger, NC, U.S.A.
    Posts
    4,126
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the replies.

    I appreciate the info, Mittineague. That stuff may be a bit over my head, though.

    As an aside, I just moved from West Springfield.

  6. #6
    SitePoint Wizard masm50's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    2,508
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Same location, same post count (almost) - I think one of you two is superman

    Tim

  7. #7
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    6 degrees ?

    Off Topic:

    Any relation to S O'Keefe that work(ed|s) at BMC, and married S ?

  8. #8
    Ex-SitePointer silver trophy
    Patrick's Avatar
    Join Date
    Oct 2000
    Location
    Harbinger, NC, U.S.A.
    Posts
    4,126
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    lol, masm50. That is funny. At the moment of posting, we have the exact post count.

    Anyway, no relation that I know of, sorry.

  9. #9
    Ex-SitePointer silver trophy
    Patrick's Avatar
    Join Date
    Oct 2000
    Location
    Harbinger, NC, U.S.A.
    Posts
    4,126
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I just thought I'd bring this up once to see if anyone who knows of something ready to go might have missed it. Thanks.

  10. #10
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    direct access

    I just finished something somewhat similar for some cheesy mid files I put back online. More for hot-link protection than for serving additional content, but maybe you could adapt it to your goal.
    In the page that has the links to the files
    Code:
    session_start
    if isset session
      check db for match 
      if not within acceptable time frame - unset
    if not set
      set session
      enter info into db
    In htaccess (note* not usiing add-type)
    Code:
    RewriteEngine on
    Options +FollowSymlinks
    RewriteBase /
    RewriteRule ^(regex_here)\.mid$ $1/file_name_here.php
    In the file that's redirected to
    Code:
    session_start
      if issest session
      preg_match session or unset
      check db for match and acceptable time or unset
    if isset session
     - use $_SERVER["REQUEST_URI"] to get name of file
     - serve with header("Content-Type: audio/mid");
    if not isset (here's where to get inventive, what I did is:)
     - serve random mid file instead of requested file
    I think for a redirect you would need to serve the php file as javascript with a location=new_page. You could have that page be a dynamically generated one that has the requested image in it, so the image would be in a page, not by itself.
    I don't think you could just use only htaccess to redirect to the new page directly, (not that it can't be done) eg. if someone has a page with
    <img src='your_img ...
    sending back a page wouldn't go into the tag's src
    Alternatives might be creating a new image with the requested image in it, or water-marking.

  11. #11
    Ex-SitePointer silver trophy
    Patrick's Avatar
    Join Date
    Oct 2000
    Location
    Harbinger, NC, U.S.A.
    Posts
    4,126
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Thanks for that.

    I'm really looking for something seamless. I don't have to make a change to any existing files, etc. (unless it's .htaccess, etc.). Just something I set into place easily and then it works on all of my images if accessed directly. I don't really have any programming knowledge.

  12. #12
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    htaccess

    I did a bit of experimenting. I couldn't get javascript to go to an img src (as js), just a broken link. So it may be that the add-type directive would be needed for that (but more likely not possible).
    You could just add a rewrite for links to image files. It would result in "broken" image boxes in any page that's hot-linking. But if the image was linked to as an anchor tag URL or requested by the URL in the browser's address bar. htaccess could redirect to the page instead of the image.
    Try adding this to your htaccess file (the top 3 lines may already be declared, if so, you won't need to add them again.)
    Code:
    RewriteEngine on
    Options +FollowSymlinks
    RewriteBase /
    RewriteRule ^test_img.jpg$ file_name_here.php
    file_name_here.php
    PHP Code:
    <html>
    <head>
    </head>
    <body>
    <p>just some text on the page for testing purposes.</p>
    <?php
    $request_uri 
    $_SERVER["REQUEST_URI"];
    if(
    stripos($request_uri,".jpg"))/*you don't want to show just any file!*/
    {
    echo 
    "<img src='" $request_uri "' \>";
    }
    ?>
    </body>
    </html>
    Then put a "test_img.jpg" online and make a direct HTTP request for it. You should end up at file_name_here.php
    The tricky part will be writing a good RewriteCond
    You don't want links from your pages being redirected.
    Referer can't be relied upon for 100% as some browsers don't send referer headers. Although maybe some would be good enough for you. But maybe if your images are 2 deep and relatively linked you could test for full path requests? (I don't know if this would work. Does Apache "add" full path to relative path requests?) eg
    Code:
    RewriteCond /secondary_folder/image.gif [NC]
    would catch requests for http://www.domain.com/secondary_folder/image.gif
    but not relative path requests for
    ./image.gif


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •