Browsing » Web Development

PHP: Session Timeouts

PHP: Session Timeouts

Defining session timeout thresholds for PHP scripts is a security “must”. I recommend that you consider the purpose of your script before applying a session timeout function. For instance, if your site has a secure login and security requirements, it’s important to include the timeout function. However, it’s often an inconvenience to end-users.
Use [...]

Use PHP to Backup your MySQL Database

Use PHP to Backup your MySQL Database

If you don’t backup your databases regularly, shame on you. You should!
The code below will allow you to generate a backup as often as you’d like. It only makes sense to run this via a CRON job. This is pretty easy to do and you can set the frequency as you wish.
The [...]

Return Random Record via MySQL

Return Random Record via MySQL

There are many practical and frequently used methods requiring a random record to be called. For instance, when you see “featured profiles” or random customer comments on a website, they are most likely using a function to call a random record.
In addition, this function can allow you to display data in a random order.
Here’s [...]

Detecting iPhone visitors with PHP

Detecting iPhone visitors with PHP

More and more internet traffic is generated by the iPhone and iPod touch.
The PHP snippet below shows you how to automatically redirect your users to a page which is optimized for the iPhone Safari browser.

if(strstr($_SERVER['HTTP_USER_AGENT'],’iPhone’) || strstr($_SERVER['HTTP_USER_AGENT'],’iPod’))
{
// Change your URL below
header(‘Location: http://www.domain.com/iphone’);
exit();
}

PHP: Preventing typical XSS attacks

PHP: Preventing typical XSS attacks

XSS attacks plague beginner programmers and are a significant vulnerability for commercial web hosts & website operators.  XSS means “cross-site scripting“.  These exploits work on the client side. Often, hackers put some type of JavaScript in content that users submit that allow them to steal the data from a cookie.  XSS attacks are pretty difficult [...]

PHP/AJAX: Call PHP function by clicking a link

PHP/AJAX: Call PHP function by clicking a link

This tutorial demonstrates how to execute an external PHP function by clicking a simple link within HTML.  The method uses AJAX so that the page doesn’t refresh and doesn’t require a form submission.
1) Paste the following code into a .js file.  For demonstration purposes, we have named it “ajax_click.js”.

/*
* ajax_click.js
* chriscook.me
*/
function loadurl(dest) {
try {
// [...]

Your Ad Here