PHP
If you are wanting to use different more than one session on the same domain, (i.e. if you have several versions of the same login system in different folders or subdomains), you need to name your session before calling session_start();
For example:
// Start Session & starting vars…
Here’s a simple PHP function that allows you to target a specified IP address, and can therefore be used to show certain information to the developer or developing team…
Replace 123.456.78.90 with your real IP address…
// Only show to the ip address 123.456.78.90
if($_SERVER['REMOTE_ADDR']=='123…
I love the ‘LIKE’ SQL command for searching within phpMyAdmin, but to do the job properly on a page, you really need to know how to use ‘Full-text Searching’…
This article by Jim Ferrara does the trick…. Thanks Jim!
//
// Convert a date from jQuery 'Date picker' date to the database date format
//
function dpDateToDbDate($date){
$time = strtotime($date);
return date('Y-m-d', $time);
}
//
// Convert Text to 'Safe Url'
//
// Mark Jacksons Function
function safeURL($txt,$allowSpace=false,$allowCaps=false) {
$find = array('/à|á|â|ã|ä|å/', '/ç/', '/è|é|ê|ë/', '/ì|í|î|ï/', '/ñ/', '/ð|ó|ò|ô|õ|ö|ø/', '/ù|ú|û|ü/', '/ý|ÿ/');
$replace = array('a', 'c', 'e', 'i', 'n', 'o', 'u', 'y…
I’ve become a big fan of using a ‘config’ file that I include at the beginning of all my PHP pages. Here I can set everything from global settings and variables, to site-wide functions…
One of the site-wide functions I use a lot sends an email if a script fails, i.e. do this and if it worked do…
Here is a great, lightweight script that’s great for logging a user out of a password protected site. It deletes the cookie too…
// Delete Sessions
$_SESSION = array();
if (isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', time()-42000, '/');
}
session_destroy();
Taken from php…
So we want to allow visitors to the site to download files, but would either like to restrict this to those logged in, track/count download times, or do something else interesting….
If we use a PHP page to do this, we can add all of our usual functionality at the top, and then get the page to…
When you’ve just added an entry to the database with ‘INSERT’, and you need to get the ID of that row for the next step….
$lastId = mysql_insert_id();
I have had a few issues with this, so in one case I ended up just running a SELECT query with the same data I added the query, but just returned…
Quick and handy function to purify data before entering into the database
function escape_data($data){
$data = mysql_escape_string(trim($data));
$data = htmlspecialchars($data, ENT_QUOTES, 'UTF-8');
return = $data;
}