View Full Version : is there a html code..
Mario
07-01-2008, 04:27 PM
that makes it so when you refresh the page the code is on, a certain image changes into other images ive specified? +rep for code or alternatives.
MrCraig
07-01-2008, 05:21 PM
Like you have to refresh the page a few times to view the image..?
I made one a while ago..
<?php
ob_start();
session_start();
/*
CONFIG
*/
$message = "Sorry, This website is not currently open!"; #Message to show to users who havent refreshed.
$type = "cookie"; #Choose what method of storing refreshes you wish to use, Set to cookie to use cookies and session to use sessions
/*
DONT EDIT BELOW
*/
if($type=="cookie")
{
if($_COOKIE["refresh"]!=3)
{
if(isset($_COOKIE["refresh"]))
{
$ref_value = $_COOKIE["refresh"] + 1;
setcookie("refresh",$ref_value,time()+3600);
die("$message");
}
else
{
setcookie("refresh","1",time()+3600);
die("$message");
}
}
}
elseif($type=="session")
{
if($_SESSION["refresh"]!=3)
{
$_SESSION["refresh"] = $_SESSION["refresh"]+1;
die("$message");
}
}
else
die("No valid storing type specified!");
?>
Just add in your image after the code.
I think he means that the image changes each time you refresh.
Hypertext
08-01-2008, 03:25 AM
I think you mean refresh certain parts, umm put the image or w.e in an iframe and put a piece of code in the heading of whats redirected to the iframe of content refresh?
Please elaborate :)
If I was right in thinking that you want the image to change to another random image on each refresh, I've found two ways:
Random.php
<?php
$dir = '.';
$avatar_types[] = 'gif';
$avatar_types[] = 'jpg'; //add as many new image extensions as you want.
// DO NOT EDIT BELOW THIS LINE
$avatar = array_key_exists('avatar',$_GET)?$_GET['avatar']:'';
if ($avatar != '') {
$avatar = urldecode($avatar);
}
else {
$avatars = array();
$directory = opendir($dir);
while ($list = readdir($directory)) {
if ($list != '.' && $list != '..') {
$ext_check = explode('.',$list);
foreach ($avatar_types as $variable => $value) {
if (in_array($value,$ext_check) && !in_array($value,$avatars)) {
$avatars[] = $list;
}
}
}
}
closedir($directory);
$random = array_rand($avatars,1);
$avatar = $avatars[$random];
}
$file = fopen($dir.'/'.$avatar,'r');
$content = fread($file,filesize($dir.'/'.$avatar));
fclose($file);
die($content);
?>
And then call it by..
<img src="random.php" alt="" />
Or, a much simpler one, but it doesn't check if image exists
<?php
$file = rand(1, 20);
$file .= '.jpg';
echo '<img src="'.$file.'" >';
?>
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.