SL8R.co.uk - Code Zone

Code, Code and Code

SL8R.co.uk - Code Zone header image 4

PHP: Page Inclusion using GET selection

April 18th, 2008 · No Comments

Sample code to handle page inclusion based on get values 
// parse the passed value
switch($_GET['page'])
{
  // check for page1
  case(’page1′):
  include ‘page1.php’;
  break;
  // check for page2
  case(’page2′):
  include ‘page2.php’;
  break;
  // send other enquiries to our 404 page
  default:
  include ‘page404.php’;
  break;
}

addthis_url = ‘http%3A%2F%2Fwww.sl8r.co.uk%2F2008%2F04%2F18%2Fphp-page-inclusion-using-get-selection%2F’;
addthis_title = ‘PHP%3A+Page+Inclusion+using+GET+selection’;
[...]

[Read more →]

Tags: Code

PHP: Encoding HTML Special Characters

April 18th, 2008 · 1 Comment

When working with untrusted information it is always worth running it through the htmlspecialchars function.
This function converts characters that are used by html into safer versions, e.g. ‘<’ becomes $lt;
myString = htmlspecialchars($_GET['fieldname'], ENT_QUOTES);

addthis_url = ‘http%3A%2F%2Fwww.sl8r.co.uk%2F2008%2F04%2F18%2Fphp-encoding-html-special-characters%2F’;
addthis_title = ‘PHP%3A+Encoding+HTML+Special+Characters’;
addthis_pub = ”;

[Read more →]

Tags: Code