wu :: forums (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi)
riddles >> suggestions, help, and FAQ >> Grimbal's Personalized Picture
(Message started by: alien on Sep 27th, 2004, 3:57pm)

Title: Grimbal's Personalized Picture
Post by alien on Sep 27th, 2004, 3:57pm
Is Grimbal changing his personalized picture in his profile every time he connects to wu :: forums or is there another (automatic) way?

Title: Re: Grimbal's Personalized Picture
Post by Aryabhatta on Sep 27th, 2004, 8:34pm
You can specify an external link for your personalized picture.
Grimbal's is http://florian.net/pic/65x65/mypic.php?.gif

Question is, how does his script manage to return the same pic for a long topic to which he has posted many times? Maybe he is using cookies.

Anyway, hope that helps.

Title: Re: Grimbal's Personalized Picture
Post by THUDandBLUNDER on Sep 27th, 2004, 8:37pm

Quote:
Question is, how does his script manage to return the same pic for a long topic to which he has posted many times? Maybe he is using cookies.  



on 06/14/04 at 13:50:21, Grimbal wrote:
I change my mind all the time.  ;)

No, actually, I quickly got bored of any avatar I chose, so I wrote a script that brings back a random picture among those I collected.

A script-kiddie, huh?    ;)


Title: Re: Grimbal's Personalized Picture
Post by towr on Sep 28th, 2004, 4:08am

on 09/27/04 at 20:34:22, Aryabhatta wrote:
Question is, how does his script manage to return the same pic for a long topic to which he has posted many times? Maybe he is using cookies.
Or maybe your browser caches the image and uses it over and over instead of dowmloading the (from the browsers pov same) image again and again..
IF you can tell your browser to never cache images (or anything) it would probably be different more often, also inside topics.

Title: Re: Grimbal's Personalized Picture
Post by John_Gaughan on Sep 28th, 2004, 5:56am
I noticed this too. I did not check the image URL but I imagine it is  a script that picks an image at random (or by time, a new one every hour?) and writes it manually to the output stream with HTTP headers. At least that was what I was going to do but then I was too lazy to follow through with it ;D

Title: Re: Grimbal's Personalized Picture
Post by John_Gaughan on Sep 28th, 2004, 6:04am

on 09/27/04 at 20:34:22, Aryabhatta wrote:
Question is, how does his script manage to return the same pic for a long topic to which he has posted many times?

Possibly by checking the $SERVER['HTTP_REFERER'] PHP variable. When a web page has embedded objects such as images, flash animations, Java applets, et al, the browser requests those objects from the server using the web page's URL as the referrer. This forum has the thread ID and other information embedded in the URL, so parsing it out and serving a custom image is trivial.

It is quite possible to write a script that checks the "Referer" header and serves different images based on it. I have run into web sites that do this at the web server (not CGI) level to save on bandwidth: if the server does not like the referrer, it denies the image. Images can eat up bandwidth, and image leachers tend to do more harm than good.

Title: Re: Grimbal's Personalized Picture
Post by Aryabhatta on Sep 28th, 2004, 9:31am

Quote:
Or maybe your browser caches the image and uses it over and over instead of dowmloading the (from the browsers pov same) image again and again..
IF you can tell your browser to never cache images (or anything) it would probably be different more often, also inside topics.


I don't think most broswers would cache links which refer to scripts, though I am not sure.


on 09/28/04 at 06:04:30, John_Gaughan wrote:
Possibly by checking the $SERVER['HTTP_REFERER'] PHP variable. When a web page has embedded objects such as images, flash animations, Java applets, et al, the browser requests those objects from the server using the web page's URL as the referrer. This forum has the thread ID and other information embedded in the URL, so parsing it out and serving a custom image is trivial.

It is quite possible to write a script that checks the "Referer" header and serves different images based on it. I have run into web sites that do this at the web server (not CGI) level to save on bandwidth: if the server does not like the referrer, it denies the image. Images can eat up bandwidth, and image leachers tend to do more harm than good.


