Quick and Dirty PHP Caching Advertisement Caching your database-driven website pages has a plethora of benefits, not the least of which being improved speed and reduced server loads. This article will explain how to set up a simple caching system, and will also address when and where caching might not be appropriate. For me, the impetus to switch to a caching method for one of my database driven sites was sparked by Mosso, since they bill by cpu cycle, and I have one site that is, well, humongous (60k+ pages), and it happens to the highest traffic site on the account. While the database queries were all very efficient, and each page had, on average, no more than 6 queries, performance and cpu cycles would both be helped quite a lot by implementing a cache. This caching solution was a temporary fix, while we switched to a new CMS that was already using a robust caching system. Using output buffering, caching pages is incredibly easy. The basic stuff In all its 6-lines of glory, this is actual, working caching code. 3.
PHP Help Tutorial: PHP Basic Pagination Basic Pagination As a web developer, you will often be tasked to display large amounts of data to the user in some kind of easy to read format. Let's say for instance you have a list of employees in your database, and you want to be able to list them on your web page. If you only have a dozen or so employees, it's no big deal to just make a simple loop and display them all on the same page, right? Pulling out all that data at the same time can leave your user tapping his fingers on the desk wondering what the frak is taking so long, and when he finally does get his info, it's a whole frakking novel on one page! Well anyways, it makes way more sense to break up your list into page-sized chunks, and only query your database one chunk at a time. A basic pagination routine seems long and scary at first, but once you close your eyes, take a deep breath, and look at each piece of the script individually, you will find it's actually pretty easy stuff. <? Why 3 digits? <? Now we run our query.
TUTORIAL: How to install PHP and MySQL on IIS With the apparent increase of interest in individuals desiring to install PHP and MySQL on computers running Windows operating systems, I thought it would be beneficial to provide a set of instructions to help make this process as easy as possible. In this article, I’ll be providing some basics of IIS installation and then move to the installation of PHP and MySQL. Some essentials you will need to get started:IIS (preferably IIS 5 or IIS 6)The PHP windows installer file The PHP binaries fileThe MySQL Windows installation file(links will be provided for the downloads shortly). Optional:phpMyAdminMySQL Administrator Let’s get started. Since you are installing on a Windows computer, you will most likely be using IIS for a web server, however, it is not required. Some things to know about IIS. If you haven’t already done so begin by installing IIS. It really shouldn’t matter whether you install PHP first or MySQL first. Then go to your web browser and type: . mysql>
Absolute paths for PHP include PHP form tutorial This tutorial takes you step by step through web form processing using PHP. You will learn how to collect input from a web form, validate and save it. This tutorial assumes that you are familiar with at least very basic PHP and HTML. Note: You can make web forms quickly with Simfatic Forms. Simfatic Forms helps you to make complete, feature rich forms and get it online quickly. Read more here. Creating the HTML code for the form In HTML, a form is begins and ends with a <form> tag. The “action” specifies what page to submit the form to. Now let’s add some inputs to the form. Getting the form data The input of type “text” is just a single line field to type in some text. Congratulations! Let’s add some PHP to process this form: First, remember that this form “submits to itself”, meaning that the form variables will be sent to this page, and the page will load again from the top. So, the first thing we should do is to check and see if a form was submitted or not. Validating the input
PHP Examples - snippetdb.com passing variables via url Pass variables to a page using the question mark, for example mypage.php?value=hello. Access these variables with the _GET command. send email Send an email from PHP - one line example. redirect browser Using the php header function, a browser can be redirected to another page. get current filename as variable Sometimes you need just the filename of the current script, without the path. email validation, simple Validate an email address - returns TRUE or FALSE. get current page URL Often used for form actions, the variable $PHP_SELF has changed with recent versions, and now must be accessed using the _SERVER array of pre-defined variables. form action - detect form post There are several ways to process a php form. generate random number Generate a random number using mt_rand. force cookies, disable php sessid in URL This commands disables php from rewriting URLs to add a phpsessid, and forces the use of cookie sessions instead. show referring URL Define A Constant
PHP form tutorial - PHP form processing This article demonstrates how to use PHP forms. You will find detailed information from the form basics to advanced form processing. Tutorial info: Bookmark PHP form tutorial Step 2 - PHP form processing PHP form tutorial Now we have a HTML page with a form but if we press the submit button then we will get a Not Found message if the form.php file doesn't exists yet. First you should save the HTML site shown in the previous step as form.php. If a form was submitted and the script defined in the action parameter of the form tag is called then a so called super global array will be populated with the user entered information. Code: $_POST['name'] : "John"$_POST['email'] : "john@john.com"$_POST['mesg'] : "Hello, my nam is John!" What does it mean? However it can happen that the visitor submitted an empty form by just clicking on the Send button. Ok, it's nice but what to do now. Previous Step of PHP form tutorialNext Step of PHP form tutorial
PHP Tutorials: Variables - Some Practice In the previous section, you saw what variables are: storage areas to hold things like numbers and text. You tell PHP to remember these values because you want to do something with them. In this section, you'll get some practice using variables. Off we go. Testing variables with PHP First, we'll take a look at how to display what's in your variables. <html> <head> <title>Variables - Some Practice</title> </head> <body> When you've finished typing it all, save the page as variables.php. If you've created a folder inside the www folder, then the address to type in your browser would be something like: If you were successful, you should have seen the text "It worked!" The PHP script is only one line long: The rest of the script is just plain HTML code. We've put the PHP in the BODY section of an HTML page. So you need a left angle bracket ( < ) then a question mark ( ? To display things on the page, we've used print( ). <?
15 very useful PHP code snippets for PHP developers | ViralPatel.net Following are list of 15 most useful PHP code snippets that a PHP developer will need at any point in his career. Few of the snippets are shared from my projects and few are taken from useful php websites from internet. You may also want to comment on any of the code or also you can share your code snippet through comment section if you think it may be useful for others. 1. Send Mail using mail function in PHP 2. 3. The above code will not work in case your client is behind proxy server. 4. This function will return the duration of the given time period in days, hours, minutes and seconds. e.g. secsToStr(1234567) would return “14 days, 6 hours, 56 minutes, 7 seconds” 5. 6. Required Extension: SimpleXML 7. 8. Following is the PHP code to create the JSON data format of above example using array of PHP. Following code will parse the JSON data into PHP arrays. 9. 10. This basic snippet will create a random authentication code, or just a random string. 11. Validate a date in “YYYY-MM-DD” format.
7 Secure, Lightweight, and Easy to Use PHP Frameworks Choosing a good PHP frameworks can help you develop complex Rich Internet Applications quickly, with a best practices oriented approach, and saving a lot of time reusing code snippets that are already available. There are a lot of interesting PHP frameworks you can choose for your next web project. Which framework you choose is really a personal decision. There is no one “best” framework on the market at the moment. Different frameworks are better for different types of projects, and for different developer. Today we will focus on 7 secure, lightweight and easy to use PHP Frameworks. Why Use a PHP Framework? There are plenty of reasons to use a PHP Framework to build your websites. 1. Below we’ve covered some of the best frameworks available today. 1. CodeIgniter is a powerful, high-performance, open-source PHP framework that helps you author PHP applications rapidly. CodeIgniter has an exciting online manual, a couple of helpful video tutorials and an active user forum. 2. 3. 4. 5. 6. 7.
10 code snippets for PHP developers « The html blog I’ve compiled a small list of some useful code snippets which might help you when writing your PHP scripts… Email address check Checks for a valid email address using the php-email-address-validation class. Source and docs: 01.include('EmailAddressValidator.php'); 03. 04.if ($validator->check_email_address('test@example.org')) { 07.else { Random password generator PHP password generator is a complete, working random password generation function for PHP. 01.function generatePassword($length=9, $strength=0) { 02. 03. 04. if ($strength & 1) { 05. 07. if ($strength & 2) { 08. 10. if ($strength & 4) { 11. 13. if ($strength & 8) { 14. 17. 18. 19. for ($i = 0; $i < $length; $i++) { 20. if ($alt == 1) { 21. 22. 23. } else { 24. 25. 28. return $password; Get IP address Returns the real IP address of a visitor, even when connecting via a proxy. 01.function getRealIpAddr(){ 02. if (! 04. 06. elseif (! 08. 10. else{ 11. 13. return $ip; XSL transformation 01. 04. 05. 08.