September PHP-Scripts Blog Archives
I’m not sure how current or updated this is because I found some broken project links (all links below work) but these projects seem promising and worth closer inspection, especially if one is looking to make their PHP scripts run faster.
Turck MMcache:
… a free open source PHP accelerator, optimizer, encoder and dynamic content cache for […]
09-30-2005 | Permanent Link | No Comments | Related Entries: Optimization, Encoding, PHP 4.x
To change MySQL databases within code use the mysql_select_db() function like this:
<?php
mysql_select_db(‘db_2′, $mysql_link);
$query = “SELECT username from user where userid = ‘$user_id’”;
$result = mysql_query($query,$mysql_link);
if(mysql_num_rows($result)) {
$row = mysql_fetch_row($result);
$username = $row[0];
}
mysql_select_db(‘db_1′, $mysql_link);
?>
This code […]
09-29-2005 | Permanent Link | No Comments | Related Entries: MySQL, Information
Wordpress has a cool plugin system that allows for various template changes. Sometimes, though, some defaults are planted in the program that require hacking the code to remove. By creating your own 404.php template and storing in the template are you can have it match the design of the rest of your blog, but what […]
09-26-2005 | Permanent Link | No Comments | Related Entries: Wordpress, Information
The PHP Security Guide discusses and explains in depth PHP security issues, including many code examples:
If you do not design your application with security in mind, you are doomed to be constantly addressing new security vulnerabilities. Careful programming cannot make up for a poor design.
Even a little security philosophy in there. Definitely worth bookmarking.
09-26-2005 | Permanent Link | No Comments | Related Entries: Information
At one of our sites we needed to parse out some names and numbers from a log file. The strings also contained comment text and the order would be mixed format. These types of regular expression parsing can be tricky.
Let’s take a look at the two possible formats of the strings:
FORMAT #1:
[00:02:18][jvastine]7.52..I agree with […]
09-23-2005 | Permanent Link | No Comments | Related Entries: Functions, PHP 5.x, PHP 4.x
The PHP header function allows redirection of the browser, among other cool things.
Example redirecting the browser to php-scripts.com homepage:
<?php
header(”Location: http://www.php-scripts.com/”);
?>
09-22-2005 | Permanent Link | 4 Comments | Related Entries: Functions, PHP 5.x, PHP 4.x, PHP 3.x
Finding out the number of days elapsed from a UNIX timestamp is actually pretty straightforward. If you only know two dates then first you’ll need to convert the date to a UNIX timestamps and then subtract the most recent timestamp from the older timestamp like this:
<?php
$old_timestamp = 1102971600;
$elapsed_seconds = time() - $old_timestamp;
print ‘Seconds elapsed since […]
09-21-2005 | Permanent Link | No Comments | Related Entries: Linux, PHP 5.x, PHP 4.x, PHP 3.x, Information
<?php
$string = “?This is a test that should be in single quotes quotes?”;
$text = preg_replace(”/(\?([^\?]+)\?)/”,”‘\\2′”,$string);
?>
regular expression produces:
This is a test that should be in single quotes’
09-20-2005 | Permanent Link | No Comments | Related Entries: PHP 5.x, PHP 4.x, Information
Today being it is our 16th wedding anniversary I decided it would be appropriate to build a small script to keep track and post a message automatically on our special day together. I wanted this program to remember what year of our anniversary it was without me having to remind it: a great use for […]
09-19-2005 | Permanent Link | No Comments | Related Entries: PHP 5.x, PHP 4.x, Information
So you are getting a weird parser error at a line of code that doesn’t have any errors? Here are some tips and tricks I’ve compiled over the 6+ years I’ve been doing PHP scripting for tracing various PHP errors in source code:
1. Start commenting out code near the parser error line number. Start by […]
09-18-2005 | Permanent Link | No Comments | Related Entries: Information