Random avatar PHP script

PookyBoy

Senior member
Aug 18, 2001
200
0
0
So I wrote this script that works fine in IE. But I notice with Firefox/Mozilla it doesn't always change the avatar everytime. It seems to only change after a while. I think it's caching the image or something? Any ideas?
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Well so long as each number has a different name then caching the image itself shouldn't be a problem. What exactly is your setup? Is the code above in a page that the browser expects to be an image? It's possible that this page itself (with the Location: header) are getting cached. In theory that shouldn't happen because php is pretty good about adding headers that specify with little doubt that they should never be cached. It's possible that the browser is ignoring the cache directions because it's an image instead of an html page.

What if you actually embedded the random picture url in the <img> tag instead?
 

PookyBoy

Senior member
Aug 18, 2001
200
0
0
The above code is in a file called avatar.php and I would use that for off-site avatar url link in phpbb forums. In Firefox/Mozilla even if I hit refresh, it'll still show the same image.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Hmm. If you look in the browser cache, what do you see for the file that is actually linked from the html page? And do you see any images called url_to_imagesXX.jpg?

Explain a little further: is avatar.php on the same server as the images? is it on the same server as phpbb? or are we talking about 3 different servers?

If avatar.php and the images are on the same server what you might try is actually returning the image from that page instead of redirecting the user to another url. I've never done this in php (only java) but you should be able to open up the image file and write it out to the response directly. It sort of reproduces what the webserver itself is supposed to do but it's sometimes necessary for dynamic images.

If avatar.php and phpbb are on the same server I'm not sure why you can't just hack the phpbb code and have a random url inserted directly into the html.

Personally, I'd fire up ethereal and examine the http requests to see what actually gets requested everytime.
 

PookyBoy

Senior member
Aug 18, 2001
200
0
0
The php board, avatar.php and the actual images are all located on different servers. I'm no expert so I don't really understand what you just said. Thanks for your replies.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Sh|t, that's tricky. Most of what I said does not apply any more. So you cannot hack the phpbb source code? It will just always go to your avatar.php for the image?

Well, yes, I would use ethereal and see what gets requested.

Another possibility (and I'm stretching here) is for avatar.php to retrieve the image itself and write it to the response. I don't know if php can also act as an http client (I know I could do it in java ).
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: PookyBoy
The php board, avatar.php and the actual images are all located on different servers. I'm no expert so I don't really understand what you just said. Thanks for your replies.

I think he is saying that it is caching the final location of the image instead of the locaiton of the script so the script isn't run when you visit the cache.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Originally posted by: amdfanboy
Originally posted by: PookyBoy
The php board, avatar.php and the actual images are all located on different servers. I'm no expert so I don't really understand what you just said. Thanks for your replies.

I think he is saying that it is caching the final location of the image instead of the locaiton of the script so the script isn't run when you visit the cache.

That makes sense. So it doesn't cache any pages but it does cache certain headers? Let's walk through that:

-browser gets html
-browser sees that it needs an image found at avatar.php
-browser inspects cache, does not have avatar.php cached, tries to retrieve avatar.php
-gets a redirection back from avatar.php and caches that redirection even though it is not supposed to cache avatar.php
-gets picture, goes on it's merry way

...next time...

-browser sees it needs an image found at avatar.php
-browser does not have avatar.php cached but does remember that it was redirected to a certain other url last time and goes there again...

That seems incorrect to me, but it is certainly a remote case.

PookyBoy, do you have the LiveHttpHeaders extension installed? If so, could you do the following:

-clear the browser cache
-bring up LiveHttpHeaders (pops up in left panel)
-request a single page that will contain an avatar, just as you normally would
-inspect the headers that have gone by
-see if you can find the request going out for avatar.php and the response coming back in
-post both
-repeat without clearing the cache first
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: kamper
Originally posted by: amdfanboy
Originally posted by: PookyBoy
The php board, avatar.php and the actual images are all located on different servers. I'm no expert so I don't really understand what you just said. Thanks for your replies.

I think he is saying that it is caching the final location of the image instead of the locaiton of the script so the script isn't run when you visit the cache.

That makes sense. So it doesn't cache any pages but it does cache certain headers? Let's walk through that:

-browser gets html
-browser sees that it needs an image found at avatar.php
-browser inspects cache, does not have avatar.php cached, tries to retrieve avatar.php
-gets a redirection back from avatar.php and caches that redirection even though it is not supposed to cache avatar.php
-gets picture, goes on it's merry way

...next time...

-browser sees it needs an image found at avatar.php
-browser does not have avatar.php cached but does remember that it was redirected to a certain other url last time and goes there again...

That seems incorrect to me, but it is certainly a remote case.

PookyBoy, do you have the LiveHttpHeaders extension installed? If so, could you do the following:

-clear the browser cache
-bring up LiveHttpHeaders (pops up in left panel)
-request a single page that will contain an avatar, just as you normally would
-inspect the headers that have gone by
-see if you can find the request going out for avatar.php and the response coming back in
-post both
-repeat without clearing the cache first

Let me change that. It probably just caches the place it got the image from and stores a copy on the HDD. Then it probably checks the last modifed date to see if it has changed. This script hasn't been modifed so it won't download it.

 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
The script meaning avatar.php? But it should never check the dates of avatar.php, it was told not to cache it so it shouldn't have it. If it sends a request for avatar.php with the If-not-modified-since: header (or whatever it's called) that header should be ignored and avatar.php should be run again because the php processor should know that the page is expected to chage every time. Or, maybe the web server sees that header and inspects the actual avatar.php file before passing control to the php processor? No, if that were the case php would never work properly...

