PHP PhantomJS Change User Agent String

PHP PhantomJS Change User Agent String

Noticed that google isn’t really useful in this case (there’s no copy and paste answer). Google for me only shows a bunch of people having issues and no easy solution when in fact the solution is quite simple

First things first, you have to check to see if your PHP-PhantomJs library version is 3.x or 4.x

If it is 3.x, to change the user-agent string, you just have to do this

$request->addSetting('userAgent', 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0');

If it is 4.x, to change the user-agent string, you just have to do this

$request->addHeader('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0');

Of course, feel free to change the new value of your user-agent to whatever you want it to be.

To verify that it is working, if your testing locally, then you can use tools such as Fiddler to check the headers. Alternatively, you can dump out the $request and $response variables, like so,

var_dump($request); // $request is the return value of either createRequest or createCaptureRequest function
var_dump($response); // $response is the return value of createResponse function

If you have any questions feel free to let me know in the comments below.

 

 

Enjoyed the content ? Share it with your friends !

List Of Free CDNs To Speed Up Your Site

List Of Free CDNs To Speed Up Your Site

The order of which I am listing the CDNs are random, and does not testify as to how good or bad they are.

  1. Cloudflare
    Cloudflare has always been a popular free solution among many users and can certainly how to boost your website’s loading time by a large margin.
    Some of the features offered by CloudFlare:

      • Globally load balanced CDN
      • Large PoP network
      • Rocket Loader
      • Content caching with controls such as instant purging
      • HTTP/2 and SPDY
      • DDoS protection
      • Page rules
      • Bot and spam protection
  2. Incapsula
    Incapsula is a less known alternative to Cloudflare. It is, however lacking features that Cloudflare has, but nonetheless a good alternative if you are not satisfied with Cloudflare.
    Some features they offer are :

      • Globally load balanced CDN
      • IPV6
      • Bot and spam protection
      • Statistics and monitoring tools
  3. Site Accelerator (formerly Photon) by Jetpack
    Site Accelerator, formerly known as Photon, is a free image CDN targeted at WordPress users. So, if you have a site that uses WordPress and has many images, this is a great free CDN that can help to speed up your site for your user. As you should know, images take up a large portion of a visitor’s loading time on the page.
  4. Netlify
    Netlify is not your typical CDN in that they do not work they same way as how a CDN usually do. Instead, Netlify targets users who wishes to host their static site but yet have great loading times by loading your static sites via their CDN.
  5. INXY
    INXY has 35 POPs in USA and Europe, and 48 POPs globally. They offer a free plan of 10GB traffic in USA and Europe, and a free plan of 5GB traffic globally. Although not much, it is certainly great for sites that are low in traffic, but yet still wishes to boost their site’s speed while keeping costs low.
  6. Gullo CDN
    Gullo CDN is a new CDN targeted for users in the USA. Currently, it is a USA-only CDN, meaning that the POPs they have are all based in USA.
Enjoyed the content ? Share it with your friends !