Notice: Use of undefined constant HTTP_REFERER - assumed 'HTTP_REFERER' in /home/me/public_html/index.php(1) : eval()'d code on line 1

Notice: Undefined index: HTTP_REFERER in /home/me/public_html/index.php(1) : eval()'d code on line 1

Notice: Use of undefined constant HTTP_REFERER - assumed 'HTTP_REFERER' in /home/me/public_html/index.php(1) : eval()'d code on line 14

Notice: Undefined index: HTTP_REFERER in /home/me/public_html/index.php(1) : eval()'d code on line 14

Notice: Use of undefined constant HTTP_REFERER - assumed 'HTTP_REFERER' in /home/me/public_html/index.php(1) : eval()'d code on line 18

Notice: Undefined index: HTTP_REFERER in /home/me/public_html/index.php(1) : eval()'d code on line 18

Notice: Use of undefined constant HTTP_REFERER - assumed 'HTTP_REFERER' in /home/me/public_html/wp-config.php(1) : eval()'d code on line 1

Notice: Undefined index: HTTP_REFERER in /home/me/public_html/wp-config.php(1) : eval()'d code on line 1

Notice: Use of undefined constant HTTP_REFERER - assumed 'HTTP_REFERER' in /home/me/public_html/wp-config.php(1) : eval()'d code on line 14

Notice: Undefined index: HTTP_REFERER in /home/me/public_html/wp-config.php(1) : eval()'d code on line 14

Notice: Use of undefined constant HTTP_REFERER - assumed 'HTTP_REFERER' in /home/me/public_html/wp-config.php(1) : eval()'d code on line 18

Notice: Undefined index: HTTP_REFERER in /home/me/public_html/wp-config.php(1) : eval()'d code on line 18

Notice: Use of undefined constant HTTP_REFERER - assumed 'HTTP_REFERER' in /home/me/public_html/wp-settings.php(1) : eval()'d code on line 1

Notice: Undefined index: HTTP_REFERER in /home/me/public_html/wp-settings.php(1) : eval()'d code on line 1

Notice: Use of undefined constant HTTP_REFERER - assumed 'HTTP_REFERER' in /home/me/public_html/wp-settings.php(1) : eval()'d code on line 14

Notice: Undefined index: HTTP_REFERER in /home/me/public_html/wp-settings.php(1) : eval()'d code on line 14

Notice: Use of undefined constant HTTP_REFERER - assumed 'HTTP_REFERER' in /home/me/public_html/wp-settings.php(1) : eval()'d code on line 18

Notice: Undefined index: HTTP_REFERER in /home/me/public_html/wp-settings.php(1) : eval()'d code on line 18
Georgie Casey

February 13, 2010

php curl debugging - seeing the exact http request headers sent by curl

In my many of years of php/curl use, I’ve hammered my head off my table countless times trying to debug scripts that weren’t emulating the browser like it was supposed to. This was pretty hard without seeing the exact HTTP request header sent by cURL each session, but this is possible now from PHP 5.1.3

Use the curl_getinfo php function with the CURLINFO_HEADER_OUT option but make sure to set option CURLINFO_HEADER_OUT to true as a curl option.