D@mn you, PookyBoy, I'm trying to do homework here :|
 

PookyBoy

Senior member
Aug 18, 2001
200
0
0
This is what I got the first time. The second time, without clearing the cache, I couldn't find the request for the php script.
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: kamper
The script meaning avatar.php? But it should never check the dates of avatar.php, it was told not to cache it so it shouldn't have it. If it sends a request for avatar.php with the If-not-modified-since: header (or whatever it's called) that header should be ignored and avatar.php should be run again because the php processor should know that the page is expected to chage every time. Or, maybe the web server sees that header and inspects the actual avatar.php file before passing control to the php processor? No, if that were the case php would never work properly...

D@mn you, PookyBoy, I'm trying to do homework here :|

lol
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
So avatar.php is actually eriko.php? Just want to make sure

Ok, there's the problem. For some odd reason there are no cache control headers on the response there. Maybe php left them out because it assumed you didn't need them since you're using Location:

You can set them yourself, in the same manner as Location. Here's what you should set:

Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache

That's what a normal php page will return.
 

PookyBoy

Senior member
Aug 18, 2001
200
0
0
Ya it's eriko.php. So I changed it to this like you said. Is this correct? But it still does the same thing. Anyways I don't want to waste your time. It's not a big problem.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
That's what I'd do. And then I'd cross my fingers.

Don't worry about wasting my time. If it wasn't interesting I'd just be ignoring you and doing other stuff
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Originally posted by: amdfanboy
No one tried my script?


It looks pretty funky. Does that run under a default php installation or does it require those funky graphics libraries?

PookyBoy: how's it going? I'm curious to find out if that does it
 

PookyBoy

Senior member
Aug 18, 2001
200
0
0
Originally posted by: kamper
Originally posted by: amdfanboy
No one tried my script?


It looks pretty funky. Does that run under a default php installation or does it require those funky graphics libraries?

PookyBoy: how's it going? I'm curious to find out if that does it

I guess you missed my last reply. Unfortunately I implemented the changes you suggested but it's still the same.

I ended up using the imagerotator script from http://automaticlabs.com/products/rotator
It works good. The image changes even without manual refresh. The code is beyond me though.

Sorry amdfanboy, I didn't try your script now that I'm using that one.

Thank you guys.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Oops, I did see your last reply, just not the middle sentence Glad you got something working.

ps. did you reflush your cache before trying my idea?
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: kamper
Originally posted by: amdfanboy
No one tried my script?


It looks pretty funky. Does that run under a default php installation or does it require those funky graphics libraries?

PookyBoy: how's it going? I'm curious to find out if that does it

Should work after 4.1 I think. No extras needed.
 

PookyBoy

Senior member
Aug 18, 2001
200
0
0
Originally posted by: kamper
Oops, I did see your last reply, just not the middle sentence Glad you got something working.

ps. did you reflush your cache before trying my idea?

Yep I cleared the cache before trying the new script.
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
Originally posted by: PookyBoy
Originally posted by: kamper
Originally posted by: amdfanboy
No one tried my script?


It looks pretty funky. Does that run under a default php installation or does it require those funky graphics libraries?

PookyBoy: how's it going? I'm curious to find out if that does it

I guess you missed my last reply. Unfortunately I implemented the changes you suggested but it's still the same.

I ended up using the imagerotator script from http://automaticlabs.com/products/rotator
It works good. The image changes even without manual refresh. The code is beyond me though.

Sorry amdfanboy, I didn't try your script now that I'm using that one.

Thank you guys.

Yeah, it's a more advanced and revised version of what I posted.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |