A few sites I administer have recently had the misfortune of having spambots visit their enquiry and contact pages. These pages usually have a contact form, where an enquirer can leave their name, e-mail, and request or comment. When they submit the form, a copy of the message is e-mailed to the site owner. The [...]
Timezones and UTC in PHP
If you are dealing with multiple users in different timezones or simply want to display times in a timezone other than your server's settings, it is best to store timestamps as their UTC (~ GMT) equivalents. When you read those timestamps later, you can convert them to local time. Local time to UTC time PLAIN [...]
HTTP Status Codes
The following is a list of HTTP Status Codes returned by a web server and what they mean. The information is summarised from RFC2616 Section 10. Informational 1xx Informational responses that contain no message bodies. 100 Continue - The client should continue with the request. Either the request is in a queue or the client [...]
Prevent caching of page on client’s end – PHP and HTML solutions
To prevent the caching of a web page on your client's end, use the following snippet of PHP to ensure that the appropriate HTTP headers are sent. PLAIN TEXT PHP: header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Tue, 03 Jul 1979 00:00:00 GMT"); // Date in the past The first header tells the client that the [...]
Using mysqldump to export a database
mysqldump is a useful utility for dumping the contents of an entire database to an SQL file. PLAIN TEXT CODE: mysqldump --user=dbusername --password=dbpassword db_name_here> db_name_here.sql By default the --opt option is enabled, which is a shorthand option for specifying the below options. According to the documentation, using this option "... should give you a fast [...]
PHP/CURL
cURL is used to interact with remote URLs without needing a user to initiate the process (e.g. by clicking on a form submit button). cURL is useful for submitting HTTP POST/PUT/DELETE requests when dealing with web services. PHP has inbuilt cURL support since PHP 4.0.2 using cURL's libcurl library. Find out more about PHP/CURL -- [...]
Rewriting URLs to force www or non-www URLs
PLAIN TEXT CODE: #Activate the rewrite engine if it isn't so already RewriteEngine on #intercept all HTTP requests to the site that do not have a 'www.' at the beginning of the Domain name #and then force a redirect to the same page address only this time, including the 'www.' RewriteCond %{HTTP_HOST} !^www\..* [NC] RewriteRule [...]
Sending a plain text e-mail
Sending a plain-text e-mail through PHP is a simple process PLAIN TEXT PHP: mail ($to, $subject, $message, $headers); The $to parameter can look like: example@mysite.com example@mysite.com, user@mysite.com Example Sr <example@mysite.com>, Example Jr <user@mysite.com> Common headers to use in your messages: PLAIN TEXT PHP: $headers = "From: yourname@yoursite.com\r\n Reply-To: replyhere@yoursite.com\r\n [...]
htpasswd
htpasswd is a command line tool for creating and updating user authentication files. These files are primarily used by apache to authenticate HTTP users. Creating a password file PLAIN TEXT CODE: htpasswd -c /path/to/.htpasswd username Adding a user & password PLAIN TEXT CODE: htpasswd -b /path/to/.htpasswd username password Tweet
Creating an XML document with PHP 5′s DOM Functions
PHP 5's DOM Functions (or extension) allows you to create and manipulate XML documents. In fact, it can also be used to create and manipulate any documents adhering to the DOM3 specifications such as HTML and XHTML documents. Creation of a DOM document is a fairly simple affair Instantiate DOMDocument - also specify which version [...]
