Thursday, 16 July 2009

PHP Session Test

Recently, i've had problems setting a clients site live on a 3rd party providers hosting. The problem is the site wouldn't allow sessions to be written so login scripts and catcha codes did not work as intended. The main problem is that technical support always blame programmers code before actually investigating the problem (sigh).

Therefore here is a simple php script to prove to the technical support that sessions are not working as they should;

if($_GET["test"] == '1'){
if($_SESSION['atest'] == 'yes'){
echo('Your hosting supports sessions');
} else echo('Your hosting does not support sessions');
} else {
$_SESSION['atest'] = 'yes';
echo '
<script type="text/javascript">
function delayer(){
window.location = "'.$_SERVER['PHP_SELF'].'?test=1";
<body onLoad="setTimeout(\'delayer()\', 5000)">
About to test sessions.
<br /><br />
please wait...

The script performs a 301 redirect to test if sessions are working correctly when a page is refreshed.

1 comment:

how to ollie said...

Excellent post and writing style. Bookmarked.