Yes, that is a possibilty. There might be one problem with this though. If I immediately refresh the page for the discussion of a thread, the images change. How does the script figure out the difference?


It might be a good puzzle to try and figure out what actually the script is doing. We can all try to provide evidence/proof as to what is going on, other can try to refute/support it and Grimbal (if he will be so kind) can then say what the script is actually doing (or provide hints).

Title: Re: Grimbal's Personalized Picture
Post by Sir Col on Sep 28th, 2004, 10:41am
Give or take a bit, my guess...


Code:
$dirname="<path>";
$i=0;
$dh=opendir($dirname);
while ($f=readdir($dh)) {
     if (strstr($f,".gif")) {
           $a[$i]=$f;
           $i++;
     }
}
closedir($dh);
$rn=time()%$i;
print "<img src='$dirname/$a[$rn]' alt='' /><br />";

Title: Re: Grimbal's Personalized Picture
Post by Sir Col on Sep 28th, 2004, 11:15am
Okay, I abandon that theory. The following script (which waits 1 second between obtaining the next image) produces ten identical images:


Code:
for($j=1;$j<=10;$j++) {
     print "Testing $j<br />";
     print "<img src='http://florian.net/pic/65x65/mypic.php' alt='' /><br />";
     sleep(1);
}

Title: Re: Grimbal's Personalized Picture
Post by towr on Sep 28th, 2004, 12:42pm

on 09/28/04 at 09:31:07, Aryabhatta wrote:
I don't think most broswers would cache links which refer to scripts, though I am not sure.
Oh, but they do.. Espescially IE. Besides, the url is written thusly that most browsers won't readily recognize it as a script. (They recognize it as an image file with extention .gif)
To avoid caching you need to use some four ways to dissuade the various browsers from caching it using http headers:

Code:
<?php
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

// always modified
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");

// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);

// HTTP/1.0
header("Pragma: no-cache");
?>

