PHP

From The System Administrator Zone

What is phpinfo?

phpinfo.php is a simple, three line php script;

<?php
    phpinfo();
?>

It will tell you more than you want to know about the version of PHP installed on the system.

How can you test if e-mail is working on your server?

Create a file one your site named: Mail_test.php

<?php
$body="<em>HTML</em> formatted <strong>Message</strong>";
$headers = "From: bob@example.net \r\n";
$headers.= "Content-Type: text/html; charset=ISO-8859-1 ";
$headers .= "MIME-Version: 1.0 ";
mail("mary@example.com", "An HTML Message", $body, $headers);
?>

How do you increase or eliminating the 15 minute timeout?

You might simply want to select the "Remember my login on this browser" checkbox when logging in.

If that isn't sufficient, you can adjust session.gc_maxlifetime in /etc/php5/apache2/php.ini.

The real solution is to put something like this at the top of each page;

session_start();
  
// set timeout period in seconds
$inactive = 600;
  
// check to see if $_SESSION['timeout'] is set
if(isset($_SESSION['timeout']) ) {
     $session_life = time() - $_SESSION['start'];
     if($session_life > $inactive)
     { session_destroy(); header("Location: logoutpage.php"); }
}
$_SESSION['start'] = time();

How do you verify someone has logged in?

Add this to the previous script;

if($_SESSION['valid_user'] != true){
    header('Location: ../index.php');
    }else{

It checks to see if the session variable $_SESSION['valid_user'] is set to "true" and sends you back to the login page if it's not. You will have to set $_SESSION['valid_user'] to "true" when the person successfully logs in. Then they will have access to every page that has this at the top.

Using a Cookie to deal with Users

Here is an article showing how you can us your database and local cookies to work with users.

How to Expire a User Session After 30 Minutes of Inactivity

PHP Links of Interest

PHP Freaks.com Installing APC cache