force users to different pages?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Geoff Cox

    force users to different pages?

    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
  • Jonathan N. Little

    #2
    Re: force users to different pages?

    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.htm l','d.html');
    $last=count($li nks)-1;
    $link=$links[rand(0,$last)];

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

    ?>

    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO

    Comment

    • Geoff Cox

      #3
      Re: force users to different pages?

      On Fri, 21 Mar 2008 09:40:41 -0400, "Jonathan N. Little"
      <lws4art@centra l.netwrote:
      >A much simpler method would be a link randomizer.
      >
      ><?php
      >
      >$links = array('a.html', 'b.html','c.htm l','d.html');
      >$last=count($l inks)-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

      Comment

      • Jonathan N. Little

        #4
        Re: force users to different pages?

        Geoff Cox wrote:
        On Fri, 21 Mar 2008 09:40:41 -0400, "Jonathan N. Little"
        <lws4art@centra l.netwrote:
        >
        >A much simpler method would be a link randomizer.
        >>
        ><?php
        >>
        >$links = array('a.html', 'b.html','c.htm l','d.html');
        >$last=count($l inks)-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

        Comment

        • Geoff Cox

          #5
          Re: force users to different pages?

          On Fri, 21 Mar 2008 13:12:49 -0400, "Jonathan N. Little"
          <lws4art@centra l.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.

          Comment

          • Michael Fesser

            #6
            Re: force users to different pages?

            ..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'>My stery Tour</a>";

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

            Micha

            Comment

            • Chris F.A. Johnson

              #7
              Re: force users to different pages?

              On 2008-03-21, Jonathan N. Little wrote:
              Geoff Cox wrote:
              >On Fri, 21 Mar 2008 09:40:41 -0400, "Jonathan N. Little"
              ><lws4art@centr al.netwrote:
              >>
              >>A much simpler method would be a link randomizer.
              >>>
              >><?php
              >>>
              >>$links = array('a.html', 'b.html','c.htm l','d.html');
              >>$last=count($ links)-1;
              >>$link=$link s[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">Myste ry Tour</a>\n' "$link"

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

              Comment

              • Michael Fesser

                #8
                Re: force users to different pages?

                ..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">Myste ry 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

                Comment

                • Geoff Cox

                  #9
                  Re: force users to different pages?

                  On Fri, 21 Mar 2008 21:02:41 +0000, "Chris F.A. Johnson"
                  <cfajohnson@gma il.comwrote:
                  Or use the safer and more portable printf instead of the
                  deprecated echo:
                  >
                  >printf '<a href="%s">Myste ry 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'>Myste ry Tour</a>",$link);

                  Seem OK to you?

                  Cheers

                  Geoff

                  Comment

                  • Chris F.A. Johnson

                    #10
                    Re: force users to different pages?

                    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)

                    Comment

                    • Bergamot

                      #11
                      Re: force users to different pages?

                      Michael Fesser wrote:
                      .oO(Chris F.A. Johnson)
                      >
                      >>printf '<a href="%s">Myste ry 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

                      Comment

                      • Michael Fesser

                        #12
                        Re: force users to different pages?

                        ..oO(Bergamot)
                        >Michael Fesser wrote:
                        >.oO(Chris F.A. Johnson)
                        >>
                        >>>printf '<a href="%s">Myste ry 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">Myste ry 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

                        Comment

                        Working...