Title: Re: Grimbal's Personalized Picture
Post by towr on Sep 28th, 2004, 12:49pm
Try this (http://tcw2.ppsw.rug.nl/~towr/PHP/html.php?html=%3Cimg+src%3Dhttp%3A%2F%2Fflorian.net%2Fpic%2F65x65%2Fmypic.php%3F.gif%3E%0D%0A%3Cimg+src%3Dhttp%3A%2F%2Fflorian.net%2Fpic%2F65x65%2Fmypic.php%3F.gif%3E%0D%0A%3Cimg+src%3Dhttp%3A%2F%2Fflorian.net%2Fpic%2F65x65%2Fmypic.php%3F.gif%3E%0D%0A%3Cimg+src%3Dhttp%3A%2F%2Fflorian.net%2Fpic%2F65x65%2Fmypic.php%3F.gif%3E%0D%0A%3Cimg+src%3Dhttp%3A%2F%2Fflorian.net%2Fpic%2F65x65%2Fmypic.php%3F.gif%3E%0D%0A%3Cimg+src%3Dhttp%3A%2F%2Fflorian.net%2Fpic%2F65x65%2Fmypic.php%3F.gif%3E%0D%0A%3Cimg+src%3Dhttp%3A%2F%2Fflorian.net%2Fpic%2F65x65%2Fmypic.php%3F.gif%3E) in various browsers. In IE it gives me the same picture 7 times, in NS4.7 it gives me different ones, in firebird and opera again the same ones.
Of course you can change options of your browser as well, with varying results..

Title: Re: Grimbal's Personalized Picture
Post by Aryabhatta on Sep 28th, 2004, 12:59pm

on 09/28/04 at 12:49:40, towr wrote:
Try this (http://tcw2.ppsw.rug.nl/~towr/PHP/html.php?html=%3Cimg+src%3Dhttp%3A%2F%2Fflorian.net%2Fpic%2F65x65%2Fmypic.php%3F.gif%3E%0D%0A%3Cimg+src%3Dhttp%3A%2F%2Fflorian.net%2Fpic%2F65x65%2Fmypic.php%3F.gif%3E%0D%0A%3Cimg+src%3Dhttp%3A%2F%2Fflorian.net%2Fpic%2F65x65%2Fmypic.php%3F.gif%3E%0D%0A%3Cimg+src%3Dhttp%3A%2F%2Fflorian.net%2Fpic%2F65x65%2Fmypic.php%3F.gif%3E%0D%0A%3Cimg+src%3Dhttp%3A%2F%2Fflorian.net%2Fpic%2F65x65%2Fmypic.php%3F.gif%3E%0D%0A%3Cimg+src%3Dhttp%3A%2F%2Fflorian.net%2Fpic%2F65x65%2Fmypic.php%3F.gif%3E%0D%0A%3Cimg+src%3Dhttp%3A%2F%2Fflorian.net%2Fpic%2F65x65%2Fmypic.php%3F.gif%3E) in various browsers. In IE it gives me the same picture 7 times, in NS4.7 it gives me different ones, in firebird and opera again the same ones.
Of course you can change options of your browser as well, with varying results..


Yes. I tried it with netscape with caching disabled and I got 7 different pics. This link (http://tcw2.ppsw.rug.nl/~towr/PHP/html.php?html=%3Cimg+src%3Dhttp%3A%2F%2Fflorian.net%2Fpic%2F65x65%2Fmypic.php%3F7%3E%0D%0A%3Cimg+src%3Dhttp%3A%2F%2Fflorian.net%2Fpic%2F65x65%2Fmypic.php%3F.6%3E%0D%0A%3Cimg+src%3Dhttp%3A%2F%2Fflorian.net%2Fpic%2F65x65%2Fmypic.php%3F5%3E%0D%0A%3Cimg+src%3Dhttp%3A%2F%2Fflorian.net%2Fpic%2F65x65%2Fmypic.php%3F4%3E%0D%0A%3Cimg+src%3Dhttp%3A%2F%2Fflorian.net%2Fpic%2F65x65%2Fmypic.php%3F3f%3E%0D%0A%3Cimg+src%3Dhttp%3A%2F%2Fflorian.net%2Fpic%2F65x65%2Fmypic.php%3F2%3E%0D%0A%3Cimg+src%3Dhttp%3A%2F%2Fflorian.net%2Fpic%2F65x65%2Fmypic.php%3F1%3E) gives 7 (maybe less) different pics in IE (depending on the random generator used)

It is the same as what towr gave, but .gif replaced by 7,6,5,4,3,2,1.

Title: Re: Grimbal's Personalized Picture
Post by Grimbal on Sep 28th, 2004, 2:25pm
I don't think I am a script kiddie, at least not as per this definition.
   http://www.webopedia.com/TERM/S/script_kiddie.html
I wrote the script *myself*.

Sir Col's code won't work, because the URL must return a gif file, and not a piece of HTML that links to a gif file.

I did not use REFERRER, because I don't care what picture shows where.  I would have to use it if I wanted to use one picture per forum, but always the same picture within a forum.  In my case, I just return any picture.

In fact, how often it changes is just a matter of how often your browser thinks it needs to reload the image.  Usually, if the same image is used multiple times on a page, the browser will load it once and display it so many times.

Anyway, here is the code.  It selects a random image file in the current directory, declares the returned data type as .gif format, and copy the binary file contents to the output.  To the caller, (the browser), it exactly as if it retrieved a static .gif file.


Code:
<?php

$files = array();
$i = 0;

$dh = opendir("./");
while( ($file = readdir ($dh)) ){
     if( substr($file,-4)==".gif" ){
           $files[$i++] = $file;
     }
}
closedir($dh);

$i = rand(0,count($files)-1);
$file = $files[$i];
header('Content-type:image/gif');
$pic = file_get_contents($file);
echo $pic;
exit;
?>

Title: Re: Grimbal's Personalized Picture
Post by Marcello Toskana on Nov 5th, 2005, 1:44am
Awesome!
Thanks for the code I will now try to implement it. Looked a little complicated..

Greetz from Europe,

Marcello Toskana (http://www.casamundo.de/ferienhaus_italien/toskana/)



Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright © 2000-2004 Yet another Bulletin Board