HighDots Forums  

force users to different pages?

HTML Writing HTML for the Web (comp.infosystems.www.authoring.html)


Discuss force users to different pages? in the HTML forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Geoff Cox
 
Posts: n/a

Default force users to different pages? - 03-21-2008 , 03:58 AM






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

Reply With Quote
  #2  
Old   
Jonathan N. Little
 
Posts: n/a

Default Re: force users to different pages? - 03-21-2008 , 08:40 AM






Geoff Cox wrote:
Quote:
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


Reply With Quote
  #3  
Old   
Geoff Cox
 
Posts: n/a

Default Re: force users to different pages? - 03-21-2008 , 10:35 AM



On Fri, 21 Mar 2008 09:40:41 -0400, "Jonathan N. Little"
<lws4art (AT) central (DOT) net> wrote:

Quote:
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



Reply With Quote
  #4  
Old   
Geoff Cox
 
Posts: n/a

Default Re: force users to different pages? - 03-21-2008 , 10:45 AM



On Fri, 21 Mar 2008 09:40:41 -0400, "Jonathan N. Little"
<lws4art (AT) central (DOT) net> wrote:

Quote:
?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>";

?
I didn't save as .php file!

Any thoughts on this one?

<script type="text/javascript">
function getNextPage(){
var num = Math.random();
if (num<.5) {
location.href="test1/test1.htm";
} else {
location.href="test2/test2.htm";
}

}
</script>

<IMG alt="image" src="assets/images/movelab1.gif"
onClick="getNextPage();">

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.

Cheers

Geoff


Reply With Quote
  #5  
Old   
Jonathan N. Little
 
Posts: n/a

Default Re: force users to different pages? - 03-21-2008 , 10:46 AM



Geoff Cox wrote:
Quote:
On Fri, 21 Mar 2008 09:40:41 -0400, "Jonathan N. Little"
lws4art (AT) central (DOT) net> wrote:

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


Reply With Quote
  #6  
Old   
Jonathan N. Little
 
Posts: n/a

Default Re: force users to different pages? - 03-21-2008 , 12:12 PM



Geoff Cox wrote:
Quote:
On Fri, 21 Mar 2008 09:40:41 -0400, "Jonathan N. Little"
lws4art (AT) central (DOT) net> wrote:

?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>";

?

I didn't save as .php file!

Any thoughts on this one?

script type="text/javascript"
function getNextPage(){
var num = Math.random();
if (num<.5) {
location.href="test1/test1.htm";
} else {
location.href="test2/test2.htm";
}

}
/script

IMG alt="image" src="assets/images/movelab1.gif"
onClick="getNextPage();"

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?

The server side solution means it doesn't matter.

--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com


Reply With Quote
  #7  
Old   
Geoff Cox
 
Posts: n/a

Default Re: force users to different pages? - 03-21-2008 , 01:49 PM



On Fri, 21 Mar 2008 13:12:49 -0400, "Jonathan N. Little"
<lws4art (AT) central (DOT) net> wrote:

Quote:
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

Quote:
The server side solution means it doesn't matter.



Reply With Quote
  #8  
Old   
Michael Fesser
 
Posts: n/a

Default Re: force users to different pages? - 03-21-2008 , 03:49 PM



..oO(Jonathan N. Little)

Quote:
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


Reply With Quote
  #9  
Old   
Chris F.A. Johnson
 
Posts: n/a

Default Re: force users to different pages? - 03-21-2008 , 04:02 PM



On 2008-03-21, Jonathan N. Little wrote:
Quote:
Geoff Cox wrote:
On Fri, 21 Mar 2008 09:40:41 -0400, "Jonathan N. Little"
lws4art (AT) central (DOT) net> wrote:

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)


Reply With Quote
  #10  
Old   
Michael Fesser
 
Posts: n/a

Default Re: force users to different pages? - 03-21-2008 , 04:25 PM



..oO(Chris F.A. Johnson)

Quote:
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.

Quote:
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


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.