[Pro] Displaying a random image on a web pag

I would like to include a random image ad when a page is loaded. I have found the following code:

<?php /* * Name your images 1.jpg, 2.jpg etc. * * Add this line to your page where you want the images to * appear: <?php include "randomimage.php"; ?>

*/

// Change this to the total number of images in the folder
$total = “11”;

// Change to the type of files to use eg. .jpg or .gif
$file_type = “.jpg”;

// Change to the location of the folder containing the images
$image_folder = “images/random”;

// You do not need to edit below this line

$start = “1”;

$random = mt_rand($start, $total);

$image_name = $random . $file_type;

echo “$image_name”;

?>

I have added a markup item, included the code however I am only getting :
Parse error: syntax error, unexpected T_VARIABLE in /home/ictlinks/web/ICTLinks2010/index.php on line 424

http://www.ictlinks.co.uk/ICTLinks2010/

What have I missed?


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi,

The script has an invisible char (round blob or dot) on line 11. This
can happen when copying scripts from web pages, if you remove this
then the script should run without error.

To fix this you could remove the spaces (what look like spaces) after
the last line of the following code in the script by:

  1. Place the cursor about the distance of 3 or 4 letters after the */
    (You will see that the cursor enters the line a couple of spaces after
    the /).

  2. Press the delete key a couple of times until there is no space
    after the /

  3. Save the file and try again.

If you have BBEdit you could open the file and then select to ‘Show
invisibles’ and you will see the little sod, it shows as a round dot
about the size of an asterix

/*
* Name your images 1.jpg, 2.jpg etc.
*
* Add this line to your page where you want the images to
* appear: <?php include "randomimage.php"; ?>
*/

HTH

On Jun 21, 2010, at 12:53 AM, ictlinks wrote:

I would like to include a random image ad when a page is loaded. I
have found the following code:

<?php /* * Name your images 1.jpg, 2.jpg etc. * * Add this line to your page where you want the images to * appear: <?php include "randomimage.php"; ?>

*/

// Change this to the total number of images in the folder
$total = “11”;

// Change to the type of files to use eg. .jpg or .gif
$file_type = “.jpg”;

// Change to the location of the folder containing the images
$image_folder = “images/random”;

// You do not need to edit below this line

$start = “1”;

$random = mt_rand($start, $total);

$image_name = $random . $file_type;

echo “$image_name”;

?>

I have added a markup item, included the code however I am only
getting :
Parse error: syntax error, unexpected T_VARIABLE in /home/ictlinks/
web/ICTLinks2010/index.php on line 424

http://www.ictlinks.co.uk/ICTLinks2010/

What have I missed?


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

There is also the ‘Random Image’ action Random Image - ActionsForge which allows you to select from up to 25 images. Built for exactly this sort of scenario.

David


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thanks Mike and David

I have gone through the php script and still get the same error, even retyping it in espresso
however have also tried the random image action and works like a treat, so I think I will stick with this method for the moment.


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

even retyping it in espresso

The best place to type code is in a plain text editor like BBedit - making sure that it is formatted as plain text.

Anywhere else and you are running the risk of adding those weird characters that can screw things up.

But hey if the Random Image action does the job then you are sorted!

David


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Espresso is a VERY nice programmer’s editor, from the same whimsical
guy who brought the world CSSEdit (quite possibly the finest way to
make stylesheets).

Walter

On Jun 21, 2010, at 4:49 PM, DeltaDave wrote:

even retyping it in espresso

The best place to type code is in a plain text editor like BBedit -
making sure that it is formatted as plain text.


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Espresso is a VERY nice programmer’s editor…

Well you learn something new every day. I do have it but didn’t realise that it was more capable than I give it credit for.

I must dig into it deeper.

Thanks Walter

D


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi, Am I imagining it but did I read somewhere that the Random Image Action can be modified so that the an image does not appear two or maybe even three times in succession - as is the case in a true random selection?

Richard


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Random is random. The odds of one image appearing more than once in a session are the same as that image appearing only once in a session. If you truly want to control the number of times an image appears, then you can’t actually use purely random functions to get that. You have to use a session or some other local store to mark out which images have been seen by that visitor, and then make a random selection from the remainder, and then what do you do once the person has seen everything? Either that or you use the timed sequence Action and set up a specific path through the images on hand.

Walter


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Yes I understand that but maybe I wrote, as usual, poor English. It is not the number of times an image appears that I was looking to control. Essential in fact that in any one session, no matter how long, each image will continue to re-present itself at random.

What I am wondering is - is it possible prevent an image immediately appearing again at the next roll of the dice? So in a group of images labeled ABCDE I never get AA or BB or CC. Yep it’s not random but I am sure I saw a reference to this possibility somewhere but as yet have not landed on it. (Due to my somewhat random search methodology?)

Richard


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

