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 !

Linux Run SCP command in background

Linux Run SCP command in background

Here is how you can keep the SCP command running even after closing the remote shell (e.g Putty)

Keep Process In Background

  1. Open ssh terminal to remote server.
  2. Type your scp command as normal
  3. Background the scp process by entering Ctrl+Z, then typing the command bg
  4. Disown the background process by typing disown
  5. Close the SSH session and you will see that it is still running

Verify Process Is Running

You can verify that it is running by checking the remote destination size. For example, using the command du -s <directory> to check a directory size, or ls -l <filename> to check a file size

Enjoyed the content ? Share it with your friends !

WordPress Find Categories By Name

WordPress Find Categories By Name

The below works for both categories, and other custom taxonomies (e.g genres) you may have.

Find category by an exact match

$cat = get_term_by( 'name', $cat_name, 'category' );

Find category by partial match anywhere

$categories = get_terms( 'category', array( 'name__like' => 'cat_name' ) );

Find category by partial match from the start of the string

$categories = get_terms( 'category', array( 'search' => 'cat_name' ) );
Enjoyed the content ? Share it with your friends !

LiteSpeed Redirect Traffic To HTTPS with CyberPanel

LiteSpeed Redirect Traffic To HTTPS

To redirect traffic from http to https, you can use rules that are the same as you would use in that of apache. So, for example, the below rules will help in https redirection

RewriteCond %{HTTPS} !on
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

If you are using CyberPanel, then you can edit the rules by going to your individual web panel for your domain, and clicking Rewrite Rules as shown below.

CyberPanel Rewrite Rules

After clicking it, I suggest you put the rule at the top of the file so that the redirection is processed before any other rule.CyberPanel Rewrite Rules FileAfter which, you just have to save the new rules and your good to go.CyberPanel Rewrite Rules Save

 

Enjoyed the content ? Share it with your friends !