Saturday, May 28, 2016

Decodes a complex JSON string and converted into associative arrays using php

Call a API 
 $jsonurl = "https://api.coindesk.com/v1/bpi/currentprice/USD.json";  
 $json = file_get_contents($jsonurl); 
 echo var_dump(json_decode($json)); 

Which will return this

 object(stdClass)[5]  
  public 'time' =>   
   object(stdClass)[6]  
    public 'updated' => string 'May 29, 2016 06:05:00 UTC' (length=25)  
    public 'updatedISO' => string '2016-05-29T06:05:00+00:00' (length=25)  
    public 'updateduk' => string 'May 29, 2016 at 07:05 BST' (length=25)  
  public 'disclaimer' => string 'This data was produced from the CoinDesk Bitcoin Price Index (USD). Non-USD currency data converted using hourly conversion rate from openexchangerates.org' (length=155)  
  public 'bpi' =>   
   object(stdClass)[7]  
    public 'USD' =>   
     object(stdClass)[8]  
      public 'code' => string 'USD' (length=3)  
      public 'rate' => string '519.1350' (length=8)  
      public 'description' => string 'United States Dollar' (length=20)  
      public 'rate_float' => float 519.135  

Or as plain json return

 {"time":{"updated":"May 29, 2016 03:59:00 UTC","updatedISO":"2016-05-29T03:59:00+00:00","updateduk":"May 29, 2016 at 04:59 BST"},"disclaimer":"This data was produced from the CoinDesk Bitcoin Price Index (USD). Non-USD currency data converted using hourly conversion rate from openexchangerates.org","bpi":{"USD":{"code":"USD","rate":"516.4050","description":"United States Dollar","rate_float":516.405}}}  
Now we want to get data as associative arrays

 $jsonurl = "https://api.coindesk.com/v1/bpi/currentprice/USD.json";  
 $json = file_get_contents($jsonurl);  
 $obj = json_decode($json);  
 echo $obj->bpi->USD->{'rate'}; // show the rate   

Thursday, May 12, 2016

Popup new window center screen php javascript

First Create a javascript function for popup window. w=width , h=height of the window
 // Popup windows   
 function popupwindow(url, title, w, h) {  
        var left = (screen.width/2)-(w/2);  
        var top = (screen.height/2)-(h/2);  
        return window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);  
 }  

Now make a php function to use this java-script function everywhere in php easily.

 /**  
  * Return pop up   
  * @author Sharif Ahmed  
  * @param str url  
  * @param str title/value  
  * @param int width  
  * @param int height  
  * @return return popup center windows  
  */  
 function my_anchor_popup($url,$title,$width,$height)   
   {  
     return '<a href="'.$url.'" onclick="popupwindow(\''.$url."','".$title."', '".$width."','".$height."'); return false;\">".$title.'</a>';  
   }   

Sunday, May 1, 2016

Point website to somewhere else, but keep email on cpanel/server

Think I have a domain mydomain.com and my website which is hosted in a cpanel / web server like serverplushost.com . All my email is also running in serverplushost.com.

But now i want to move my website to other server/ dedicated server(like IP 123.124.125.126) but keep email on serverplushost.com as it was before.

1. Login cpanel of  mydomain.com. Click on Advanced DNS zone/ Simple DNS zone.

2. Add A record  name mydomain.com and to the new server IP 123.124.125.126. Also add a CNAME for www.mydomain.com to point mydomain.com. (If there is already have one then edit it).

3. Add A record for webmail.mydomain.com and IP of serverplushost.com (default cpanel IP).
(it's possible that you already have a mail.mydomain.com / webmail.mydomain.com CNAME - delete that and only keep the A record).


So www.mydomain.com and mydomain.com is now pointed to new server IP and webmail.mydomain.com is now pointed to default cpanel hosting.

Total Pageviews