Web & Software Developer

Archive for “PHP Code Snippets”

PHP code snippets and tips for customizing your own website, and for generating dynamic content with PHP.

Print or var_dump To Screen, But Only On My IP Address

This lets you print PHP variable information, or any debugging code, to the screen, but only on your IP address. This is useful when you have to test on a live site, and for whatever reason you want to print to the screen rather than to error logs, but you don’t want visitors to see […]

Hide Content From One IP Address on WordPress Site

This gets the visitor’s IP address, and hides the content from the IP address that you specify. This is for use on WordPress sites. One way to use it is in your single.php template file (or content-single.php). Replace this: … with this: Be sure to change the ‘11.111.111.11’ on line 21 above to the IP […]

Harvest Data From Multiple Text Files To Insert Into MySQL

Here is a way of preparing a large amount of data to insert into a MySQL database table via PHP. This method works if your data is split up into multiple text files. If your data is already in a single text file, see Harvesting Data From A Text File instead. Note: My example is […]

Harvest Data From A Text File To Insert Into MySQL of 2 Columns

Here is a way of preparing a large amount of data to insert into a MySQL database table via PHP. This method works if your data is all in one text file. If your data is split up into multiple text files, see Harvesting Data From Multiple Text Files To Insert Into MySQL instead. Note: […]

Subscribe Existing Commentators Into Comment Notifier Plugin

This is for you if you are using the WordPress Comment Notifier Plugin by Satollo. The purpose of this is to automatically subscribe your existing commentators (which are people who have already made comments to your blog). You want to add these people as subscribers to this Comment Notifier Plugin, or they get left out […]

Get Current Page URL Using PHP

This is a PHP function to get the current page URL with only PHP. This works within WordPress, as well. Example Usage One use for this is if you’re using ajax to process a form and return results to the page, and you’d like a link below the results to allow the user to “Return […]

Get Local Time in PHP with localtime

This will get the local time from the visitor’s browser. Then it converts PHP’s localtime() function into a readable display format, with leading zeros before the single-digit minutes. It also converts time into 12-hour format and appends the meridian ( am/pm ) to it. Then it displays the final time, formatted nicely, like See below […]