29th May 2015

Two Useful php Functions

Two Useful php Functions

Ensure that the user has access to a page with a query string.

The code below ensures that the user has a specific query string, this can be useful especially if you want to prevent robots crawling your site and potentially triggering a task page (e.g. an import).

The example below works on the assumption that the URL is similar to:
http://your-website/webpage?k=369D1131-05F040E089B259E9A9CA7B64

<?php
$keya = "369D1131-05F040E089B259E9A9CA7B64";
$keyb = $_GET["k"];

if ($keya == $keyb)

// your code which you want to run

else

// non valid users – redirect to the homepage header("Location: http://your-website/"); die();

?>

Convert .NET ticks to php ticks

<?php
$tempTicks = $netTicks - 621355968000000000;
$phpTicks = $tempTicks / 10000000;
?>
Choose your interests: