Questions about this topic? Sign up to ask in the talk tab.

Php

From NetSec
Revision as of 02:38, 3 June 2012 by LaraNnvuuk (Talk | contribs) (Created page with "PHP Hypertext Preprocessor (PHP) is an HTML-embedded server side scripting language. It has become the most common programming language used by developers for web applications. ...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

PHP Hypertext Preprocessor (PHP) is an HTML-embedded server side scripting language. It has become the most common programming language used by developers for web applications. PHP can be installed using your respective package manager with these commands:

  • Debian/Ubuntu
 apt-get install php5-cli
  • Arch Linux
 sudo pacman -S php-apache

Basic Formatting

All PHP code must be wrapped in the following:

<syntaxhighlight lang="php"> <?php

  1. Code goes here

?><\syntaxhighlight>

Here is an example of a basic hello world program using PHP and HTML:

<syntaxhighlight lang="php"> My First PHP Program <title> </head> <body> <?php echo "Blackhat Academy Rules!"; ?> </body> </syntaxhighlight> </p> </td></tr></table> <p>PHP is not whitespace driven. Your spacing between tags, instructions, ect. does not affect the flow of the program. </p> <h2><span class="mw-headline" id="Variables">Variables</span></h2> <p>A variable is how you store a value such as a string or integer. An example where a variable would be used is if you wanted to handle a string multiple times throughout your application. Here is an example of a variable and how it can be used: </p> <table class="wikitable" width="100%"> <tr> <td> <p><syntaxhighlight lang="php"> <?php $variable = "Blackhat Academy"; $variable1 = "Rules!"; echo $variable . $variable1 ?></syntaxhighlight> </p> </td></tr></table> <p>This snippet of code will display the following: Blackhat Academy Rules! </p> <h2><span class="mw-headline" id="Strings">Strings</span></h2> <p>Strings have already been used within this page. A string is a series of characters. PHP supports a 256-character set. Strings can be stored in variables or standalone within an instruction. </p><p>The following is an example of a string stored in a variable and a string used with the echo function. </p> <table class="wikitable" width="100%"> <tr> <td> <p><syntaxhighlight lang="php"> <?php $variable = "I love Blackhat Academy!\n"; echo $variable; echo "I love BHA!"; ?></syntaxhighlight> </p> </td></tr></table> <p>\n is used for a newline. This is called an escaped character and is only used within double quotations (""). </p> <ul><li>List of escaped characters:</li></ul> <p>\n - newline \r - carriage return \t - tab \$ - dollar sign \"" - double quote </p><p>If you do not want to interpret escaped characters, wrap your strings in single quotations (<i>). However if you want to use a single quote within a string you have to escape the quote with a backslash</i> </p><p>example: </p> <table class="wikitable" width="100%"> <tr> <td> <p><syntaxhighlight lang="php"> $string = 'I\'m a p </p> </td></tr></table> <h2><span class="mw-headline" id="Operators">Operators</span></h2> <p>Operators are used to compare variables, mathematics, and more. For example, you can set a variable equal to another variable using the '=' operator. </p> <ul><li>List of operators:</li></ul> <pre> + - Addition - - Subtraction * - Multiplication / - Division  % - Modulus </pre> <table class="wikitable" width="100%"> <tr> <td> <p><syntaxhighlight lang="php"> $add = 1 + 1; $subtract = 5 - 2; $multiply = 6 * 5; $divide = 14/7 modulis = 5 % 2; </p><p>echo "1 + 1 = ".$add."<br />"; echo "5 - 2 =".$subtract."<br />"; echo "6 * 5 =".$multiply."<br />"; echo "14 / 7 =".$divide."<br />"; echo "5 % 2 =".$modulus; <\syntaxhighlight> </p> </td></tr></table> <p>Comparison operators are used to evaluate true or false when comparing variables and/or values </p> <ul><li>List of comparison operators:</li></ul> <pre> == - Equal To  != - Not Equal To < - Less than > - Greater than <= - Less Than or Equal To >= - Greater Than or Equal To </pre> <!-- NewPP limit report CPU time usage: 0.017 seconds Real time usage: 0.018 seconds Preprocessor visited node count: 62/1000000 Preprocessor generated node count: 182/1000000 Post‐expand include size: 1002/2097152 bytes Template argument size: 768/2097152 bytes Highest expansion depth: 3/40 Expensive parser function count: 0/100 --> <!-- Transclusion expansion time report (%,ms,calls,template) 100.00% 5.492 1 - -total 70.79% 3.888 6 - Template:Code --> </div><div class="printfooter"> Retrieved from "<a dir="ltr" href="http://nets.ec/index.php?title=Php&oldid=6857">http://nets.ec/index.php?title=Php&oldid=6857</a>"</div> <div id='catlinks' class='catlinks catlinks-allhidden'></div> <!-- end content --> <div class="visualClear"></div> </div> </div> </div> <div id="column-one"> <h2>Navigation menu</h2> <div id="p-cactions" class="portlet" role="navigation"> <h3>Views</h3> <div class="pBody"> <ul> <li id="ca-nstab-main" class="selected"><a href="/Php" title="View the content page [c]" accesskey="c">Page</a></li> <li id="ca-talk" class="new"><a href="/index.php?title=Talk:Php&action=edit&redlink=1" title="Discussion about the content page [t]" accesskey="t">Discussion</a></li> <li id="ca-viewsource"><a href="/index.php?title=Php&action=edit&oldid=6857" title="This page is protected. You can view its source [e]" accesskey="e">View source</a></li> <li id="ca-history"><a href="/index.php?title=Php&action=history" title="Past revisions of this page [h]" accesskey="h">History</a></li> </ul> </div> </div> <div class="portlet" id="p-personal" role="navigation"> <h3>Personal tools</h3> <div class="pBody"> <ul> <li id="pt-uls" class="active"><a href="#" class="uls-trigger autonym">English</a></li> <li id="pt-login"><a href="/index.php?title=Special:UserLogin&returnto=Php&returntoquery=oldid%3D6857" title="You are encouraged to log in; however, it is not mandatory [o]" accesskey="o">Log in</a></li> <li id="pt-createaccount"><a href="//nets.ec/Special:RequestAccount" title="You are encouraged to create an account and log in; however, it is not mandatory">Request account</a></li> </ul> </div> </div> <div class="portlet" id="p-logo" role="banner"> <a href="/Main_Page" class="mw-wiki-logo" title="Visit the main page"></a> </div> <div class="generated-sidebar portlet" id="p-Wiki" role="navigation"> <h3>Wiki</h3> <div class='pBody'> <ul> <li id="n-mainpage-description"><a href="/Main_Page" title="Visit the main page [z]" accesskey="z">Main page</a></li> <li id="n-The-index"><a href="/Category:Indexing">The index</a></li> <li id="n-Contribute"><a href="/Category:Requested_maintenance">Contribute</a></li> <li id="n-recentchanges"><a href="/Special:RecentChanges" title="A list of recent changes in the wiki [r]" accesskey="r">Recent changes</a></li> <li id="n-randompage"><a href="/Special:Random" title="Load a random page [x]" accesskey="x">Random page</a></li> </ul> </div> </div> <div class="generated-sidebar portlet" id="p-Community" role="navigation"> <h3>Community</h3> <div class='pBody'> <ul> <li id="n-IRC-Chat"><a href="/IRC">IRC Chat</a></li> <li id="n-.40NetsecStaff"><a href="http://twitter.com/netsecstaff" rel="nofollow">@NetsecStaff</a></li> <li id="n-Requesting-an-account"><a href="/Requesting_an_account">Requesting an account</a></li> <li id="n-Classes"><a href="/Current:Classes">Classes</a></li> </ul> </div> </div> <div id="p-search" class="portlet" role="search"> <h3><label for="searchInput">Search</label></h3> <div id="searchBody" class="pBody"> <form action="/index.php" id="searchform"> <input type='hidden' name="title" value="Special:Search"/> <input type="search" name="search" placeholder="Search" title="Search NetSec [f]" accesskey="f" id="searchInput" /> <input type="submit" name="go" value="Go" title="Go to a page with this exact name if exists" id="searchGoButton" class="searchButton" />  <input type="submit" name="fulltext" value="Search" title="Search the pages for this text" id="mw-searchButton" class="searchButton" /> </form> </div> </div> <div class="portlet" id="p-tb" role="navigation"> <h3>Tools</h3> <div class="pBody"> <ul> <li id="t-whatlinkshere"><a href="/Special:WhatLinksHere/Php" title="A list of all wiki pages that link here [j]" accesskey="j">What links here</a></li> <li id="t-recentchangeslinked"><a href="/Special:RecentChangesLinked/Php" title="Recent changes in pages linked from this page [k]" accesskey="k">Related changes</a></li> <li id="t-specialpages"><a href="/Special:SpecialPages" title="A list of all special pages [q]" accesskey="q">Special pages</a></li> <li id="t-print"><a href="/index.php?title=Php&oldid=6857&printable=yes" rel="alternate" title="Printable version of this page [p]" accesskey="p">Printable version</a></li> <li id="t-permalink"><a href="/index.php?title=Php&oldid=6857" title="Permanent link to this revision of the page">Permanent link</a></li> <li id="t-info"><a href="/index.php?title=Php&action=info" title="More information about this page">Page information</a></li> </ul> </div> </div> </div><!-- end of the left (by default at least) column --> <div class="visualClear"></div> <div id="footer" role="contentinfo"> <div id="f-poweredbyico"> <a href="//www.mediawiki.org/"><img src="/resources/assets/poweredby_mediawiki_88x31.png" alt="Powered by MediaWiki" srcset="/resources/assets/poweredby_mediawiki_132x47.png 1.5x, /resources/assets/poweredby_mediawiki_176x62.png 2x" width="88" height="31" /></a> </div> <ul id="f-list"> <li id="privacy"><a href="/NetSec:Privacy_policy" title="NetSec:Privacy policy">Privacy policy</a></li> <li id="about"><a href="/NetSec:About" title="NetSec:About">About NetSec</a></li> <li id="disclaimer"><a href="/NetSec:General_disclaimer" title="NetSec:General disclaimer">Disclaimers</a></li> </ul> </div> </div> <script>if(window.jQuery)jQuery.ready();</script><script>if(window.mw){ mw.loader.state({"site":"ready","user":"ready","user.groups":"ready"}); }</script> <script>if(window.mw){ mw.loader.load(["mediawiki.toc","mediawiki.action.view.postEdit","mediawiki.user","mediawiki.hidpi","mediawiki.page.ready","mediawiki.searchSuggest","ext.uls.pt"],null,true); }</script> <script src="//meta.wikimedia.org/geoiplookup"></script> <script>if(window.mw){ mw.config.set({"wgBackendResponseTime":134}); }</script></body></html>