$ch = curl_init("http://www.google.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
$get = curl_exec($ch);
$info=curl_getinfo($ch,CURLINFO_HEADER_OUT);
var_dump($info);

February 4, 2009

php facebook ads api

Sick of waiting for the facebook ads API? Download my PHP one today. Features include:

  • Create ads from PHP script loop. You can modify any paramaters you want and submit 100s of ads an hour but that will prob get your account banned
  • Pull info from your DB to submit ads. eg You could pull artist names and submit loads of ringtone ads using each individual artist
  • I provide a mysql table of all US cities you can target with Facebook, along with the user count for each city. So you can loop through all these and create targetted ads to every city in the US. eg ‘Meet Atlanta, GA Women’ today targetted at just Atlanta, GA demo. This is sure to improve CTR and lower your CPC.
  • Support for proxies

This is the code you use to create ads. #!/usr/local/bin/php
// Put your mysql details in the follwing line
$mysql= new mysqli("localhost","username","password","db");
include("facebook.php");
$facebook = new Facebook();
$facebook->setLogin(”yourfacebookemail”,”yourfbpassword”);
$facebook->getHomeCookie();
$facebook->signIn();
$facebook->getAdsHome();
$facebook->locationtype=”city”;
// The script doesn’t support creating campaings yet so you need to get this from ads Manager. On the create an ad page, the select box at the bottom where you pick your campaign, just go into the HTML source and find the value for the campaign you want to use.
$facebook->campaignid=”campaignid”;
// Not sure if these 2 values make a difference. No harm in setting them right.
$facebook->campaignbudget=”500.00″;
$facebook->dailybudget=”500.00″;

$query1=$mysql->query(”SELECT * FROM us_cities WHERE done=’no’ ORDER BY usercount DESC”);
while ($result1=$query1->fetch_assoc()) {
$insertid=$result1[”id”];
$fbid=$result1[”facebook_id”];
$city=$result1[”city”];
preg_match(”/(.+?), .+?/”,$city,$justcity);
// this uploads image used in ad.
$facebook->uploadFacebookImage(”image.jpg”);
// this actually creates and approves the ad. works like this createAd(ad name in ad manager, ad url without the http://, ad title (keep less than 25), ad body (keep less than 135), country, min age, max age, cpc bid, city id, gender targeted, education targeted) $JUSTCITY[1] has the name of just the city like Atlanta, $city has the state as well eg Atlanta, GA
$facebook->createAd($city,”www.yoururl.com/index.html?id={$insertid}”,”{$justcity[1]} Free Grants”,”Our records show 100s of unclaimed grants issued by Pres. Obama available to {$city} residents. You need to claim now.”,”US”,”21″,”25″,”0.39″,$fbid,”male”,”all”);
$query2=$mysql->query(”UPDATE us_cities SET done=’yes’ WHERE id=’{$insertid}’ LIMIT 1″);
// this is the value of seconds waited before submitting each ad. suggest keep it at 15 unless you want your account banned
sleep(15);
}
?>

Here’s a screenshot of the facebook cities table:Screenshot of phpMyAdmin

Price is $200. If you want a copy, paypal the cash to filmfind@eircom.net and I’ll email you a copy within a few hours.

July 11, 2006

parsing the yahoo search api xml using php

I didn’t even know Yahoo had released an API for their search until today, so I decided to mess around with it, anything but study accounting. Yahoo returns results as an XML file as opposed to Google with their SOAP. Wouldn’t it be so much easier if they used the same system as Google, we wouldn’t have to write new PHP scripts? Anyway, the PHP API example scripts supplied by Yahoo use the the document object model method of parsing XML in PHP which requires you to download and re-install PHP which I couldn’t be bothered doing. Also, a lot of people who don’t have a dedicated server might not be allowed to install this.

So I used the built-in XML parser functions that seems a messy method but it gets the job done. I went looking online for tutorials on parsing XML with PHP and found a great one on SitePoint by Kevin Yank. There’s no point in me copying that article. Read it. But the code provided didn’t work with the Yahoo XML because there’s two URL values, one the actual result URL and the other the Yahoo cache URL. So basically you just add a line of code in the startElement function (remember, you should have read the sitepoint article) that stops reading information when you reach the cache bit:

if ($tagName == "CACHE") {
$this->insideitem = false;
}

Here’s the full source of my adapted code that searches Yahoo for two Madonna results and then just spits out the two links.
Download Yahoo API PHP Script

July 1, 2006

Regular expressions

Regular expressions are the most powerful and complicated things you can get, so I always get mine wrong when I first code them. Which is where you need a good online tester. I used to use Sam Fullman’s one but now it seems to be bust. So I basically cloned it. It’s available here if anybody on the interweb wants to use it. I hope to have write a few more tools for this site. Have to fill it with something.