Last time I’ve written an article about hiding php file extension where I’ve showed you how you can use .html or .asp extension of file instead of .php extension. But there was one flaw in that technique you have had to change the file extension explicitly but in this post I’m going to show you how to rewrite the URL instead of renaming the file extension Using this technique you will see product.html in the address bar of the browser but the actual file name remains product.php and you don’t need to rename the file extension. Furthermore you can rewrite the URL like product.php?id=5 to product-5.html.
If you are looking for the validation of a number which contains only two decimal places. Means you want to accept the values like 0.21 or 1.34 or 12.55 or 445.66 as a input and throw an error when somebody enters the number like 0.2 or 4.678 from a text box. Here is a simple function for you in PHP which validates the number weather it contains exactly two decimal places or not.
Last day i saw that one of my friend looking for the validation script in PHP which post the phone no (number) of USA from the text box and wanted to validate it from PHP in the following format.
Do you know what happend when register_globals is set to ON in php.ini?? When it is set to ON it registers Environment, GET, POST, COOKIE or Server variables as global variables i.e. you don’t need to write $_POST[‘username’] to access the posted ‘username’ variable you can simply use ‘$username’ to access the $_POST[‘username’].
I think you guyz must be aware of absolute path and relative path in PHP. If you do not know anything about it then let me explain you about absolute path and relative path in the server with the example using include() function of PHP. You can see the example below, I’ve included the same files in PHP but the same file is included in two different manner.
include("/home/example/public_html/config.php"); //absolute path include("config.php"); //relative path
I’ve got many email from people asking for populating triple drop down list from the database without refreshing page using Ajax and PHP after posting the first article related to the ajax dropdown list using php .In this post, I’ve put three drop down of country , state and city and the drop down’s value changes without refreshing the page. Now let show you how to create it quickly.
Getting the extension from a file name or name of the file from the full path is not a big hassle for the experienced programmer but it might be a annoying task for the beginners of PHP. Now let me find the solution for them using two functions of PHP called explode() and pathinfo().
In your project you might have to run a function or script (.php) file automatically for a various reasons like automatic sending email on birthday or automatically close a auction when the end_time is reached. What to do in that situation? .To do these things automatically, you must have a php file which must contains the code and these files should be called automatically at certain certain time. So how to do that? The answer is Cron Job. Cron job are the cron tab command found in the UNIX or Linux system.
Now let’s see how can we call the file automatically at certain duration. Let’s suppose the duration is one hour, now I’ll show you how to setup the the cron-job of every one hour to run a PHP file automatically in the Cpanel of your website.
I’ve seen that many of my friends are struggling with the uploads of the bigger or larger files in PHP. After looking at their struggle, i’m here to solve the problem of uploading larger or bigger files in PHP.
Most of the web servers are configured such a way that a user can only upload the maximum file size of 2MB. So there might be the problem for the people who wants to upload the .pdf file of size around 15MB. But, you can increse the maximum upload file size limit by using .htaccess file.
I’ve noticed that many of my friends are storing password in database without encrypting them. This is really a bad technique because if somebody who has access of the database can easily know the password of the particular person.
The best functions available in PHP for encryption are md5() and sha1(). These both are one way encryping mechanism i.e the string encrypted with md5() or sha1() can’t be decrypted to original string. You might be then wondering how to validate the original string with the encrypted string then you can do this by encrypting the original string and compare both string,
CREATE TABLE `tbl_slider` ( `id` smallint(6) NOT NULL auto_increment, `slider_val` smallint(6) NOT NULL default '0', PRIMARY KEY (`id`) ) TYPE=MyISAM ;
Do you want to hide your web site’s server script identity ? If you don’t want to reveal the programming language ( server side script ) of your website to visitors of website so that any hacker or spammer will not be able to intrude or inject any code in your website.
Here is a small technique for you, you can use .html or .asp file to work as a php file i.e. use .asp or .html extension instead of .php. You just need to create a .htaccess file and put the following code in the .htaccess file. Remember that the .htaccess file should be placed in the root folder of your website.
What is 301 redirect ?
You have a website and its all pages are ranked in the search engine. And now you’ve moved these files to a new domain. What will happen in this scenario!!. You are sending the visitor to “Error 404 – File not found” page when they follow your website in the search engine. Furthermore, if you place the custom error page, then also you will be keep loosing ranking in upcoming days in search engines as the original file could not be found in the old URL. So what is the solution for this?? The solution is 301 redirect which means moved permanently. It is is the most efficient and search engine as well as visitor friendly method for the webpage redirection.
Are you using $_SERVER[‘REMOTE_ADDR’] to find the the client’s IP address in PHP? Well dude, you might be amazed to know that it may not return the true IP address of the client at all time. If your client is connected to the Internet through Proxy Server then $_SERVER[‘REMOTE_ADDR’] in PHP just returns the the IP address of the proxy server not of the client’s machine. So here is a simple function in PHP to find the real IP address of the client’s machine. There are extra Server variable which might be available to determine the exact IP address of the client’s machine in PHP, they are HTTP_CLIENT_IP and HTTP_X_FORWARDED_FOR.
Have you ever been frustrating, why e-mail is not going from the localhost while using XAMPP or WAMP or any other PHP servers in windows environment? well in that situation i think i can help you.In this article i am going to tell you how to send e-mail from localhost in PHP.
If you’ve to compare the difference between two dates or times values. How you’re going to accomplish it in PHP ? If you don’t know how to do it, then here is simple fuction for you to compare the date (as well as time) in PHP. For this comparison to take place, the argument supplied to this function must be in a USA and ISO date format.
What is SQL injection?
It is a basically a trick to inject SQL command or query as a input mainly in the form of the POST or GET method in the web pages. Most of the websites takes parameter from the form and make SQL query to the database. For a example, in a product detail page of php, it basically takes a parameter product_id from a GET method and get the detail from database using SQL query. With SQL injection attack, a intruder can send a crafted SQL query from the URL of the product detail page and that could possibly do lots of damage to the database. And even in worse scenario, it could even drop the database table as well.
While generating a report in your project, you might have to download the data into excel file using PHP. In most scenario, you have to display the report in a page and create a link to download the report in the excel file. Well in that scenario, i think i can help you with a simplified class and code of PHP.
I’ve created three files in my example.
Have ever been thorough cpanel ? when you open the link of cpanel, you can see a pop up which ask for entering user name and password for login. Well in my article I’m going to show you how you can build the same kind of page protecting mechanism using http authentication in PHP.
I’m going to show you a example in php and ajax to change the values of the dropdown’s options without refreshing the page. The values (options) of the dropdown are fetched from the database and the certain portion of the web pages is only refreshed without need to refresh the whole page.