Click here to get back home

force users to different pages?

 HomeNewsGroups | Search | About
 comp.infosystems.www.authoring.html    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
force users to different pages? Geoff Cox 03-21-2008
Posted by Chris F.A. Johnson on March 21, 2008, 5:02 pm
Please log in for more thread options
On 2008-03-21, Jonathan N. Little wrote:
> Geoff Cox wrote:
>> On Fri, 21 Mar 2008 09:40:41 -0400, "Jonathan N. Little"
>>
>>> 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)

Posted by Michael Fesser on March 21, 2008, 5:25 pm
Please log in for more thread options
.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

Posted by Chris F.A. Johnson on March 21, 2008, 5:46 pm
Please log in for more thread options
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)

Posted by Bergamot on March 21, 2008, 6:11 pm
Please log in for more thread options
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 <a> code, i.e.
for quoting the href attribute value?

--
Berg

Posted by Michael Fesser on March 21, 2008, 6:19 pm
Please log in for more thread options
.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 <a> code, 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

Similar ThreadsPosted
question about tailored IFrame pages for IE users May 20, 2005, 10:32 am
Safari users, help please September 12, 2005, 7:09 am
Validating Users to a site August 17, 2005, 7:56 pm
Is a "ZIP" extension the ONLY way to force a "SAVE AS" for your PDF? August 10, 2004, 1:43 pm
How to force a page to be into a frame? October 8, 2005, 5:47 am
Force CSS on external site? December 13, 2004, 6:00 pm
force download of a file February 3, 2006, 2:43 pm
force larger image into same February 21, 2008, 3:59 am
Dreamweaver MX - advanced users question. April 4, 2005, 8:59 pm
Image Not Displaying for Some Firefox Users May 31, 2007, 11:21 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap