 |
|
|
| View previous topic :: View next topic |
| Author |
Message |
mypointofview

Joined: 18 Mar 2005 Posts: 32 Location: Los Angeles
|
Posted: Sat Dec 30, 2006 7:19 pm Sequential image upon each reload (cycle vs. random) |
|
|
|
Is there a way to get a sequential (not random) new image upon each reaload ?
I have let's say 10 images. I want that the user upon first visit sees image 1, then when the visitor reloads the page, he'd see picture 2 and so forth. When seen image 10 he'd then see upon renewed reload image 1.
I tried a random script and the problem is that sometimes, especially when there are not so many images in the pile, that the same image shows the next time again. Like throwing a dice -- the liklyhood to have the same result twice exists
How can I achieve my task? I've checked everywhere -- is it even possible ??
Thanks,
Martin
PS: I want to simply make a website with a nice photo splashscreen that is guaranteed to be different with each visit. |
|
Thor Erik
Joined: 30 Dec 2006 Posts: 8
|
Posted: Sun Dec 31, 2006 5:39 am |
|
|
|
something like this may be something you like:
| Code: |
<?php
session_start();
// Use $HTTP_SESSION_VARS with PHP 4.0.6 or less
if (!isset($_SESSION['count'])) {
$_SESSION['count'] = 0;
} else {
$_SESSION['count']++;
echo '<img src="'.$_SESSION['count'].'.jpg" \>';
if ($_SESSION['count] == "10"
{
$_SESSION['count'] = 0;
}
}
?>
|
this was a example i found here:
http://no.php.net/manual/en/ref.session.php
it will use Sessions to know witch image to get, it's werry simple but it works
now all images will have to be named
1.jpg, 2.jpg up to 10.
when it reatch 10 it will reset $_SESSION['count'] to 0 |
|
mypointofview

Joined: 18 Mar 2005 Posts: 32 Location: Los Angeles
|
Posted: Sun Dec 31, 2006 5:37 pm |
|
|
|
Thanks Thor, this works basically -- I had to correct some spelling errors - see below. There are two problems though:
1. Upon first visit: page is blank
2. If the visitor visits once and comes back the next day and has his browser turned off in the meantime - he starts at zero again.
So, how can I (a) eliminate the "blank" with the first visit (I tried to set the zero in the code to 1 but this did not work) and how can I (b) get the visitor's browser to remember where he left off last time -- somehow use cookies perhaps ?
Your code:
| Code: |
<?php
session_start();
// Use $HTTP_SESSION_VARS with PHP 4.0.6 or less
if (!isset($_SESSION['count'])) { $_SESSION['count'] = 0; }
else {
$_SESSION['count']++;
echo '<img src="'.$_SESSION['count'].'.jpg">';
if ($_SESSION['count'] == "10") { $_SESSION['count'] = 0; }
}
?> |
All together:
| Code: |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Untitled</title>
</head>
<body>
test
<?php
session_start();
// Use $HTTP_SESSION_VARS with PHP 4.0.6 or less
if (!isset($_SESSION['count'])) { $_SESSION['count'] = 0; }
else {
$_SESSION['count']++;
echo '<img src="'.$_SESSION['count'].'.jpg">';
if ($_SESSION['count'] == "10") { $_SESSION['count'] = 0; }
}
?>
</body>
</html> |
PS: when reaching 10, then it indeed continues with 1 so this works  |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|
|
 |
|
|
|
|
|
|
|