Announcement

Collapse
No announcement yet.

array redirect

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

  • array redirect

    A simple PhP array redirect script - chooses from any of a number of web sites you specify, and redirects the user to one of them. It has uses well beyond sending people to search engines.

    <?php
    //the array of links
    $linx[0] = "http://www.google.com";
    $linx[1] = "http://www.dogpile.com";
    $linx[2] = "http://www.lycos.com";
    $linx[3] = "http://www.ask.com";
    $linx[4] = "http://www.msdewey.com";

    //choose a random element from the array
    $slinky = array_rand($linx, 1);
    $sslinkys = $linx[$slinky];

    //redirect to the random page
    header("Location: $sslinkys");
    ?>
    Last edited by that_chick_in_I.T.; 12-27-2006, 09:26 PM.

    root@darkstar: mount -t iso9660 /dev/hdc /cdrom
    root@darkstar: cp -r /cdrom/lib/* /lib/*
    root@darkstar: crap
    -bash crap: command not found
    root@darkstar: man -k undo

  • #2
    Isnt php fun?

    Comment


    • #3
      If I knew what any of that meant, I'd probably be laughing my butt off right now.
      Gah, I'm getting too old.
      Age and wisdom don't necessarily go together. Some people just become stupid with more authority.

      "Who put the goat in there? The yellow goat I ate."

      Comment


      • #4
        If I knew what any of that meant, I'd probably be laughing my butt off right now.
        Basically, the script takes the user from one site, and moves them to another. For example, if I had joebobswebsite.com, and put that script on there, the user would type in joebobswebsite.com, but would end up at google.com - or one of the other sites I picked out.

        You can have a lot of fun with this if you want to. The original version of this script contains about 50 links, none of which are remotely work safe.

        root@darkstar: mount -t iso9660 /dev/hdc /cdrom
        root@darkstar: cp -r /cdrom/lib/* /lib/*
        root@darkstar: crap
        -bash crap: command not found
        root@darkstar: man -k undo

        Comment


        • #5
          If I knew what any of that meant, I'd probably be laughing my butt off right now.
          Gah, I'm getting too old.
          *Enter dork mode* (mainly because my servers are broken and I'm in a holding pattern at work and really bored)

          <?php
          Marks the beginning of a section of PHP code. PHP is code that runs on the server and is used to dynamically create web pages. It can be embedded directly into webpages but the end user will not see the PHP code, because it has generated plaintext code, as well as possibly having done other things like create files on a the server and stuff, but that's more complicated than what we are talking about here.

          //the array of links
          This is a comment - an unprocessesd section of the code. The // dennotes the beginning of a comment for the line.

          $linx[0] = "http://www.google.com";
          $linx[1] = "http://www.dogpile.com";
          $linx[2] = "http://www.lycos.com";
          $linx[3] = "http://www.ask.com";
          $linx[4] = "http://www.msdewey.com";
          $linx is a variable representing an array of data (similar to algebra like X+2; X can be anything). In php, variables are denoted with a $.

          Think of an array as the mailboxes in an apartment building. Each mailbox has a number assigned to it, and has mail in it. This section of code is putting "mail" in the "mailboxes". The [<number>], called an index, denotes which element in the array is being accessed. So in the first line in the above code, the first element will hold "http://www.google.com". But why is the index 0? That's because in most languages, minus annyoing languages like VB which can't even stay consistent within itself, arrays will start at 0, not 1.

          //choose a random element from the array
          $slinky = array_rand($linx, 1);
          array_rand is a function. Functions take arguments, which are in the parenthesis. This function will look at an array (the first argument, in this case, $linx, which was created above) and and randomly return the number of indexes you specify (the second argument, in this case 1). So this specific function randomly chooses one index from our list of webpages, and assigns that index to $slinky.

          $sslinkys = $linx[$slinky];
          Now that we have an index, we need to get that element at that index from the array and assign it to another variable. This is what this line of code does. It is essentially saying "$sslinkys will be the element at the index we've randomly chosen from $linx"

          //redirect to the random page
          header("Location: $sslinkys");
          header() is another built in function of php. It will write header information in the generated webpage (but must be executed before anything else is written). THe header of a webpage can tell the webbrowser how to treat the page, in this case it is telling the webbrowser to redirect the page to the whatever $sslinkys is.

          So let's say that that $sslinkys is chosen to be http://google.com. If you were to look at the source of the generated webpage you would see the header tag, with "Location: http://google.com" in it.

          ?>
          Denotes the end of a section of PHP code.
          Last edited by trunks2k; 12-28-2006, 01:47 PM.

          Comment

          Working...
          X