Posts

Showing posts with the label PHP

Condition based MySQL left join with CASE

Image
Happy to write post after long time :) I had a scenario that there is are some fields in a table like `id`,`group`,`object_id`. `group` field(ENUM) has three groups named `user`, `deal`, `scene` and `object_id`(it will have the primary key for corresponding group). ie., If the row has group name of `user`, then `object_id` refers to `user_id` and if the row has group name of `deal`, then object id will refers to `deal_id`. What i want to achieve is i need to have a field called `name` in result so that if the current row group is user then username should be displayed in `name` field and if the row group is `deal` then the `name` field should have `deal_name`.

Get latitude and longitude using google map api - PHP

Google provides an API to get latitude and longitude based on the valid address. All we need to do is just pass address to that api. We can able to get response in various format. In below code i’m requesting api to return response a json format. If curl is enabled in your server you can use below function to get latitude and longitude by passing just address. function getLocation($address = null){ $url = 'http://maps.googleapis.com/maps/api/geocode/json?address='.rawurlencode($address).'&sensor=false'; $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL,$url); $result=curl_exec($ch); $res = json_decode($result, true); if(isset($res['results'][0]['geometry']['location'])){ return $res['results'][0]['geometry']['location']; }else{ ...

Migrate Twitter API from Version 1 to 1.1

My twitter feed response is started showing below message when i was tried to access users_timeline using this URL https://api.twitter.com/1/statuses/user_timeline.xml?include_entities=true&include_rts=true&screen_name=karthi0110&count=1 “The Twitter REST API v1 is no longer active. Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview.” I have tried by replacing version 1 to 1.1 in the request URL https://api.twitter.com/1.1/statuses/user_timeline.xml?include_entities=true&include_rts=true&screen_name=karthi0110&count=1 it shown “Bad Authentication data” error. So after some research i have fixed it in a proper way. If you are getting this error just migrate it to version 1.1 by following below steps. Process is easy Create App -> Get access codes -> Configure -> Start displaying your feed Go to https://dev.twitter.com/apps/new and fill the form fields like Name, Description, Website.. in-order to create your app. Now ag...

WePay Crowdfunding Payment integration in cakephp

How to implement WePay payment in CakePHP? Here is an idea that how to implement the WePay in cakePHP less than 10 mins! Follow the given steps to implement WePay on your cakePHP app.

Convert long url to short url using tinyurl api

Tinyurl provides us a short and simple service to convert long URL to small(tiny) URL. We can send email without link breakage. Here is the tinyurl api to get shorten url. You can use any of the method. Method 1: Use file_get_contents to fetch tinyurl. echo file_get_contents('http://tinyurl.com/api-create.php?url=http://www.websnippetz.com'); file_get_contents is not working? If your are able to access php.ini file set allow_url_fopen = On or you can use the below method. Method 2: Use cURL (runs faster than file_get_contents) to fetch tinyurl. function get_tiny_url($url) { $url = "http://tinyurl.com/api-create.php?url={$url}"; $ch = curl_init(); $timeout = 5; curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); $data = curl_exec($ch); curl_close($ch); return $data; } echo get_tiny_url('http://www.websnippetz.com');

Send email from xampp localhost

Send email from xampp localhost. Follow the easy steps Goto http://glob.com.au/sendmail/ , download latest sendmail package. Extract the zip file and copy the files into your \xampp\sendmail folder(Replace every file in the existing folder). Update the sendmail.ini file in sendmail folder with the following details, and make sure it is not commented(;). smtp_server=smtp.gmail.com smtp_port=25 error_logfile=error.log debug_logfile=debug.log auth_username=yourname@gmail.com auth_password=gmailpassword force_sender=yourname@gmail.com Here i have added gmail account for sending emails. Open xampp\php\php.ini file find sendmail_path and update its value to "\"C:\xampp\sendmail\sendmail.exe\" -t" . Now it will look like below sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t" Make sure it's not commented(;) Restart your apache server. Now you can send email from xampp localhost! enjoy :-)

Unzip file in server using PHP ZipArchive

Once i wanted to upload WordPress folder which contains 1000's of files, if i choose to upload those files using FTP it will take much time.

Clear form fields after finishing ajax submit using Jquery

Use reset() method to clear form fields after submitting the form via ajax.

Download files from multiple URL s and download it as zip format

Hello friends, here is the code for how to download files from multiple url and download is as zip format in PHP. If you have any doubt in PHP function's please refer php.net. Let's start!!! We can give url's as array format like below <?php $urls = array( 'http://skidvis.com/WordpressCheatSheet.pdf', 'http://andywibbels.com/files/WordPress_Cheatsheet_v1.pdf' ); ?>

Passing Javascript variables to PHP

It's easy to get Javascript variable into PHP. What you have to do is follow below code. //in script block var veg = 'Carrot'; //in php block $veg = "<script type='text/javascript'>document.write(veg);</script>"; echo 'Printed My JS variable into PHP: '.$veg; Result will be: Printed My JS variable into PHP: Carrot