The WF PHP Functions War Chest

php cURL to send a few characters at a time to a web page?

Some great scripts here that will help me with some of my code, but I'm looking for some way to simulate a user entering a reply to a web page form by "typing" a few characters at a time with random time delays between some of the characters. I want to be able to use proxies too, so what I know about ajax or javascript etc. have cross dom issues...

Does anyone here have any thoughts or suggestions?
 


Turn string into sexy slug.

function sanitizeSlug($str, $replace=array(), $delimiter='-', $maxLength=100) {

if( !empty($replace) ) {
$str = str_replace((array)$replace, ' ', $str);
}

$clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
$clean = preg_replace("%[^-/+|\w ]%", '', $clean);
$clean = strtolower(substr($clean, 0, $maxLength));
$clean = trim(preg_replace("/[\/_|+ -]+/", $delimiter, $clean), '-');

return $clean;
}
 
For all those who spin articles or posts (eg with bestspinner), here is a class of mine I use in autoblogs to reuse my content often:
http://www.automated-marketing-system.com/madlib/madlib.php.zip

Example for usage:
AWARE ADULT CONTENT:
General text (left side, bottom) is spinned, girls description is from csv.
Discover Axelle Parker: Golden eyes @VirtualGirl2HD.com
Watch Aria Giovanni: Vampire killer @VirtualGirl2HD.com
...


