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 [...]
Category Archives: howto
Prevent caching of page on client’s end – PHP and HTML solutions
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 [...]
Smarty tricks
Here's how to include another template file within a template file: PLAIN TEXT PHP: {include file='includes/menu_calendar.inc.tpl'} Tweet
Consuming a GData Calendar feed
If you have successfully obtained a calendar feed, you should receive some XML looking like this PLAIN TEXT XML: <default:feed> <default:id>http://www.google.com/calendar/feeds/vinoajtest%40gmail.com/public/basic</default:id> <default:updated>2007-04-08T03:38:29.000Z</default:updated> <default:category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/g/2005#event"/> <default:title type="text">Vinoaj Vijeyakumaar</default:title> <default:subtitle type="text">Vinoaj Vijeyakumaar</default:subtitle> <default:link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://www.google.com/calendar/feeds/vinoajtest%40gmail.com/public/basic"/> <default:link rel="self" type="application/atom+xml" href="http://www.google.com/calendar/feeds/vinoajtest%40gmail.com/public/basic?max-results=25"/> [...]
Authenticating for Google and GData
Making changes to your data and accessing private data will require the passing of an authentication token with your requests. You need to make use of the AuthSub Interface to acquire a token. Acquiring and manipulating tokens The workflow of the AuthSub authentication process is nicely summarised by Google: AuthSubRequest - Request an authentication token [...]
