Skip to main content

Posts

Showing posts with the label #PHP

Login with LinkedIn using PHP

Linkedin is one of the most popular social networks with the huge user base. Like the Facebook , Twitter and Google authentication, LinkedIn also is used for the user authentication in the website. If you want to allow your website’s user to login with the social account, LinkedIn login needs to be added. LinkedIn provides various API to integrate user login system in the website. Using LinkedIn API you can let the user login to your website with their LinkedIn account. In this tutorial, we will show you how to integrate user Login System with LinkedIn using PHP . The login with LinkedIn feature helps the user to sign into your website with their LinkedIn account without registration on your website. Our LinkedIn login API tutorial provides you an easy way to build user login system with LinkedIn using PHP and store the user profile data into the MySQL database. We’ll use OAuth library to connect with LinkedIn and build LinkedIn login system in PHP . Before you get started to int...

How to Export Data to CSV File using PHP and MySQL

CSV (comma-separated values) is the most popular file format to store tabular data in plain text. Generally, CSV file is used to import and export data for moving tabular data between programs. Import and export data is the most used feature in the web application, and CSV file format is a best chose for that. In the earlier tutorial, we have shown How to Import CSV File Data into MySQL Database using PHP . In this tutorial, we will show you how to export data from MySQL database to CSV file using PHP . Also, you will learn to create CSV file in PHP and download and save MySQL data in CSV file using PHP. To demonstrate Export to CSV functionality, we will build an example script which will export members data from the MySQL database and save in a CSV file using PHP. Create Table in MySQL Database The following SQL creates a members table with some basic fields in MySQL database. The members table holds the member’s information which needs to be exported. CREATE TABLE `memb...

PHP : detect location of the user

Using the below function you can check the city from which the user is visiting your website. function detect_city($ip) { $default = 'UNKNOWN'; $curlopt_useragent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)'; $url = 'http://ipinfodb.com/ip_locator.php?ip=' . urlencode($ip); $ch = curl_init(); $curl_opt = array( CURLOPT_FOLLOWLOCATION => 1, CURLOPT_HEADER => 0, CURLOPT_RETURNTRANSFER => 1, CURLOPT_USERAGENT => $curlopt_useragent, CURLOPT_URL => $url, CURLOPT_TIMEOUT => 1, CURLOPT_REFERER => 'http://' . $_SERVER['HTTP_HOST'], ); curl_setopt_array($ch, $curl_opt); $content = curl_exec($ch); if (!is_null($curl_info)) { $curl_info = curl_getinfo($ch); } curl_close($ch); if ( preg_match('{<li>City : ([^<]*)</li>}i', $content, $regs) ) { $city = $regs[1]; } if ( preg_match('{<li>State/Provinc...

Create secure login script in PHP

Recently more than 10 members asked me how to create secure login script in PHP. So in this article am going to explain you how to create a secure login system using PHP and MYSQL. This type of login system am using in most of the website, if you are using any CMS means no need of this system because CMS have inbuilt login system. In this method am mainly concentrating on the username and password strings. Am using number of steps to clear the string and prevent the any type of SQL injection to avoid the hacking. First we will start the session and connecting to the database. FInd the PHP code below, //Start session session_start(); //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select...

SMS Gateway Integration in PHP

These days SMS feature is used for the various purpose in the web application. For example user authentication, OTP verification, sending the notification to users. To send SMS from PHP script you need to select a best SMS gateway provider that suitable for your requirement. Once the SMS gateway and plan selection are completed, now it’s time to integrate SMS gateway in PHP script. In this tutorial, we will show you how to integrate SMS gateway API in PHP . SMS gateway integration process is very simple and less time required. Using our example code you can easily send SMS from your website using SMS gateway API and PHP . Usually, the SMS provider provides 3 types of plan, One-way messages, Two-way messages, and Both-ways messages. One-way messaging allow you to send SMS to the customers, but Two-way messaging allow not only the send SMS but also receive a reply from the customer. Generally, SMS gateway provides a callback URL for passing some parameters, like API Key, send...

Fetch Meta Data from URL using PHP and Ajax

In this tutorial am going to explain how to get meta data from an URL to display in website. It’s similar to URL data extracting. You can see this example most of social networking sites like Facebook and Google Plus. It also called as Extracting data from URL using Jquery, Ajax and PHP. I have used get_meta_tags PHP function to get the Meta data from URL. This is a PHP in built function. The output will be returned in array. $url=get_meta_tags("http://www.webinfopedia.com/"); This will give you an array of all Meta data like Description, Keyword, Author, Copyright, Robot etc… Now you need to display it like below. echo ($url["description"]); echo substr($url["keywords"], 0, 128); echo ($url["copyright"]); To get the title tag form URL am using file_get_contents function. echo get(file_get_contents('http://www.webinfopedia.com/'), ""); //get function function get($a,$b,$c) ...

Add Event to Calendar using jQuery, Ajax and PHP

In our first PHP event calendar tutorial, we had shown how to create an event calendar using jQuery, Ajax, and PHP . That tutorial provides the script for generating calendar and display events from the MySQL database on the respective date. In this second part of the PHP event calendar tutorial, we’ll show how to add events to the calendar using jQuery, Ajax, PHP & MySQL. Means we’ll extend our PHP event calendar script with add event functionality. Before you begin, we suggest you read the first part of PHP event calendar tutorial . It will help to understand our event calendar scripts. Build an event calendar using jQuery, Ajax and PHP Files structure of PHP Event Calendar would be the same as the first part. Here we’ll use the same scripts but the event adding code will be added. Open the functions.php file and make the following changes. Add addEvent case on switch-case in functions.php file. case 'addEvent': addEvent($_POST['date'],$_POST[...

Convert HTML to PDF in PHP with Dompdf

PDF is a file format created by Adobe Systems for illustrating text and images in a fixed-layout document. PDF is used to downloading the bunch of data or text content in the web application. PDF file format is the perfect choice to download the text or HTML content in a file. At the time of download web page content as PDF file, it requires converting HTML to PDF. In this tutorial, we will show how to convert HTML to PDF and generate PDF file using PHP . Dompdf is a PHP library that provides a simple way to convert HTML to PDF file . Using Dompdf library you can easily generate PDF from HTML page in PHP. The example script will help you to implement PDF generation functionality in the web application and make it simple to convert HTML to PDF in PHP with Dompdf . Dompdf Installation & Setup Download stable release of dompdf from GitHub . Extract the downloaded dompdf package and rename it with dompdf . Alternatively, you can download our source code to get all the required ...

Load Data on Page Scroll using jQuery Ajax PHP from MySQL Database

Previously we’ve published many tutorials on load data from MySQL database in PHP. For example our last article – Load more data using jQuery Ajax and PHP , where data are loaded from the database by clicking on the load more link. But in this article, we’ll do it differently. This tutorial will show an automatic process to load more data from the database in PHP. Here we’ll build script for load data on page scroll using jQuery, Ajax, and PHP . It will be very user-friendly because the data would be loaded from the MySQL database automatically while scrolling the page down. Users are not needed to click any link for data load. Let’s start the Load Data on Page Scroll with jquery and PHP tutorial. Before you begin, take a look on files structure. Database Table Creation Create a table named posts into the database (for example codexworld ). Example SQL query for creating posts table is given below. CREATE TABLE `posts` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` varcha...

