By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,442 Members | 1,327 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,442 IT Pros & Developers. It's quick & easy.

force users to different pages?

P: n/a
Hello

Say I have a welcome page and 2 other pages, a.htm and b.htm.

How can I guide visitors, alternately to a and to b?

Cheers

Geoff
Mar 21 '08 #1
Share this Question
Share on Google+
11 Replies


P: n/a
Geoff Cox wrote:
Hello

Say I have a welcome page and 2 other pages, a.htm and b.htm.

How can I guide visitors, alternately to a and to b?
Put a gun to their head?

Not enough information, and not sure it is a good idea.

Do you mean alternated links from one visitor to the next? if so that
would require recording the which link was last presented on the server.

Or do you mean alternate for a single visitor upon subsequent visits?
That would require a persistent cookie.

A much simpler method would be a link randomizer.

<?php

$links = array('a.html','b.html','c.html','d.html');
$last=count($links)-1;
$link=$links[rand(0,$last)];

echo "<a href=\"$link\">Mystery Tour</a>";

?>

--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
Mar 21 '08 #2

P: n/a
On Fri, 21 Mar 2008 09:40:41 -0400, "Jonathan N. Little"
<lw*****@central.netwrote:
>A much simpler method would be a link randomizer.

<?php

$links = array('a.html','b.html','c.html','d.html');
$last=count($links)-1;
$link=$links[rand(0,$last)];

echo "<a href=\"$link\">Mystery Tour</a>";

?>
Thanks Joanathan,

when I use the above I get

Mystery Tour"; ?>

I must be missing something?

Cheers

Geoff

Mar 21 '08 #3

P: n/a
Geoff Cox wrote:
On Fri, 21 Mar 2008 09:40:41 -0400, "Jonathan N. Little"
<lw*****@central.netwrote:
>A much simpler method would be a link randomizer.

<?php

$links = array('a.html','b.html','c.html','d.html');
$last=count($links)-1;
$link=$links[rand(0,$last)];

echo "<a href=\"$link\">Mystery Tour</a>";

?>

Thanks Joanathan,

when I use the above I get

Mystery Tour"; ?>

I must be missing something?
1) your server must support php

2) the page is named with a ".php" extension (normally for most server
setups)

3) attention to the escaped quotes

echo "<a href=\"$link\">Mystery Tour</a>";
^ ^
or concatenate with single quotes

echo '<a href="' . $link . '">Mystery Tour</a>';

--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
Mar 21 '08 #4

P: n/a
On Fri, 21 Mar 2008 13:12:49 -0400, "Jonathan N. Little"
<lw*****@central.netwrote:
>The reason for the 2 pages is that this web site will have some music
related exercises and we wish to have a kind of control group etc.

And what will happen if the visitor has JavaScript disabled?
Much of the site will require javascript so if javascript disabled
these people will not be able to use the site ........... it is for a
short duration project.

The javascript (soundManager which uses flash) is used to play mp3
files and also for AJAX MySQL connection. I think I could use flash ro
create the sound items but I do not have Adobe Flash software.

Cheers

Geoff
>The server side solution means it doesn't matter.

Mar 21 '08 #5

P: n/a
..oO(Jonathan N. Little)
>3) attention to the escaped quotes

echo "<a href=\"$link\">Mystery Tour</a>";
^ ^
or concatenate with single quotes

echo '<a href="' . $link . '">Mystery Tour</a>';
Or simply

echo "<a href='$link'>Mystery Tour</a>";

HTML also allows single quotes, which avoids both the ugly escaping and
concatenations in the script.

Micha
Mar 21 '08 #6

P: n/a
On 2008-03-21, Jonathan N. Little wrote:
Geoff Cox wrote:
>On Fri, 21 Mar 2008 09:40:41 -0400, "Jonathan N. Little"
<lw*****@central.netwrote:
>>A much simpler method would be a link randomizer.

<?php

$links = array('a.html','b.html','c.html','d.html');
$last=count($links)-1;
$link=$links[rand(0,$last)];

echo "<a href=\"$link\">Mystery Tour</a>";

?>

Thanks Joanathan,

when I use the above I get

Mystery Tour"; ?>

I must be missing something?

1) your server must support php

2) the page is named with a ".php" extension (normally for most server
setups)

3) attention to the escaped quotes

echo "<a href=\"$link\">Mystery Tour</a>";
^ ^
or concatenate with single quotes

echo '<a href="' . $link . '">Mystery Tour</a>';
Or use the safer and more portable printf instead of the
deprecated echo:

printf '<a href="%s">Mystery Tour</a>\n' "$link"

--
Chris F.A. Johnson <http://cfaj.freeshell.org>
================================================== =================
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
Mar 21 '08 #7

P: n/a
..oO(Chris F.A. Johnson)
Or use the safer and more portable printf instead of the
deprecated echo:
Deprecated? Safer? More portable? What are you talking about?

The only thing is that (s)printf() is much more flexible if you want to
embed multiple variables or complex expressions in a string. That's it.
For everything else print and echo are perfectly fine.
>printf '<a href="%s">Mystery Tour</a>\n' "$link"
For PHP you just have to add some (),; and please remove the quotes
around the $link variable - quoting a single variable is just stupid.

Micha
Mar 21 '08 #8

P: n/a
On Fri, 21 Mar 2008 21:02:41 +0000, "Chris F.A. Johnson"
<cf********@gmail.comwrote:
Or use the safer and more portable printf instead of the
deprecated echo:

printf '<a href="%s">Mystery Tour</a>\n' "$link"
Chris,

I couldn't get above to work so after trying various combinations the
following is OK.

printf("<a href='%s'>Mystery Tour</a>",$link);

Seem OK to you?

Cheers

Geoff
Mar 21 '08 #9

P: n/a
On 2008-03-21, Michael Fesser wrote:
.oO(Chris F.A. Johnson)
> Or use the safer and more portable printf instead of the
deprecated echo:

Deprecated? Safer? More portable? What are you talking about?
I was talking about something completely different. My apologies;
please ignore my post.

--
Chris F.A. Johnson <http://cfaj.freeshell.org>
================================================== =================
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
Mar 21 '08 #10

P: n/a
Michael Fesser wrote:
.oO(Chris F.A. Johnson)
>>printf '<a href="%s">Mystery Tour</a>\n' "$link"

please remove the quotes
around the $link variable - quoting a single variable is just stupid.
Aren't the quotes around the $link variable part of the <acode, i.e.
for quoting the href attribute value?

--
Berg
Mar 21 '08 #11

P: n/a
..oO(Bergamot)
>Michael Fesser wrote:
>.oO(Chris F.A. Johnson)
>>>printf '<a href="%s">Mystery Tour</a>\n' "$link"

please remove the quotes
around the $link variable - quoting a single variable is just stupid.

Aren't the quotes around the $link variable part of the <acode, i.e.
for quoting the href attribute value?
No. The same in PHP would be

printf('<a href="%s">Mystery Tour</a>\n', "$link");

The quotes for the href attribute are already in the first parameter,
the format string. The second parameter is just the value for the %s
placeholder. For PHP "$link" is a double-quoted string with an embedded
variable. But since there are no other characters in the string, the
quotes are pointless and just cause an unnecessary parsing overhead.

Micha
Mar 21 '08 #12

This discussion thread is closed

Replies have been disabled for this discussion.