(for wf members use only, please don't contribute)

Usage:
$outputstring = Madlib::spin(string $text [, string $salt] [,mixed $keys])

Description:
This library can be used to spin text containing madlibs (like '{one|{two|2|a pair}|three}') by selecting words thru random, a optional salt (for example a url or domain) and prefered keywords (optional).

Installation:
Just copy and extract this file into your webspace and include it at the top of your php-files:

PHP:
<?php include_once('MadlibSpinner.php'); ?>
Parameters:
string $text The text that should be spinned, nested spintax/madlibs are possible
string $salt [optional] If given, the text would be spinned every time the same way. If not, text will be spinned by random each time. Good for autosites, when the url is the salt, the page would always be the same.
mixed $keys [optional] Can be a string with one keyword, a madlib with keywords separeted by '|' or an array with several keywords. If given keywords will be prefered.

Return Values:
Returns the spun text, with madlibs replaced

Examples:
PHP:
echo Madlib::spin("{two|four} eggs");
Will output "two eggs" or "four eggs"

PHP:
echo Madlib::spin("{two|four} eggs","www.domain.tld/mypage.php");
Will ouput every time: "four eggs" cause of the given salt

PHP:
echo Madlib::spin("{two|four} eggs","www.domain.tld/mypage.php","two");
Will ouput every time: "two eggs" cause of the given keyword

PHP:
echo Madlib::spin("{two|four} eggs","www.domain.tld/mypage.php","one|two|three");
Will ouput every time: "two eggs" cause of 'two' is included in the given keyword madlib

PHP:
echo Madlib::spin("{two|three|four} eggs","",array("one","two","three"));
Will ouput: "two eggs" or "three eggs" randomly cause no salt is given and "two" and "three" are in the keys array


Damn... I just came across this and want it as it looks good, but it seems to have been taken down. Did anyone every download or save the main script?

The OP seems to have left the forum 2 years ago..
 
I don't really care for that method (though some people might), since it depends on the host site being up for it to work. That and not everyone may want the script creator to know of the sites it's being used on. (not to mention if a crap load of people use that service, it may slow down your own site when dealing with large amounts of traffic you're trying to geocode)

I can't speak of that service (but I'm going to look into it).

Here is a function I recently wrote utilizing the hostip.info.

Their API returns XML. You would realistically have to customize this script a bit to suit whatever specific needs but it will query the API and parse the XML for you to do whatever you need to do with it.

Code:
function get_user_location($ip) {
          $url = 'http://api.hostip.info/?ip='.$ip;
         
          #check to see if hostip.info service is running (and ignore localhost)
          if(simplexml_load_file($url) || $_SERVER['REMOTE_ADDR'] != "127.0.0.1"){
			  $xml = simplexml_load_file($url);
			  $location = $xml->children('gml', TRUE)->featureMember->children('', TRUE)->Hostip->children('gml', TRUE);
		  }
		  
		  else
		  {
			  #you're screwed B, the API isn't working
			  #handle failure however you want
		  }
     }

PHP:
function get_user_location($ip) {
          $url = 'http://api.hostip.info/?ip='.$ip;
         
          #check to see if hostip.info service is running (and ignore localhost)
          if(simplexml_load_file($url) || $_SERVER['REMOTE_ADDR'] != "127.0.0.1"){
			  $xml = simplexml_load_file($url);
			  $location = $xml->children('gml', TRUE)->featureMember->children('', TRUE)->Hostip->children('gml', TRUE);
		  }
		  
		  else
		  {
			  #you're screwed B, the API isn't working
			  #handle failure however you want
		  }
     }
 
oh and if someone could
PHP:
 that code instead of [code] that'd be great.[/QUOTE]

[code] is easier to read. [php] is almost impossible to read. I have to highlight the stuff between [php] tags just to be able to read it.
 
I would like to track click conversions and sales for my affiliate site but am having trouble passing url tracking info through.

My links are using redirect files: header( 'Location:AffiliateLink

I am running an AdCenter ppc campaign and would like too do 2 things:

1. Track a conversion if someone clicks on an add then clicks an affiliate link.
2. Pass URL tracking info from PPC ad to the affiliate site so I can check my sales reports later. Example: ?sid=3&pub=55555&c1={keyword}&c2={AdGroup}&c3={MatchType}.

I dont feel comfortable running ppc campaigns that I cannot track so any help would be awesome :)
 
I'll post more once I get my main computer fixed, but here are some simple ones that are really just time savers.

PHP:
function q($q){
  return mysql_query($q);
 }
 public function mid(){
  return mysql_insert_id();
 }
 function f($q){
  return mysql_fetch_array($q);
 }
 public function n($q){
  return @mysql_num_rows($q);
 }
 function e($q){
  return htmlentities($q,ENT_QUOTES);
 }
 function data($q){
  return f(q($q));
 }
 public function item($q){
  $item = data($q);
  return $item[0];
 }
 
For those of you who want a simple way to spin duplicate content.

PHP:
function spin($s){
 preg_match('#\[(.+?)\]#is',$s,$m);
 if(empty($m)) return $s;
 $t = $m[1];
 if(strpos($t,'[')!==false){
  $t = substr($t, strrpos($t,'[') + 1);
 }
 $parts = explode("|", $t);
 $s = preg_replace("+\[".preg_quote($t)."\]+is", $parts[array_rand($parts)], $s, 1);
 return spin($s);
}

$text = spin("[hi|hello] my [[last|first] name|name] is [bob|mike|frank]");

will return several variations, which could be:

hi my last name is mike
hi my name is frank
hello my first name is bob

etc
 
Psuedo PHP threads:

PHP:
function phpThread($u) {
 $fp = fsockopen("localhost", 80, $errno, $errstr, 5);
  if (!$fp){
   die("Can't connect to localhost");
  }
  $out = "GET /".$u." HTTP/1.1\r\n";
  $out .= "Host: localhost\r\n";
  $out .= "Connection: Close\r\n\r\n";
  fwrite($fp, $out);
  fclose($fp);
 }

localhost would need to be changed to whatever the host you are on is.
 
Last one for tonight.

Quick function to load a page using cURL

PHP:
function load($url,$pd=null){
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_TIMEOUT, 30);  
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
  curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)");
  if (!empty($pd)){
   curl_setopt($ch, CURLOPT_POST, 1);
   curl_setopt($ch, CURLOPT_POSTFIELDS, $pd);
  }
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  $page = curl_exec($ch);
  return $page;
 }

Usage:

$page = load("http://wickedfire.com");

with POST data

$page = load("http://google.com/search", "q=this+is+an+example");
 
using php functions

thanks for your valuable inforamtion . you write someting intresting regarding php function please specif with comments that will be easy for us to understand code easiy
 
I do agree with you matt .you can get earn money easily if you are creative and hav a differet ways ti sought out the problem. php is good option bt grtting money is not easy...you just be a creative.