Delete All Files from Folder using PHP

Sometimes you need to free the space of the web server by deleting old or specific or all files from a directory. Means you want to remove files from the folder without know the name of the files. This type of functionality required for the following situation. Need to remove all files in a folder for free the space of web server. Need to remove old files in a folder which are used before the specific time. Need to remove some files from a folder which holds a specific extension. And much more. In this short article, we’re going to write a simple PHP script to unlink or delete all files from folder or directory. There is no need to know the files name. To delete files from directory we’ll use glob() and unlink() functions in PHP. glob() function is used to get filenames or directories as an array based on the specified pattern. unlink() function is used to delete a file. Here the PHP code is provided for three situations. In these situations, you should need to delete...

PHP CRUD Operations without Page Refresh using jQuery Ajax MySQL

CRUD stands for Create, Read, Update and Delete database records. Add, Edit, Update, and Delete functionality is used almost every web project in PHP. You’ve done it many times, but today we’ll show you the more user-friendly way to implement CRUD functionality in PHP . Here we’ll implement PHP CRUD operations without page refresh using jQuery, Ajax, and MySQL. The functionality of the example script would be read, add, update, and delete the records from MySQL database. In this example script, we’ll fetch the users data from the database and display the user data list with add link, edit link, and delete link. By these links user can add new data to the database, update previously inserted data and delete the data from the database. All operations will happen on a single page without page refresh. Also, bootstrap table structure will be used for styling the list, form fields, and links. Let’s start the step-by-step guide on creating a CRUD application with PHP using jQuery Ajax MySQL...

How to Force Download File in PHP

To download a file in PHP, you need to force the browser to download file except display. In this article, we are going to show how to download a file from directory or server in PHP. Using header() and readfile() function, you can easily download a file in PHP. Here we’ll provide the example PHP code to force download file in PHP. Also, this simple PHP script helps to implement a download link which downloads a file from the directory. The following example script can be used for download any types of file like text, image, document, pdf, zip, etc. Download a File in PHP $fileName = basename('codexworld.txt'); $filePath = 'files/'.$fileName; if(!empty($fileName) && file_exists($filePath)){ // Define headers header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=$fileName"); header("Content-Type: application/zip"); header(...

Get YouTube Video Thumbnail Image URL using PHP

In the present day, YouTube embed video is used on many websites. Many web project needs to implement a YouTube video gallery where YouTube video thumbnails are dynamically listed in the gallery. In this article, we’ll provide the short PHP snippet to get YouTube video thumbnail image URL using PHP. This simple PHP script is very useful when you want to get the YouTube video thumbnail image URL dynamically based on the provided YouTube URL. Using this YouTube thumbnail URL, you can design the video gallery as per your project needs. Get Thumbnail Image URL from YouTube Embed Code The following PHP code extracts the src value from YouTube Embed Code and generates the video thumbnail image URL based on YouTube video ID. $embedCode = '<iframe width="560" height="315" src="https://www.youtube.com/embed/dwJasig9Olw" frameborder="0" allowfullscreen></iframe>'; preg_match('/src="([^"]+)"/', $embedCode, $match)...

PHP OOP CRUD Operations using PDO Extension and MySQL

In the earlier article, we’ve already published PHP CRUD functionality tutorial using Ajax . There we’ve using MySQLi to connect database and database-related operations. After publishing that article we received many requests from our readers for PHP CRUD tutorial with PDO extension and MySQL . They also mentioned that they are waiting for our tutorial because complete and clear PHP MySQL PDO tutorial was not found after huge searching. Waiting is over! Here we’ll show the view, add, edit, update, and delete operations using PDO in PHP. The PHP Data Objects (PDO) extension defines a consistent, lightweight interface for accessing databases in PHP. PDO extension provides a data-access abstraction layer, which means that you can use different databases using the same functions to queries and fetch data from the database. In this PHP PDO tutorial, through implementing the simple PHP CRUD operation you’ll learn PDO connection, PDO insert, PDO select, PDO update, PDO delete query managemen...