PHP Index

Basic index.php

<?php
### This definition is so that any included scripts can check against it and if this isn't defined they won't run.
define("myprogram",1);

### Variables you can change
$site_title = "Site Title";

### Start the Session
session_start();
$sessid = session_id();

### php.ini configurations
# If you use .htaccess, add the following to increase upload size (There's other values in the ini_set() syntax below)
# php_value upload_max_filesize 15M
# php_value post_max_size 15M
#
# If you want to use the built in ini_set() function, uncomment the following to allow larger uploads and other options.
# ini_set("upload_max_filesize","15M"); ### Change upload size
# ini_set("post_max_size","15M"); ### Change upload size
# ini_set("max_execution_time","86400"); ### Set script timeout in seconds
# ini_set("max_input_time","86400"); ### Set max input time in seconds
# ini_set("memory_limit","32M"); ### Change the memory limit

### MySQL Database Configuration
#$my['username'] = "mysql username";
#$my['password'] = "mysql password";
#$my['hostname'] = "mysql hostname";
#$my['port_number'] = "mysql port number";
#$my['database'] = "mysql database";

#$myid = mysql_pconnect($my['hostname'].":".$my['port_number'],$my['username'],$my['password']);
#mysql_select_db($my['database'],$myid);

### Retrieving POST and GET requests
$var_post = isset($_POST['var_post']) ? $_POST['var_post'] : NULL;
$var_get = isset($_GET['var_get']) ? $_GET['var_get'] : NULL;
$action = isset($_GET['action']) ? $_GET['action'] : NULL; # Used in the Action's section below.

### Retrieving command line arguments in Command Line Interface (CLI) mode
### Usage at command line: php myscript.php argument1 argument2
#$arg1 = $_SERVER['argv'][1]; # If using CLI mode, this is the first argument. 0 is the script itself.
#$arg1 = $_SERVER['argv'][2]; # If using CLI mode, this is the second argument.

### Constant variables (Remember and don't overwrite them.)
$httphost = $_SERVER['HTTP_HOST']; # www.example.com
$useragent = $_SERVER['HTTP_USER_AGENT']; # Mozilla ... Firefox
$referer = $_SERVER['HTTP_REFERER']; # page that sent you to this one
$remoteip = $_SERVER['REMOTE_ADDR']; # requesting ip address
$qs = $_SERVER['QUERY_STRING']; # query string
$requesturi = $_SERVER['REQUEST_URI']; # /path/phpinfo.php?querystring=included
$phpself = $_SERVER['PHP_SELF']; # /path/phpinfo.php (query string not included)

### Initialize any variables here.
$html = $page_content = "";

### Actions
# login.php should contain your login process. It can also populate the $page_content variable.
# javascript.php should set the $javascript variable which will be printed in the html <head>
#      tag between <script> tags.
# myprogram.php should contain $action's and should return the $page_content variable which
#      gets printed in the <body> of the html.
# Sample syntax for each of these included files obeying the definition at the top of index.php.
# &lt;?php if(!defined("myprogram")){ exit(0); }
#       /* Your code goes here. */
# ?&gt;
# Sorry, &lt; = < and &gt; = >. Make sure you change those when creating the files below that are required.
###
#require_once("ssi/login.php");
#require_once("ssi/javascript.php");
#require_once("ssi/myprogram.php");

### Put everything that will go between <body> and </body> in the $page_content variable.
$page_content .= "<div><p><a href=\"http://validator.w3.org/check?uri=referer\"><img style=\"border:0;\" src=\"http://www.w3.org/Icons/valid-xhtml10-blue\" alt=\"Valid XHTML 1.0 Strict\" height=\"31\" width=\"88\" /></a></p></div>";

### $html is the variable that should be printed at the very end of the script. This is the actual HTML page.
$html .= <<<eof
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>{$site_title}</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!--<link rel="stylesheet" href="css/default.css" type="text/css" />-->
<style type="text/css">
/* CSS goes here */
body {
       font-family:sans-serif;
       font-size:100%;
       }
</style>
<!--<script src="your_javascript_file.js" type="text/javascript"></script>-->
<script type="text/javascript">
/* JavaScript goes here */
/* The javascript variable below is populated via ssi/javascript.php */
{$javascript}
/* Ajax Stuff */
function http_request()
{
        var http;
        try
        {
                // Firefox ...
                http = new XMLHttpRequest();
        }
        catch(e)
        {
                // IE
                try
                {
                        http = new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch(e)
                {
                        try
                        {
                                http = new ActiveXObject("Microsoft.XMLHTTP");
                        }
                        catch(e)
                        {
                                alert("Ajax not supported.");
                                return false;
                        }
                }
        }

        return http;
}

function example_function(val,iid)
{
        http = http_request();

        http.onreadystatechange=function()
        {
                // Request has been sent and received
                if(http.readyState == 4)
                {
                        // Make sure the http status is 200 before displaying stuff
                        // If not, alert the user there was an error.
                        if(http.status == 200)
                        {
                                // http.responseText contains the output of ajax.php which was called
                                // with http.open()
                                var response = http.responseText;

                                // Populate a division with the output of ajax.php
                                document.getElementById('reponse_div').innerHTML = response;
                        }
                        else
                        {
                                alert("There has been a server " + http.status + " error.");
                        }
                }
                // Request is being processed. Show loading image or something like that here.
                if(http.readyState == 1)
                {
                        document.getElementById('loading_div').innerHTML = "<img src=\"loading.gif\" alt=\"loading image\" />";
                }
        }
        http.open("POST","ajax.php?action=some_action",true);
        http.send(null);
}

</script>
</head>
<body>
<div id="container">
{$page_content}
</div><!--container-->
</body>
</html>
eof
;

print($html);
?>

Page Comments (Click to edit)






[Click to add or edit comments])

Please prepend comments below including a date

Design by N.Design Studio, adapted by solidGone.org (version 1.0.0)
Have a nice day.