FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Display random image on foreign site





TomS
Hi.
Can anybody tell me how to display a random image in my signature eg.?

I mean like this: [img]http://domain.com/randomimage.php[/img]

I know how to select a random iamge from a lists of images, but not how to display it, by putting the phpcode in a img-tag....
LukeakaDanish
I'm not going to write yet another tutorial on making dynamic images (search google for that), but i will help you as follows:

.php files cant be displayed in a signature, so you will have to us a .png file.

You'll need to modify your .htaccess, so .png files (or whatever filetype your using), get parsed by the php engine.

STFG
TomS
LukeakaDanish wrote:
I'm not going to write yet another tutorial on making dynamic images (search google for that), but i will help you as follows:

.php files cant be displayed in a signature, so you will have to us a .png file.

You'll need to modify your .htaccess, so .png files (or whatever filetype your using), get parsed by the php engine.

STFG



If you wrote so many tutorials, why don't you give me a link? Would I have asked, if google gave me the answer? Normally this SE floods me with useless information. Thanks for the tip, though


EDIT: I did it. I really don't like mod_rewrite, because it never does, what I want (I'm too stupid for this). So I looked for a trick.

I have bbcode like this:
Code:
[img]http://domain.com/signature.jpg[/img]


In the root of my server there is a folder "signature.jpg" with an index.php in it. This index has the following code

Code:
<?php
header("Content-Type: image/jpg");
$rand = rand(1, 3);
readfile("bild".$rand.".jpg");
?>
LukeakaDanish
Have you tested that? - it looks like quite a cool method Smile

I havent written any tutorials - I'm just saying that a fair few (thousands and thousands) dynamic image tutorials excist Smile
TomS
Oh ok.



Look, how it works^^
LukeakaDanish
Lol...nice...did you notice the size when right-clicking ? 0 kb Very Happy
TomS
hehe. Folders have no size. Seems like a good way to protect pictures... Laughing

But all the folders you've got to create...
LukeakaDanish
It doesn't really protect them though - i could still save it Razz...but i spose you could prevent hot linking by adding some lines in your php script...

I'm definitely gonna use this for something at some point.
pspcoder05
Nice method dude.

I'll try to use that. Wink
TomS
This does not work, if you want a random avatar. If someone could try it with mod_rewrite and post if works then, it would be really nice. Thx
MrBlueSky
TomS wrote:


EDIT: I did it. I really don't like mod_rewrite, because it never does, what I want (I'm too stupid for this). So I looked for a trick.

I have bbcode like this:
Code:
[img]http://domain.com/signature.jpg[/img]


In the root of my server there is a folder "signature.jpg" with an index.php in it. This index has the following code

Code:
<?php
header("Content-Type: image/jpg");
$rand = rand(1, 3);
readfile("bild".$rand.".jpg");
?>


You can also do this:

1. Create a new empty directory (for example foo)

2. Create a file called ".htaccess" (don't forget the dot)

3. Put this line in .htaccess:

Code:

AddHandler application/x-httpd-php .php .jpg .png .gif


4. Copy your image-serving script (for example bar.php) to this directory and rename it with the extension of the image you want to serve

For example:
if it is an PNG-image: bar.png
or if it is an JPG image: bar.jpg

Now you can link your image by using the url, for example:
http://www.mysite.fri.com/foo/bar.png

You can put as many image-creating scripts in this directory as you want.
Related topics
IE8 not allowing new random image on each page (PHP and CSS)
question : how to display random image in main page?
Random Image
random image code?
I want to output an img url from a random image script
Image hosting site i use
Random Image Display
Random image for your gallery
Random Post on phpBB
Jamatus' Dynamic image store
PHP Image Questions
Layout Gap PRoblems with PHP/Javascript Combo
Problem placing footer
Having browser not pull files from the cache.
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.