You’re going to need to use a cookie or something like that to track
each user, and what they saw last. The issue is that HTTP (the
transport protocol for the Web) is “stateless”, which means that it
normally doesn’t know or care who asked for anything. Each request is
considered entirely on its own, without any regard for what came
before. Cookies are used to break this behavior, and to allow multiple
requests from the same browser to be considered as parts of a larger
whole, rather than random stabs in the dark, by either the browser
(using JavaScript) or the Web server (using a separate application
server process communicating with the Web server through the CGI
protocols).

When you request a page that contains some JavaScript to randomize a
feature, the script only knows the current request, and can only
figure out what a random number is between 1 and the number of images
in your array of possibilities, and return it – but nothing beyond
that.

So one way you could do this is to ask “does this person have a cookie
with an array of random items?” If no, create a new array of the
possible random items, shuffled, and store it in a cookie. If yes,
then take the first item from that array and remove it so it never
gets used again in that session and use it as the next image. When
they run out of items, such a system would naturally repeat from the
beginning.

There isn’t such a system in existence yet, but it could be written.
Perhaps someone on the Actions list has a moment to code something up?

Walter

On Nov 15, 2010, at 10:04 AM, Richard Lowther wrote:

Yes I understand that but maybe I wrote, as usual, poor English. It
is not the number of times an image appears that I was looking to
control. Essential in fact that in any one session, no matter how
long, each image will continue to re-present itself at random.

What I am wondering is - is it possible prevent an image
immediately appearing again at the next roll of the dice? So in a
group of images labeled ABCDE I never get AA or BB or CC. Yep it’s
not random but I am sure I saw a reference to this possibility
somewhere but as yet have not landed on it. (Due to my somewhat
random search methodology?)

Richard


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Wow! I was literally logging in to ask this exact question!

That big site I may be working on will need this “rotating ad” feature. The action will probably do the trick.

When selling ad space in this fashion, how do you tell the advertiser how much “click time” they get?

Bob


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

That would be impossible to tell, except as an average over a LOT of
page-views. The odds of seeing a particular ad would depend on the
number of possible ads, so if you take a significantly long view, each
ad of 5 in rotation would be seen 20% of the time.

But you can’t guarantee anything with a random display, and you can’t
guarantee that a person will stick around for the full 5 ads to show.
The math would get extremely fuzzy.

The current random image Action does permit a separate link per image,
so it’s pretty well suited for a banner ad on a very limited scale.
But there’s no way you are going to give an advertiser any sort of
odds that a particular ad will appear some number of times, or never
repeat.

Walter

On Nov 15, 2010, at 10:53 AM, Robert B wrote:

Wow! I was literally logging in to ask this exact question!

That big site I may be working on will need this “rotating ad”
feature. The action will probably do the trick.

When selling ad space in this fashion, how do you tell the
advertiser how much “click time” they get?

Bob


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

So, I guess to give the advertiser any idea of how long or often their ad appears, is to use a fancier script solution.

Bob


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Yes. A dedicated advertising management script or system (have a look on HotScripts et al.) would allow you to do all sorts of things – track the number of clicks each ad receives, use cookies to gather all sorts of useful stuff like who clicks on what combination of ads, make ads drop out of rotation after they’ve received the number of clicks the advertiser paid for, etc. There’s a whole lot of software out there to do this sort of thing, some of it free, some of it paid (and thus supported). I haven’t used any of it myself, so I can’t recommend anything specific.

Walter


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Well I finally tracked down my original reference to this in the Freeway5Reference.pdf. But it applies to the Random Rollover action and not the Random Image.

The Random Rollover Action is a variant of the Rollover Action, and allows
you to create a random rollover effect. ......................
Select the Next Image Different checkbox if you want to ensure that the
same rollover state is not displayed twice in succession (as can happen with a
strictly random order).

Is it not possible to add a ‘Select the Next Image Different’ checkbox to the Random Image Action?

Richard


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

This works in that Action because both the current image and the next
image (selected randomly) are both known to the page at the same time.
This Action is switching between a number of different images that are
all loaded into the page at the same time.

The regular Random Image action only loads one image, chosen at random
at the moment the page loads from a selection of different possible
images.

Each time a page loads, the slate is wiped clean, and so the random
image knows nothing of the one that came before it. Each random image
is random for the scope of the current page load only.

Walter

On Nov 15, 2010, at 12:38 PM, Richard Lowther wrote:

Well I finally tracked down my original reference to this in the
Freeway5Reference.pdf. But it applies to the Random Rollover action
and not the Random Image.

The Random Rollover Action is a variant of the Rollover Action, and  
allows
you to create a random rollover effect. ......................
Select the Next Image Different checkbox if you want to ensure that  
the
same rollover state is not displayed twice in succession (as can  
happen with a
strictly random order).

Is it not possible to add a ‘Select the Next Image Different’
checkbox to the Random Image Action?

Richard


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

OK - and Thanks for all your input Walter. Richard


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options