James Bachini

php

  • REGEX | A Complete Guide With Examples

    REGEX | A Complete Guide With Examples

    Regexes are a powerful way to do search queries on a text string. They can be used to replace text, sanitize user inputs and much more. Contents Introduction to REGEX REGEX Cheatsheet REGEX Examples REGEX Javascript Code An Introduction to REGEX A REGEX or regular expression is used to match text strings in many programming…

  • A simple iOS / Android traffic splitter in PHP

    A simple iOS / Android traffic splitter in PHP

    The following basic PHP code will split traffic by device with iOS traffic going to the first out link, Android to the second and leftovers to the third. TIP: This uses a 301 redirect however you can do any type of programmatic variation based on the user agent. You can copy and paste this into…

  • RAM & CPU Usage PHP Script | Server Health Check

    RAM & CPU Usage PHP Script | Server Health Check

    This single file server health check script works on Windows, Linux and possibly others. It is written in PHP to show CPU usage, RAM usage, Incoming Connections and Hard disk usage. Update September 2020 Server Check PHP was getting a lot of downloads so I’ve updated the code and open sourced it on Github. If…

  • Setting up Maxmind GEOIP2 Legacy Database with PHP or Javascript

    This is the php code I use to access geoip data from Maxmind’s geoip database: <?php $gpath = getcwd() . “/GeoIPCity.dat”; if (isset($_SERVER[‘HTTP_X_FORWARDED_FOR’])) { $myip = $_SERVER[‘HTTP_X_FORWARDED_FOR’]; } if (isset($_SERVER[‘REMOTE_ADDR’])) { $myip = $_SERVER[‘REMOTE_ADDR’]; } include(“./geoipcity.inc”); $gi = geoip_open($gpath,GEOIP_STANDARD); $record = geoip_record_by_addr($gi,$myip); $city = $record->city; $countrycode = $record->country_code; geoip_close($gi); echo ‘countrycode = “‘.$countrycode.’”; city =…

  • Passing Through Landing Page Variables

    This was inspired by another post which is well worth a read at: http://affplaybook.com/blog/affiliate-marketing/the-ultimate-guide-to-landing-page-tricks/ So many traffic sources provide you with tags such as {keyword} {countrycode} {device} etc. You can add these variables to your url so it would look something like: http://www.myserver.com/landingpage.htm?kw={keyword}&device={device} Then in the code to your landing page you can access these…

  • Email Bounce Handling

    Here’s some PHP code developed to handle bounced email responses. This will give each response a code to $resno and a category to $rescat. There are 4 categories: Unknown – Hard bounce user or email address isn’t valid Spam – Soft bounce, blocked by spam filters Full – Soft bounce, user is out of resources…

  • Coding PHP for Affiliates | A Getting Started Guide

    Coding PHP for Affiliates | A Getting Started Guide

    Coding for me is one of the most important skills you can have as an affiliate marketer. I’ve met plenty of affiliates that are running huge volume, making millions and can’t write a single line of code. “I just outsource it all” but for me I couldn’t imagine coming up with a tweak to a…

  • Direct Linking and Retargeting

    Here is how to do it, you’ll still need a server and a domain. Point all your traffic towards a php file i.e. http://www.mydomain.com/trackandforward.php Then place all your retargeting pixels in to the trackandforward.php file and put a meta refresh at the the end. The page will load the retargeting cookies will be placed and…

  • Automatic backup of MySQL database

    Would you like to have a backup of your critical MySQL database emailed to you automatically? The following script was moified from backup2mail and needs setting up as a cron job, instructions are in the code. Download it for free here This is what the code looks like: <?php /// Setup /// // Test it…

  • First Steps in Automation

    First Steps in Automation

    One of the great things about this industry is the lifestyle flexibility it offers you. The dream is to setup a campaign or website, let it run itself and live off the money tree you’ve made. In reality it rarely works like this but automation can release hours off your daily routines and go some…

  • Redirection Methods and Referer Passing

    The following are some methods you can use to redirect users from one place to another. I generally use 301 redirects for anything where I want the referer passed through because this is the fastest. Double meta refresh for anything where blank referer is important and a custom script which incorporates the form submit redirect…

  • Prosper202 Mod – Set preferences before crashing server

    Had a bit of an issue with Prosper crashing once the database got too big. I would log out and leave the analysis preferences set to my biggest traffic source and when I logged back in the server would crash as it tries to pull a report before you can modify the search critieria. I…

  • Rotating Offer Pages and Landing Pages in Prosper202

    It is really easy to setup rotation of urls in Prosper but if you actually want to track which url is doing better or you want to test different landing pages it can be a little more challenging. One way to do this is to set each url or landing page up separately and then…

  • Prosper 202 Mods 2012

    Prosper202 mods 1) increase session life – stops it logging you out every five minutes when you are trying to work add the following line just before session_start(); in 202-config/connect.php ini_set(‘session.gc_maxlifetime’,99999); 2) bypass adverts on first page – bit naughty but I prefer to jump straight into the spy section to see whats been going…

  • Custom Facebook Share and Twitter Tweet Buttons as WordPress Widget

    The following is the php code to make your own dynamic Facebook share and Twitter tweet buttons. Just place the images in the root directory and install the Samsarin PHP widget. Copy this code into a Samsarin Php widget and drag it to your sidebar. <a target=”_blank” href=”http://www.facebook.com/sharer.php?u=<?php echo “http://” . $_SERVER[‘HTTP_HOST’]  . $_SERVER[‘REQUEST_URI’]; ?>”><img…

  • Custom WordPress 404 Page For SEO

    I have recently been purchasing used domain names from Godaddy Auctions and Dropcatch. When I get the domains the first thing we do is look at what traffic they were pulling for what topics via google cached web search. If there is some good content on there and things we want to keep we will…

  • Setting up custom facebook and twitter buttons using php

    The canonical tag has been a god send for us helping to get pages indexed and clean up site structures. In many sites we use the same php variable for our share buttons. This is a great way to setup custom twitter and facebook share buttons for your pages. We always use an external template…

  • Mixing php with javascrip – Heredoc

    My main issue with javascript is the fact it is full of ‘ and ” which can be a real pain when coding. I’ve started using a method called heredoc to set a start and end point, example below. // Heredoc string // $sstring = <<<TEST Hello World TEST; The word TEST could be anything…

  • Poor mans GeoIP – Quick and Easy Geolocation

    //poor mans geoip $country=trim(file_get_contents(“http://api.hostip.info/country.php?ip=”.$_SERVER[‘REMOTE_ADDR’])); //You can then redirect customers to different offers depending on country. I wouldn’t recommend this for critical or high volume use. if ($country == ‘MyCountry’) { yadda yadda yadda; }

  • Two php functions for scraping content and extracting links

    ////// Grab webpage ////// function webFetcher($url) { $crawl = curl_init(); curl_setopt ($crawl, CURLOPT_URL, $url); curl_setopt($crawl, CURLOPT_RETURNTRANSFER, 1); $resulting = $resulting.curl_exec($crawl); curl_close($crawl); return $result = $resulting; } //////////////////////////////// //// extract links //// function extract_links($text) { preg_match_all(‘/<\s*a[^<>]*?href=[\’”]?([^\s<>\’”]*)[\’”]?[^<>]*>(.*?)<\/a>/si’, $text, $match_array, PREG_SET_ORDER); $return = array() ; foreach ($match_array as $serp) { $full_anchor = $serp[0]; $href = $serp[1]; $anchortext =…

  • Three ways to debug php

    Method 1 – error.log For this to work you need to be coding in a linux environment with php, apache etc setup. This is the best way I have found and what I currently use to debug my applications/web pages. open up a new terminal and type: tail -f /var/log/apache2/error.log This will give you a…

  • list to php array list2phparray

    Code below for a script to take a list and turn it into an array. Comes in pretty useful. <?php if ($_POST[‘list’]) { $splist = explode(“\n”, $_POST[‘list’]); $out = ‘$x = array(‘; foreach ($splist as $line) { $out = $out.”‘$line’, “; } $out = substr($out,0,-1); $out = substr($out,0,-1); $out = $out.’);’; echo $out; } else…

  • Dynamically modifying the landing page with TrafficVance using php

    Dynamically modifying the landing page with TrafficVance using php

    I ran into a silly issue today when dynamically modifying a landing page using TrafficVance. The script I was using was a pretty straight forward: <?php if ($_GET[‘t202kw’]) { $kw = strip_tags($_GET[‘t202kw’]); } if(strpos($kw,’jetinternetmarketing.co.uk’) !== false) { $page = ‘<h1>Dont target JiM on traffic Vance</h1>’; } ?> The problem was that the url I was…