PHP question

Discussion in 'HTML' started by Viper, Dec 16, 2004.

  1. Viper

    Viper Guest

    On one of my sites I use
    <? header("location: http://www.MYDOMAIN.com/pages/index.php");?> to forward
    people that goto http://www.MYDOMAIN.com to that page. Now is there a way to
    make it randomly pick a file to send to?

    Like
    <?
    $num = $rand(1,3)
    header("location: http://www.MYDOMAIN.com/pages/index$rand.php");?>
    Where $rand would pick 1 2 or 3 then send the user to that index page?
     
    Viper, Dec 16, 2004
    #1
    1. Advertising

  2. Viper

    Chris Hope Guest

    Viper wrote:

    > On one of my sites I use
    > <? header("location: http://www.MYDOMAIN.com/pages/index.php");?> to
    > forward people that goto http://www.MYDOMAIN.com to that page. Now is
    > there a way to make it randomly pick a file to send to?
    >
    > Like
    > <?
    > $num = $rand(1,3)
    > header("location: http://www.MYDOMAIN.com/pages/index$rand.php");?>
    > Where $rand would pick 1 2 or 3 then send the user to that index page?


    Yes.

    http://www.php.net/rand

    "int rand ( [int min, int max])

    If called without the optional min, max arguments rand() returns a
    pseudo-random integer between 0 and RAND_MAX. If you want a random
    number between 5 and 15 (inclusive), for example, use rand (5, 15)."

    --
    Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
     
    Chris Hope, Dec 16, 2004
    #2
    1. Advertising

  3. Viper

    Viper Guest

    Chris Hope wrote:
    > Viper wrote:
    >
    >> On one of my sites I use
    >> <? header("location: http://www.MYDOMAIN.com/pages/index.php");?> to
    >> forward people that goto http://www.MYDOMAIN.com to that page. Now is
    >> there a way to make it randomly pick a file to send to?
    >>
    >> Like
    >> <?
    >> $num = $rand(1,3)
    >> header("location: http://www.MYDOMAIN.com/pages/index$rand.php");?>
    >> Where $rand would pick 1 2 or 3 then send the user to that index
    >> page?

    >
    > Yes.
    >
    > http://www.php.net/rand
    >
    > "int rand ( [int min, int max])
    >
    > If called without the optional min, max arguments rand() returns a
    > pseudo-random integer between 0 and RAND_MAX. If you want a random
    > number between 5 and 15 (inclusive), for example, use rand (5, 15)."


    Thanks that helped a bit. :)
    This works:

    <?
    $newpage = "http://www.MYDOMAIN.com/pages/index".rand(1,3).".php";
    header("location: $newpage")

    ;?>
     
    Viper, Dec 16, 2004
    #3
  4. Viper

    Chris Hope Guest

    Viper wrote:

    > Chris Hope wrote:
    >> Viper wrote:
    >>
    >>> On one of my sites I use
    >>> <? header("location: http://www.MYDOMAIN.com/pages/index.php");?> to
    >>> forward people that goto http://www.MYDOMAIN.com to that page. Now
    >>> is there a way to make it randomly pick a file to send to?
    >>>
    >>> Like
    >>> <?
    >>> $num = $rand(1,3)
    >>> header("location: http://www.MYDOMAIN.com/pages/index$rand.php");?>
    >>> Where $rand would pick 1 2 or 3 then send the user to that index
    >>> page?

    >>
    >> Yes.
    >>
    >> http://www.php.net/rand
    >>
    >> "int rand ( [int min, int max])
    >>
    >> If called without the optional min, max arguments rand() returns a
    >> pseudo-random integer between 0 and RAND_MAX. If you want a random
    >> number between 5 and 15 (inclusive), for example, use rand (5, 15)."

    >
    > Thanks that helped a bit. :)
    > This works:
    >
    > <?
    > $newpage = "http://www.MYDOMAIN.com/pages/index".rand(1,3).".php";
    > header("location: $newpage")
    >
    > ;?>


    You could also do something like this, although there's a little more
    overhead involved as it has to initiate the array and use memory:

    $pages = array(
    "somepage.php",
    "anotherpage.php",
    "someotherpage.php"
    ...
    );

    $rand = rand(0, sizeof($pages)-1);

    $newpage = "http://www.MYDOMAIN.com/pages/" . $pages[$rand];
    header("location: $newpage");
    exit;

    --
    Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
     
    Chris Hope, Dec 16, 2004
    #4
  5. Viper wrote:

    > Chris Hope wrote:
    >> Viper wrote:
    >>
    >>> On one of my sites I use
    >>> <? header("location: http://www.MYDOMAIN.com/pages/index.php");?> to
    >>> forward people that goto http://www.MYDOMAIN.com to that page. Now is
    >>> there a way to make it randomly pick a file to send to?
    >>>
    >>> Like
    >>> <?
    >>> $num = $rand(1,3)
    >>> header("location: http://www.MYDOMAIN.com/pages/index$rand.php");?>
    >>> Where $rand would pick 1 2 or 3 then send the user to that index
    >>> page?

    >>
    >> Yes.
    >>
    >> http://www.php.net/rand
    >>
    >> "int rand ( [int min, int max])
    >>
    >> If called without the optional min, max arguments rand() returns a
    >> pseudo-random integer between 0 and RAND_MAX. If you want a random
    >> number between 5 and 15 (inclusive), for example, use rand (5, 15)."

    >
    > Thanks that helped a bit. :)
    > This works:
    >
    > <?
    > $newpage = "http://www.MYDOMAIN.com/pages/index".rand(1,3).".php";
    > header("location: $newpage")
    >
    > ;?>


    Well done that man! Looks neat.

    --
    Charles Sweeney
    http://CharlesSweeney.com
     
    Charles Sweeney, Dec 16, 2004
    #5
  6. Viper

    Viper Guest

    Charles Sweeney wrote:
    > Viper wrote:
    >
    >> Chris Hope wrote:
    >>> Viper wrote:
    >>>
    >>>> On one of my sites I use
    >>>> <? header("location: http://www.MYDOMAIN.com/pages/index.php");?>
    >>>> to forward people that goto http://www.MYDOMAIN.com to that page.
    >>>> Now is there a way to make it randomly pick a file to send to?
    >>>>
    >>>> Like
    >>>> <?
    >>>> $num = $rand(1,3)
    >>>> header("location: http://www.MYDOMAIN.com/pages/index$rand.php");?>
    >>>> Where $rand would pick 1 2 or 3 then send the user to that index
    >>>> page?
    >>>
    >>> Yes.
    >>>
    >>> http://www.php.net/rand
    >>>
    >>> "int rand ( [int min, int max])
    >>>
    >>> If called without the optional min, max arguments rand() returns a
    >>> pseudo-random integer between 0 and RAND_MAX. If you want a random
    >>> number between 5 and 15 (inclusive), for example, use rand (5, 15)."

    >>
    >> Thanks that helped a bit. :)
    >> This works:
    >>
    >> <?
    >> $newpage = "http://www.MYDOMAIN.com/pages/index".rand(1,3).".php";
    >> header("location: $newpage")
    >>
    >> ;?>

    >
    > Well done that man! Looks neat.


    Thanks but now I have to wonder how search engines will handle it. See what
    I am planning to do is take all the domains I own that have no pages on them
    and make up "portal" pages using PPC Search engines. I want it to show a
    different portal page that has a different set of PPC Search engines links
    on it each time they visit. But will Google, etc even list these pages?
     
    Viper, Dec 16, 2004
    #6
  7. Viper wrote:

    > Charles Sweeney wrote:
    >> Viper wrote:
    >>
    >>> Chris Hope wrote:
    >>>> Viper wrote:
    >>>>
    >>>>> On one of my sites I use
    >>>>> <? header("location: http://www.MYDOMAIN.com/pages/index.php");?>
    >>>>> to forward people that goto http://www.MYDOMAIN.com to that page.
    >>>>> Now is there a way to make it randomly pick a file to send to?
    >>>>>
    >>>>> Like
    >>>>> <?
    >>>>> $num = $rand(1,3)
    >>>>> header("location:
    >>>>> http://www.MYDOMAIN.com/pages/index$rand.php");?> Where $rand
    >>>>> would pick 1 2 or 3 then send the user to that index page?
    >>>>
    >>>> Yes.
    >>>>
    >>>> http://www.php.net/rand
    >>>>
    >>>> "int rand ( [int min, int max])
    >>>>
    >>>> If called without the optional min, max arguments rand() returns a
    >>>> pseudo-random integer between 0 and RAND_MAX. If you want a random
    >>>> number between 5 and 15 (inclusive), for example, use rand (5,
    >>>> 15)."
    >>>
    >>> Thanks that helped a bit. :)
    >>> This works:
    >>>
    >>> <?
    >>> $newpage = "http://www.MYDOMAIN.com/pages/index".rand(1,3).".php";
    >>> header("location: $newpage")
    >>>
    >>> ;?>

    >>
    >> Well done that man! Looks neat.

    >
    > Thanks but now I have to wonder how search engines will handle it. See
    > what I am planning to do is take all the domains I own that have no
    > pages on them and make up "portal" pages using PPC Search engines. I
    > want it to show a different portal page that has a different set of
    > PPC Search engines links on it each time they visit. But will Google,
    > etc even list these pages?


    As I understand it, when using a redirection, Google will index the page
    it gets sent to, but drop the sending page.

    --
    Charles Sweeney
    http://CharlesSweeney.com
     
    Charles Sweeney, Dec 16, 2004
    #7
  8. Viper

    Karl Core Guest

    "Charles Sweeney" <> wrote in message
    news:Xns95C16A020C173mecharlessweeneycom@130.133.1.4...
    > Viper wrote:
    >
    >> Charles Sweeney wrote:
    >>> Well done that man! Looks neat.

    >>
    >> Thanks but now I have to wonder how search engines will handle it. See
    >> what I am planning to do is take all the domains I own that have no
    >> pages on them and make up "portal" pages using PPC Search engines. I
    >> want it to show a different portal page that has a different set of
    >> PPC Search engines links on it each time they visit. But will Google,
    >> etc even list these pages?

    >
    > As I understand it, when using a redirection, Google will index the page
    > it gets sent to, but drop the sending page.
    >



    AFAIK that's only if Google knows it is a redirection - i.e. if you're
    sending the proper headers while redirecting.
    Would googlebot know if Viper's site is redirecting it?


    --
    -Karl Core
    Please Support "Project Boneyard":
    http://www.insurgence.net/info.aspx?action=band&item=boneyard
     
    Karl Core, Dec 16, 2004
    #8
  9. On Thu, 16 Dec 2004 08:55:40 -0500, Karl Core wrote:

    > AFAIK that's only if Google knows it is a redirection - i.e. if you're
    > sending the proper headers while redirecting.
    > Would googlebot know if Viper's site is redirecting it?


    Probably. PHP is pretty decent about complying with header standards.

    --
    Jeffrey D. Silverman |
    Website | http://www.newtnotes.com

    Drop "PANTS" to reply by email
     
    Jeffrey Silverman, Dec 16, 2004
    #9
  10. Viper wrote:
    > Charles Sweeney wrote:
    >
    >>Viper wrote:
    >>
    >>
    >>>Chris Hope wrote:
    >>>
    >>>>Viper wrote:
    >>>>
    >>>>
    >>>>>On one of my sites I use
    >>>>><? header("location: http://www.MYDOMAIN.com/pages/index.php");?>
    >>>>>to forward people that goto http://www.MYDOMAIN.com to that page.
    >>>>>Now is there a way to make it randomly pick a file to send to?
    >>>>>
    >>>>>Like
    >>>>><?
    >>>>>$num = $rand(1,3)
    >>>>>header("location: http://www.MYDOMAIN.com/pages/index$rand.php");?>
    >>>>>Where $rand would pick 1 2 or 3 then send the user to that index
    >>>>>page?
    >>>>
    >>>>Yes.
    >>>>
    >>>>http://www.php.net/rand
    >>>>
    >>>>"int rand ( [int min, int max])
    >>>>
    >>>>If called without the optional min, max arguments rand() returns a
    >>>>pseudo-random integer between 0 and RAND_MAX. If you want a random
    >>>>number between 5 and 15 (inclusive), for example, use rand (5, 15)."
    >>>
    >>>Thanks that helped a bit. :)
    >>>This works:
    >>>
    >>><?
    >>>$newpage = "http://www.MYDOMAIN.com/pages/index".rand(1,3).".php";
    >>>header("location: $newpage")
    >>>
    >>>;?>

    >>
    >>Well done that man! Looks neat.

    >
    > Thanks but now I have to wonder how search engines will handle it. See what
    > I am planning to do is take all the domains I own that have no pages on them
    > and make up "portal" pages using PPC Search engines. I want it to show a
    > different portal page that has a different set of PPC Search engines links
    > on it each time they visit. But will Google, etc even list these pages?


    Depending on how your files are set up, instead of doing a redirect with
    headers, you could use an include or an fpassthru call. That way, the
    content is displayed without a redirect...

    --
    Justin Koivisto -
    http://www.koivi.com
     
    Justin Koivisto, Dec 16, 2004
    #10
  11. Viper

    Per Jessen Guest

    Karl Core wrote:

    > AFAIK that's only if Google knows it is a redirection - i.e. if you're
    > sending the proper headers while redirecting.
    > Would googlebot know if Viper's site is redirecting it?


    Yes, the PHP header() function sends a proper 30x redirect header as specified
    by the caller.


    --
    Per Jessen, Zurich
    Let your spam stop here -- http://www.spamchek.com
     
    Per Jessen, Dec 16, 2004
    #11
  12. Karl Core wrote:

    > AFAIK that's only if Google knows it is a redirection - i.e. if you're
    > sending the proper headers while redirecting.
    > Would googlebot know if Viper's site is redirecting it?


    Good point, and good day to you sir.

    --
    Charles Sweeney
    http://CharlesSweeney.com
     
    Charles Sweeney, Dec 16, 2004
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ted Zeng
    Replies:
    4
    Views:
    572
    Tim Arnold
    Oct 3, 2006
  2. Ted Zeng
    Replies:
    0
    Views:
    686
    Ted Zeng
    Oct 13, 2006
  3. torque63
    Replies:
    0
    Views:
    666
    torque63
    Jan 1, 2009
  4. raviraj joshi
    Replies:
    0
    Views:
    360
    raviraj joshi
    Jul 4, 2009
  5. Rajive Narain
    Replies:
    0
    Views:
    2,091
    Rajive Narain
    Sep 18, 2009
Loading...

Share This Page