PHP Index
- Wiki.PHP
- Wiki.PhpAuthenticationScript
- Wiki.PhpClasses
- Wiki.PhpDatabaseAbstraction
- Wiki.PhpIndex
- Wiki.PhpMultipleUploadInputBoxesAndProcessingScript
- Wiki.PhpNotes
- Wiki.PhpNotes2
- Wiki.PhpNotes3
- Wiki.PhpSqlite
- Wiki.PhpTemplates
- Wiki.Php-AHandyWayOfCommentingForDebugging
- Wiki.Php-AScriptICreatedThatMimicsSimpleXMLInPHP5
- Wiki.Php-AccessCharactersOfStringWithArraySyntax
- Wiki.Php-ApplyAFunctionToEveryEntryOfAnArray
- Wiki.Php-ArrayOfMysqlStopWords
- Wiki.Php-ArraysAndStdClassObjects
- Wiki.Php-BackTickOperatorForExecutingShellCommands
- Wiki.Php-BackupYourListOfPearPackages
- Wiki.Php-BitwiseOperators
- Wiki.Php-Break
- Wiki.Php-ChainingMethodsOOP
- Wiki.Php-CheckToSeeIfHostIsUpOrDown
- Wiki.Php-ClassConstants
- Wiki.Php-Classes
- Wiki.Php-CompressYourHttpTraffic
- Wiki.Php-ConditionalStatementsWithEmptyConditions
- Wiki.Php-ConvertAnObjectToAnArray
- Wiki.Php-ConvertTextLinksToActualHTMLLinks
- Wiki.Php-ConvertingXMLToUTF-8OrAnyOtherEncoding
- Wiki.Php-CreateAZipFile
- Wiki.Php-CreateArrayElementsViaQueryString
- Wiki.PHP-Create1920x1080ImagesScript
- Wiki.Php-CustomErrorHandler
- Wiki.Php-DateKeepsReturningADateOf1969
- Wiki.Php-DateQueriesInOracleWithOci8PhpDrivers
- Wiki.Php-EncryptAndDecryptFunctions
- Wiki.Php-EncryptAnyFile
- Wiki.Php-EndOfLineCharacter
- Wiki.Php-EregVsPreg
- Wiki.Php-ErrorFetchingHttpHeaders
- Wiki.Php-EscapingSQLiteStrings
- Wiki.Php-ExampleRegularExpressionWhichWasUsefulInCreatingAWikiEngine
- Wiki.Php-ExecVersusUsingBackticksForSystemCalls
- Wiki.Php-ExportContactsInEntourageExportEntourageContacts
- Wiki.Php-ExtensiveListOfRegularExpressions
- Wiki.Php-FatalErrorAllowedMemorySizeOf8388608BytesExhausted
- Wiki.Php-FiguringOutWhenDSTStarts
- Wiki.Php-FilePutContentsStripsLastLineEnding
- Wiki.Php-FindOutWhatModulesAreCompiledIntoYourPHPFromTheCommandLineInterfaceCli
- Wiki.Php-FlagsToRemoveLineEndingsInTheFileFunction
- Wiki.Php-FunctionThatAutomaticallyCreatesRealHtmlLinksFromJustText
- Wiki.Php-FunctionToBuildAQueryString
- Wiki.Php-FunctionToValidateAnXmlFile
- Wiki.Php-FunctionsThatCauseCaching
- Wiki.Php-GetTheUsernameFromEmailString
- Wiki.Php-GettingInformationFromAPathToAFile
- Wiki.Php-GlobByExpandingBraces
- Wiki.Php-GLOBALVariables
- Wiki.Php-GmailImapConnectionStringForAllMail
- Wiki.Php-GreatExampleOfPassingByReference
- Wiki.Php-HandlingIntegerTypes
- Wiki.Php-HandlingNamespacesWithSimplexml
- Wiki.Php-HandlingPropertiesOfAnObjectThatHaveProblemCharactersLikeColonsForExample
- Wiki.Php-Hashing
- Wiki.Php-HowMuchDidYourMeetingCost
- Wiki.Php-HowToCommitOracleQueries
- Wiki.Php-HowToCreateAnInfiniteLoop
- Wiki.Php-HowToDisplayOnlyCertainPHPErrors
- Wiki.Php-HowToGenerateACryptoQuote
- Wiki.Php-HowToInsertElementsInsideAnArray
- Wiki.Php-HowToInstallOptionalFeaturesOfPackage
- Wiki.Php-HowToMakeAnInteractiveShellScriptInPHP
- Wiki.Php-HowToPrintEveryVariableAndItsValueThatIsBeingUsedInAPHPScript
- Wiki.Php-HowToRemoveAByteOrderMark
- Wiki.Php-HowToRenameFilesWithoutSpecialCharacters
- Wiki.Php-HowToSetUserAgentOnFileGetContents
- Wiki.Php-HowToStartASession
- Wiki.Php-HowToUseThePearPackageMdb2
- Wiki.Php-HttpPostWithCurl
- Wiki.Php-ImagemagickExamples
- Wiki.Php-InitialParsingOfAXMLFile
- Wiki.Php-InvalidSuppliedArgumentErrorMySQLAndPHP
- Wiki.Php-Is_intVersusIs_numeric?
- Wiki.Php-JavaScriptLibraryThatMimicsPhpFunctions
- Wiki.Php-LockPageBasedOnHourOfTheDay
- Wiki.Php-LockingFiles
- Wiki.Php-LoopThroughAnArrayManually
- Wiki.Php-LoopingThroughAStringCharacterByCharacterLineByLine
- Wiki.Php-LoopingThroughLettersInsteadOfNumbers
- Wiki.Php-MakeARESTRequestUsingCurl
- Wiki.Php-Message-IdAndDateAppearingInTheBodyOfAnEmailWhenUsingTheMailFunction
- Wiki.Php-MoreDetailedErrorOutputing
- Wiki.Php-MultidimensionalArraySorting
- Wiki.Php-MyDefaultFunctions
- Wiki.Php-NegativeLookupRegularExpression
- Wiki.Php-NiceCommandLineScriptToRenameBadFileNames
- Wiki.Php-NiftyLooping
- Wiki.Php-Non-GUIStatusDialogForPhpCommandLineInterfaceScripting
- Wiki.Php-ObjectVisibilty
- Wiki.Php-OneWayToRemoveACookie
- Wiki.Php-ParseChromeHtmlBookmarksFile
- Wiki.Php-ParsePhpFilesAsTextWithHtaccess
- Wiki.Php-PassingHtmlEntitiesAndProcessingThem
- Wiki.Php-PearPhpCodeSnifferForAutoFormattingCode
- Wiki.Php-PHPsBuiltInCodeHighlighting
- Wiki.Php-PHPErrorHandlingFunction
- Wiki.Php-PHPIndex
- Wiki.Php-PHPOracleOci8Example
- Wiki.Php-PlaceCurlRequestResponseInVariable
- Wiki.Php-PotentialGotchaWithTheCountFunction
- Wiki.Php-PreventFlashCaching
- Wiki.Php-PrintVersusEcho
- Wiki.Php-ProblemsPrintsAStringThatHasMathOperationsInTheMiddle
- Wiki.Php-PuttingFileContentsIntoAStringOrArray
- Wiki.Php-QuestionMarkColonControlStatementGotcha
- Wiki.Php-QuickScriptThatCanBackupAFileYouAreWorkingOn
- Wiki.Php-QuickScriptToDisplayAllImagesInADirectory
- Wiki.Php-QuickScriptToTestPageLoadTimes
- Wiki.Php-ReadingHeadersSent
- Wiki.Php-References
- Wiki.Php-RegularExpressionForMatchingEmails
- Wiki.Php-RegularExpressions
- Wiki.Php-RemovingHtmlSpecialCharactersFromAString
- Wiki.Php-RemovingWhiteSpacesAndOtherUnwantedCharacters
- Wiki.Php-ScriptThatStripsExcessWhiteSpaceFromString
- Wiki.Php-ScriptToShowMockupDesigns
- Wiki.Php-SearchAndReplace
- Wiki.Php-SendPostVariableFromScript
- Wiki.Php-SessionTimeoutConfigurationPhpIni
- Wiki.Php-ShebangProblems
- Wiki.Php-SimpleCookieLoginScript
- Wiki.Php-SimpleScriptToGetSizeOfDirectory
- Wiki.Php-SimpleXMLWithXPath
- Wiki.Php-SmallBackupScript
- Wiki.Php-SQLite3ClassExample
- Wiki.Php-StoringCookiesInAnArray
- Wiki.Php-StripAllOrSomePHPAndHtmlTagsFromString
- Wiki.Php-TableOfContents
- Wiki.Php-TernaryOperators-HandyWayOfGettingA_GETVariableOr_POSTOr_COOKIEOrAnythingElseYouWant?
- Wiki.Php-TestTheSpeedOfYourProcessor
- Wiki.Php-TidyYourHtmlWithPhp
- Wiki.Php-TriggerAFileDownload
- Wiki.Php-TurnCachingOff
- Wiki.Php-UltimateHandlePrintFunction
- Wiki.Php-UpdateThePearChannelsProtocols
- Wiki.Php-UsePhpInJavascript
- Wiki.Php-UsingGetcwdAndAvoidingThePossibleOutputsYouDontWant
- Wiki.Php-UsingPregFunctionsSuchAsPreg_replaceAndAvoidingProblems?
- Wiki.Php-UsingVarAndVarAndTheDifferences
- Wiki.Php-UsingXsltProcessorToConvertXml
- Wiki.Php-VariableVariablesAndHowToUseIllegalVariableNames
- Wiki.Php-WhatIs0xff
- Wiki.Php-WritingFiles
- Wiki.Php-ZipLikeFilesIntoChunks
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.
# <?php if(!defined("myprogram")){ exit(0); }
# /* Your code goes here. */
# ?>
# Sorry, < = < and > = >. 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);
?>
### 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.
# <?php if(!defined("myprogram")){ exit(0); }
# /* Your code goes here. */
# ?>
# Sorry, < = < and > = >. 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);
?>
[Click to add or edit comments])
Please prepend comments below including a date