76.gif

Search (advanced search)
Use this Search form before posting, asking or make a new thread.
Tips: Use Quotation mark to search words (eg. "How To Make Money Online")

09-09-2015, 01:26 AM
Post: #1
[GET] mass url shortening script (301)
script to run a url through many url shortening services and output the shortened urls (free 301 redirects ;) ).

btw these sites run on the YOURLS platform (yourls.org).

i wrote this quickly in like 10 mins a few years ago, but it still does its job just fine. it can also output all urls in spintax and removes bad hosts automatically too.

PHP Code:
Code:
<?php
    // YOURLS - URL shortening script by styx @ argo-content.com 2011

    if(empty($argv[2])) usage($argv[0]);
    $fl=$argv[1]; // list file
    $f=file($fl); // don't touch this!
    $url=urlencode($argv[2]);
    $verbose=0; // show more detailed output, 0 = disabled | 1 = enabled
    $spin=1; // output the urls as spintax, 0 = disabled | 1 = enabled
    function curl($url,$postdata=NULL,$pr=0)
    {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/4.0');
        curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate');
        curl_setopt($curl, CURLOPT_AUTOREFERER, true);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        if($pr !== 0) {
            curl_setopt($curl, CURLOPT_PROXY, '127.0.0.1:9050');
            curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
        }
        curl_setopt($curl, CURLOPT_COOKIESESSION, FALSE);
        curl_setopt($curl, CURLOPT_COOKIEJAR, "cookie");
        curl_setopt($curl, CURLOPT_COOKIEFILE, "cookie");
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
        curl_setopt($curl, CURLOPT_TIMEOUT, 10);
        if($postdata !== NULL) {
            curl_setopt($curl, CURLOPT_POST, TRUE);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
        }
        $html = curl_exec($curl);
        curl_close($curl);
        return $html;
    }

    function delLine($list,$line){
        if(!is_writable($list)) {
            die("x $file isn't writable.\n");
        } else {
            $arr = file($list);
        }
        if($fp=fopen($list,'w+')) {
            foreach($arr as $ln) {
                $match=trim($ln);
                if(!stristr($line,$match)) {
                    fwrite($fp,$ln);
                }
            }
            fclose($fp);
        } else {
            die("x coudln't open $file! check permissions.");
        }
    }

    function remove_host($host,$list) {
        $fa = file($list);
        foreach ($fa as $f => $l) {
            if(stristr($l,$host)) {
                delLine($list,trim($l));
                break;
            }
        }
    }

    function main() {
        global $f,$fl,$url,$verbose,$spin;
        $sz=count($f);
        if($spin==1) print "{";
        foreach($f as $n => $l) {
            $host=trim($l);

            if($verbose==1&and$spin==0) { // only print this if spintax is disabled..
                print "(".($n+1)."/$sz) current host: $host | ";
            }
            $query="url=$url&keyword=";
            $html = curl($host,$query);
            preg_match_all("/copylink\" class=\"text\" size=\"40\" value=\"(.*)\"/i",$html,$m);
            if(!empty($m[1][0])) {
                $lnk=$m[1][0];
                if($spin==0) {
                    print $lnk."\n";
                } else {
                    if($n<($sz-1)) {
                        print $lnk."|";
                    } else {
                        print "$lnk";
                    }
                }
            } else {
                if($verbose==1&and$spin==0) print "- removing host: $host\n";
                remove_host($host,$fl);
            }
        }
        if($spin==1) print "}\n";
    }

    function usage($arg) {
       die("mass url shortening script by styx @ bhseos.com\nusage: <list> <url>\nexample: php $arg list.txt http://argo-content.com\n");
    }
    main(); // execute
?>
usage:

you need to run this from the linux (or other *nix) shell like:
Code:
php shorten.php targets.txt http://yourdomain.com
to enable verbose and/or spintax output, change the variables on top of the script:
Code:
$verbose=0; // show more detailed output, 0 = disabled | 1 = enabled
    $spin=1; // output the urls as spintax, 0 = disabled | 1 = enabled
and here some working hosts (just a few as i was too lazy now to scrape new ones):
Code:
http://activ.me
http://jdivert.com
http://j.plustar.jp
http://macp.ro
http://onj.me
http://rct.me
http://urim.sourceforge.net

here are some example footprints to find sites:
Code:
intitle:"yourls -- your own url shortener"
or
"powered by Yourls"

enjoy :)
11-16-2015, 05:56 AM
Post: #2
RE: [GET] mass url shortening script (301)
hm thought might be useful to some of you :)




21.gif