Posts marked with "PHP" in categories
Uploading An Image Using AJAX In jQuery With PHP
A Sample of uploading image using AJAX in jQuery is shown below :
<div>
Now Let’s start on the code. Here is the <b>HTML</b> page :
</div>
<div>
<pre class="prettyprint"><code><!DOCTYPE html>
<html> <head> <script src="//code.jquery.com/jquery-latest.min.js"></script> <script src=“http://malsup.github.io/jquery.form.js"></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>
Send Email using GMail SMTP server in PHP
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
Here is a quick example :... [READ MORE]
Upload Image To Remote Server With PHP cURL & Handle File in Remote Server
For this submission we will use 2 files :
- form.php – The Page Where we will show the client the form. This file also sends the uploaded data to the external server.
- 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 :
Split Name in 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
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
$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.