1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

A little php help please!

Discussion in 'PHP & Perl' started by nutsforsports, Mar 2, 2010.

  1. nutsforsports

    nutsforsports Junior Member

    Joined:
    Aug 18, 2008
    Messages:
    172
    Likes Received:
    48
    Home Page:
    What I need is a quick script (code) for php that will take random urls from a text file and go to it.

    So...

    User clicks link and the code grabs a random url from a text file and goes to it.


    I don't think it is hard to do, just not a programmer so I have no idea on how to do this.

    Thanks!
     
  2. ukescuba

    ukescuba Jr. VIP Jr. VIP Premium Member

    Joined:
    Feb 24, 2008
    Messages:
    994
    Likes Received:
    634
    Occupation:
    Mobile Marketer & QR Code Junkie
    Location:
    San Antonio, TX
    Home Page:
    how many urls are you talking about? 1000's or like 5?
     
  3. atlascopy

    atlascopy Junior Member

    Joined:
    Nov 25, 2008
    Messages:
    171
    Likes Received:
    24
    Home Page:
    If you don't get any takers you can do it yourself. Grab AUTOMATE, it should be in the downloads here somewhere. It's not hard to figure out.
     
  4. nutsforsports

    nutsforsports Junior Member

    Joined:
    Aug 18, 2008
    Messages:
    172
    Likes Received:
    48
    Home Page:
    I am only talking around 20 or so.
     
  5. ukescuba

    ukescuba Jr. VIP Jr. VIP Premium Member

    Joined:
    Feb 24, 2008
    Messages:
    994
    Likes Received:
    634
    Occupation:
    Mobile Marketer & QR Code Junkie
    Location:
    San Antonio, TX
    Home Page:
    quick and dirty way of doing it probably easier ways but for now...

    create a file called urllist.php with the following code:

    <?php
    $url1="http://www.yourdomain1.com";
    $url2="http://www.yourdomain2.com";
    $url3="http://www.yourdomain3.com";
    ?>

    ie add all your 20 links...

    on your actual page where you want to show your random url do this:

    <?php
    //pull all your url values from urllist.php
    include 'urllist.php';
    // create a random number between 1 and the total number of urls in your urllist.php file in this example we use 20
    $x=(rand(1,20));
    //create prefix for random url
    $randomurl="$url";
    // echo out the random url in a href - you can format this anyway you want ie add a class, title, img src, target, etc
    echo "<a href=\"$randomurl$x\">your anchor text here</a>";
    ?>

    not tested this but it should work...

    hth
     
    • Thanks Thanks x 1
    Last edited: Mar 2, 2010
  6. aмillionaírе

    aмillionaírе Jr. VIP Jr. VIP Premium Member

    Joined:
    Apr 20, 2008
    Messages:
    532
    Likes Received:
    358
    PHP:
    [PHP]<?
    if(!empty($_GET['r']) && $_GET['r'] = 'true') { 
    $site = fopen("websites.txt","r"); $s = filesize('websites.txt');
    $site = fread($site, $s);
    $site = explode("\n",$site);
    $x = array_rand($site);
    header('Location: '.$site[$x]);
    }


    ?>
    HTML code:
    Code:
    <a href="<?php echo $_SERVER['PHP_SELF'].'?r=true'; ?>">Anchor text</a>
    Make sure the websites in 'websites.txt' start with the http:// protocol.
     
    • Thanks Thanks x 1