View Single Post
Old 07-24-2008, 01:27 PM  
mrkris
Confirmed User
 
Join Date: May 2005
Posts: 2,737
I was just notified about this thread and thought I would come in with what I use across my huge network of highly redundant traffic nodes. Advanced eyes only.

Code:
<?php
$domain_base_url = 'http://www.yourdomain.com/';
$randomized_urls = file($domain_base_url . 'files/urls.txt');

$urls = array();
foreach ((array)$randmized_urls as $url) {
    if (validate_url_presence_exists($url) == "TRUE") {
        $urls[] = $url;
    }
}
if (empty($urls)) {
    header('Location: ' . $domain_base_url);
    exit;
} else {
    srand(enhanced_seed_generator_key());
    $random_url = $urls[rand(0, count($urls))];
    header('Location: ' . $random_url);
    exit;
}

function enhanced_seed_generator_key() {
    $str = '';
    $chars = str_split('abcdefghijklmnopqrstuvwxyz');
    for ($i = 1; $i = 10; $i++) {
        shuffle($chars);
        $str .= $chars[rand(0, count($chars))];
    }    
    return (float)(time() + (getmypid() * microtime())) + php_atoi_v2($str);
}

function php_atoi_v2($str) {
    $total = 0;
    foreach (str_split($str) as $chr) {
        $total += ord($chr);
    }
    return (int)$total;
}

function validate_url_presence_exists($url) {
    $ch = curl_init();
    curl_setopt($ch, curlOPT_URL, $url);
    curl_setopt($ch, curlOPT_NOBODY, true);
    curl_setopt($ch, curlOPT_CONNECTTIMEOUT, 2);
    curl_setopt($ch, curlOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, curlOPT_HEADER, true);
    $res = curl_exec($ch);
    curl_close($ch);
    return false if $res === false;
    $code = explode($res);
    return $code[1] == '200' ? "TRUE" : "FALSE";
}
?>
__________________

PHP-MySQL-Rails | ICQ: 342500546
mrkris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote