background preloader

PHP Programming

Facebook Twitter

FPDF. Easy PHP Blackhole Trap with WHOIS Lookup for Bad Bots. One of my favorite security measures here at Perishable Press is the site’s virtual Blackhole trap for bad bots. The concept is simple: include a hidden link to a robots.txt-forbidden directory somewhere on your pages. Bots that ignore or disobey your robots rules will crawl the link and fall into the trap, which then performs a WHOIS Lookup and records the event in the blackhole data file. Once added to the blacklist data file, bad bots immediately are denied access to your site. I call it the “one-strike” rule: bots have one chance to follow the robots.txt protocol, check the site’s robots.txt file, and obey its directives.

Failure to comply results in immediate banishment. The best part is that the Blackhole only affects bad bots: normal users never see the hidden link, and good bots obey the robots rules in the first place. The Blackhole is built with PHP, and uses a bit of .htaccess to protect the blackhole directory. Installation Overview One-time Live Demo Optional customization: PHP for Beginners: Building Your First Simple CMS. The Magic of PHP + MySQL It’s safe to say that nearly every website that’s up-to-date these days is using some form of content management system (CMS). While there are a ton of great free options that provide us with a CMS to power a website (WordPress, Drupal, etc.), it doesn’t hurt to peek under the hood and get a feel for how these systems work. To get our feet wet as back-end developers, we’ll be creating a simple PHP class that will: Create a databaseConnect to a databaseDisplay a form with two fieldsSave the form data in the databaseDisplay the saved data from the database Download Files This class is intended to give you a feel for how PHP and MySQL interact together, and to show the basics of a CMS.

Building the Class Our first step is to simply lay out the class in a file named ‘simpleCMS.php’ so we have a road map to work with. As you can see, we’re creating one class with four variables and five methods. The Variables Build the Database Connect to the Database Build the Form <! <? PHP 101: PHP For the Absolute Beginner. Create daemons in PHP. Everyone knows PHP can be used to create websites. But it can also be used to create desktop applications and commandline tools. And now with a class called System_Daemon, you can even create daemons using nothing but PHP. And did I mention it was easy? Update 4 Dec, 2012: Legacy Warning This class was relevant in 2009, and may still be to some people, but if you want to daemonize a php script nowadays, a 5-line Ubuntu upstart script should suffice. If you're still convinced you need to do this with pure PHP, read on. What is a Daemon? A daemon is a Linux program that run in the background, just like a 'Service' on Windows.

You reading this page, would not have been possible without them. Why PHP? Most daemons are written in C. Reuse & connect existing code Think of database connections, classes that create customers from your CRM, etc.Deliver new applications very fast PHP has a lot of build in functions that speed up development greatly.Everyone knows PHP (right?)

Possible use cases Beta. AtomicPHP.com - Free PHP Scripts, Large PHP script directory site. PHPBuilder.com, the best resource for PHP tutorials, templates, PHP manuals, content management systems, scripts, classes and more. I wish I had known these 10 tips the day I started working with PHP. Instead of learning them through painstaking process, I could have been on my way to becoming a PHP programmer even sooner! This article is presented in two parts and is intended for folks who are new to PHP. Tip 1: MySQL Connection Class The majority of web applications I've worked with over the past year have used some variation of this connection class: class DB { function DB() { $this->host = "localhost"; // your host $this->db = "myDatabase"; // your database $this->user = "root"; // your username $this->pass = "mysql"; // your password $this->link = mysql_connect($this->host, $this->user, $this->pass); mysql_select_db($this->db); } } // calls it to action $db = new $DB; Simply edit the variables and include this in your files.

This doesn't require any knowledge or special understanding to use. $result = mysql_query("SELECT * FROM table ORDER BY id ASC LIMIT 0,10"); Tip 2: Dealing with Magic Quotes Tip 4: Debugging. OBJECT ORIENTED PHP TUTORIAL FOR BEGINNERS. Preamble The hardest thing to learn (and teach btw,) in object oriented PHP is the basics. But once you understand them, the rest will come much, much easier. But don’t be discouraged! You just found the easiest to understand tutorial out there on OOP and PHP. . … Or so I’ve been told. About This Tutorial This tutorial is designed to teach total beginners object oriented PHP. This is not a long-winded theoretical blathering that you see all too often; instead, we actually start writing OO code very quickly. So before you begin, get out your favorite PHP code editor and be ready to write and run some object oriented PHP code. PS: scroll to the bottom of the page for the supporting videos.

Thanks for reading, Stefan Mischook Introduction With the release of php5 in 2004, php programmers finally had the power to code with the ‘big boys’. In this tutorial, you will be guided (step-by-step) through the process of building and working with objects using php’s built-in OOP capabilities. OOP Videos. Improve website load time by 500% with 3 lines of code | Aciddrop.com. Major New Update - PHP SPEEDY: latest version available here There are 4 relatively easy ways by which you can speed up the time it takes a browser to download a page: Make fewer HTTP requestsAdd a far-future expires headerGzip your page's componentsMinify your JavaScript, CSS and HTML Following on from my post on joining CSS and JavaScript files, I have written a PHP script which will automatically do all of the above.

All you have to do is call the following at the top of your page: The code require_once('class.compressor.php'); //Include the class. And the following at the bottom of the page: The Demo That's it! The class can be downloaded here: site speed boost class download Requirements A server running at least PHP4. Setting basic options Options can be set with a comma separated string as follows: $compressor = new compressor('css,javascript,page'); The string can contain 'css', 'javascript' and 'page' depending on which elements you would like to be compressed. Setting advanced options. Good PHP Tutorials - Beginner To Advanced PHP Programming Tutorials. Ten PHP Best Practices Tips that will get you a job | PHP vs .Net.

Posted by blake on Jun 4, 2008 in Code, Performance, PHP | 167 comments The last couple of weeks have been quite the experience for me. I was part of a big layoff at my former company, which was interesting. I've never been in that position before, and it's hard not to take it personally. I started watching the job boards, and a nice-looking full-time PHP position caught my eye, so I sent out a resume and landed an interview. Find the errors in the following code: So, give it a shot. If you got the missing comma in the parameter list, the "new Array()" error, the colon instead of a semi-colon, the '=' instead of '=>' in the foreach statement, and the erroneous use of '+' on the echo line, then congratulations, you found all the errors!

That's not how I answered the question though. After pointing out the actual errors, I made a point of adding comments about those things I just mentioned. So, read on for my Ten PHP Best Practices Tips that will get you a job: 1. 2. 3. 4. 5. 6. 7. 8. 9. Random Password Generation by Stefan Ashwell | PHP & MySql articles and tutorials | Total PHP.