Posts marked with "PHP" in categories

Create Your Own URL Shortening Service Using PHP & jQuery

I made a URL shortening service a year back using PHP & jQuery. It was pretty simple. You should know the concept of URL Shortening. The concept is simple. When a user sends a request to short a URL, PHP will check if the URL is valid. If it’s valid then PHP will make a string of 5 or 6 characters. A folder is created with the name of this string and an index.php file with header function code is created in this folder. This will make the folder redirect to the URL the user requested. Since it’s a folder no extensions will be seen ! So You can make up some pretty good URL‘s.

... [READ MORE]

Uploading An Image Using AJAX In jQuery With PHP

As you know AJAX is the method of sending data without refreshing the page. Now I’m going to tell you how to upload images using AJAX in jQuery. For This You need to Download the jquery.form plugin from here. The Minimum requirement for this plugin is jQuery version 1.5 or later.

A Sample of uploading image using AJAX in jQuery is shown below :

<div>
  Now Let&#8217;s start on the code. Here is the <b>HTML</b> page :
</div>

<div>
  <pre class="prettyprint"><code>&lt;!DOCTYPE html&gt;

<html> <head> <script src="//code.jquery.com/jquery-latest.min.js"></script> <script src=“http://malsup.github.io/jquery.form.js"&gt;&lt;/script> </head> <body> <form action=“upload.php” method=“POST” id=“uploadform”>   <input type=“file” name=“file”/>   <input type=“submit” value=“Upload”/><br/><br/>   Message :   <div id=“onsuccessmsg” style=“border:5px solid #CCC;padding:15px;"></div> </form> </body> </html>

... [READ MORE]

Send Email using GMail SMTP server in PHP

This tutorial was suggested by SWDS. To send an e-mail using GMail’s SMTP server, you need extra help. Download the latest version of Swift Mailer Package from here.
This mailing class is simple, that’s why I recommend you to use Swift Mailer.
If you have enabled application specific password feature on Google Accounts, you may have to generate a new application password and use that password for SMTP authentication. Otherwise the example won’t be able to login to your google account.

... [READ MORE]

Execute Command Without Waiting For It To Finish

If you just execute a terminal command using exec or system in PHP, the page will only load completely until the command has been finished. If you are running commands to run a websocket server, the page will not load, because the start server command won’t terminate. So to avoid this problem you should just do a simple trick, Just add > /dev/null & after the command you’re running.
Here is a quick example :

... [READ MORE]

Upload Image To Remote Server With PHP cURL & Handle File in Remote Server

If you want to upload images to an external server which is uploaded to your site by a client, you are at the right tutorial.
For this submission we will use 2 files :

  1. form.php – The Page Where we will show the client the form. This file also sends the uploaded data to the external server.
  2. handle.php – The Page on the external server which receives the uploaded data from form.php using cURL.

We won’t copy the uploaded file by the client to our server, instead we will directly send the file to the external server. For sending we will encrypt the file with base64.
OK. Lets’ Start. First, Let’s create the FORM page :

... [READ MORE]

Split Name in PHP and Javascript

If you have a user with a long name and want to short it because it won’t fit into the element that contains the name, you can either do it on the server or the client. In this post I am going to tell you how to accomplish this with PHP and JavaScript.
Suppose We have a user named Paul Steve Panakkal (my cousin). To separate the first name, middle name and last name you can do the following in PHP :

... [READ MORE]

Prevent Directory Listing using HTACCESS

If you don’t want your site users to see your directory listing, you can do a simple trick in .htaccess file.
Here is a screenshot of a directory listing on Apache Server :

Now, to disable directory listing of all types of files, type in the following code in .htaccess :

IndexIgnore *

This will change the directory listing to this :

The empty directory listing looks ugly. To make it beautiful, you can add an index page for all directory listings without adding each index files on each directory. Use the following code on .htaccess for that.

... [READ MORE]

Create MySQL Injection free Secure Login System in PHP

There were a lot of people who created tutorials to create a PHP Login System. But they were all vulnerable to MySQL Injection. In this post I’m going to demonstrate a login system free of this vulnerability. It is very secure. There are mysqli and PDO in PHP to escape these injections. We are going to use **PDO ( PHP Data Object **).

UPDATE – logSys

There is a new, free, better Advanced Login System which you can check out here.

... [READ MORE]

Generating Random String in PHP

In PHP you can generate random number by using rand function, but there is no specific function to generate a random text or string. In this post I’m going to show the function that will generate a random string of length mentioned.

Here is the function:

function rand_string($length) {
 $str="";
 $chars = "subinsblogabcdefghijklmanopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
 $size = strlen($chars);
 for($i = 0;$i < $length;$i++) {
  $str .= $chars[rand(0,$size-1)];
 }
 return $str;
}

Usage

To generate a random string use rand_string() function with the parameter of length of the to be generated string. Here’s an example:

... [READ MORE]

Preventing double encode of URL in PHP

There is no practical way to check whether an URL is encoded or not to encode if it’s not encoded. But you can do encode the URL by first decoding like below:

$string = url_decode($url);

And then you should encode as to prevent double encoding.

$string = url_encode($url);

By doing this we can prevent double encoding of URL‘s.

... [READ MORE]

Follow/Subscribe

Telegram 

Mastodon  Twitter

GitHub GitLab

Subdomains

Demos  Lab

Past

This blog was once on WordPress. Now a static site. See source code on

GitLab