Advertisement
ozh

Insert fake links in YOURLS

ozh
Nov 7th, 2013
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.36 KB | None | 0 0
  1. <pre>
  2. <?php
  3. /**
  4.  * Insert fake links in YOURLS
  5.  *
  6.  */
  7.  
  8. // Load YOURLS
  9. require_once( dirname(__FILE__).'/includes/load-yourls.php' );
  10.  
  11. // Add 10 links
  12. for( $i = 1; $i <= 10; $i++ ) {
  13.     $url     = generate_fake_URL();
  14.     $title   = 'Title ' . yourls_rnd_string( mt_rand(5, 20) );
  15.     $return  = yourls_add_new_link( $url, '', $title );
  16.     $keyword = $return['url']['keyword'];
  17.     // Add 10 hits per link
  18.     for ( $h = 1; $h <= 10; $h++ ) {
  19.         insert_fake_link( $keyword );
  20.     }
  21.     var_dump( $keyword );
  22. }
  23.  
  24. // Generate fake URL
  25. function generate_fake_URL() {
  26.     return yourls_rnd_string( mt_rand(2, 10) ) . '.com/' . yourls_rnd_string( mt_rand(2, 10) ) . '/';
  27. }
  28.  
  29. // Generate fake IP
  30. function generate_fake_IP() {
  31.     return long2ip(rand(0, 2147483647));
  32. }
  33.  
  34. // Generate fake user agent
  35. function generate_fake_user_agent() {
  36.     return 'Mozilla/' . mt_rand( 3, 5 ) . '.0 (' . yourls_rnd_string( mt_rand(5, 20) ) . ')';
  37. }
  38.  
  39. // Insert fake hits on a link
  40. function insert_fake_link( $keyword ) {
  41.     global $ydb;
  42.    
  43.     $table = YOURLS_DB_TABLE_LOG;
  44.  
  45.     $referrer = generate_fake_URL();
  46.     $ua = generate_fake_user_agent();
  47.     $ip = generate_fake_IP();
  48.     $location = yourls_geo_ip_to_countrycode( $ip );
  49.    
  50.     return $ydb->query( "INSERT INTO `$table` (click_time, shorturl, referrer, user_agent, ip_address, country_code) VALUES (NOW(), '$keyword', '$referrer', '$ua', '$ip', '$location')" );
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement