SlideShare uma empresa Scribd logo
1 de 114
  -By V.Gouthaman
INTRODUCTION PHP: Hypertext Preprocessor is a widely used, general-purpose scripting language that was originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document. As a general-purpose programming language, PHP code is processed by an interpreter application in command-line mode performing desired operating system operations and producing program output on its standard output channel.
It may also function as a graphical application. PHP is available as a processor for most modern web servers and as standalone interpreter on most operating systems and computing platforms. PHP was originally created by Rasmus Lerdorf in 1995 and has been in continuous development ever since. The main implementation of PHP is now produced by The PHP Group and serves as the de facto standard for PHP as there is no formal specification. PHP is free software released under the PHP License.
INSTALLATION AND CONFIGURATION
Step 1:  Download the latest Windows PHP Binaries (MSI file) from “http://www.php.net/get/php-5.2.4-win32-installer.msi/from/a/mirror” . I choose the eZNetworking mirror because it is the closest one to Malaysia. Choose a mirror that is nearer to your country for a faster file download. The latest PHP version that I downloaded is 5.2.4. Save the file to your Desktop. Step 2:  Right click on the file and click “Install“.
Step 3:  Click “Next ” once the Welcome page is displayed.
Step 4:  Select “I accept the license agreement” and click “Next “.
Step 5:  Change your PHP installation path OR just accept the default path - C:rogram FilesHPand click “Next “.
Step 6:  On the Web Server Setup screen, select the Apache 2.2.x Module and click “Next “. select-webserver-to-install-php-on-apache-2
Step 7:  On the Apache Configuration Directory screen, browse for the Apache configuration directory (conf) OR just enter C:rogram Filespache Software Foundationpache2.2onfand click “Next ” to proceed with the installation.
Step 8:  For now, accept the default selection and click “Next”.
Step 9:  Click “Install ” to install PHP 5 on Windows.
Step 10:  Click “Finish ” once completed. PHP 5 is successfully installed.
Step 11:  Start your Apache 2.2 server using the “Monitor Apache Servers” console (Start -> Apache HTTP Servers 2.2.4 -> Monitor Apache Servers ). You can see that PHP was successfully installed by checking the Apache status at the bottom of the console.
Testing  PHP 5 Installation Step 1:  Open up your Windows Notepad. Type in “<?php phpinfo(); ?>” inside the file. Save this file as “info.php” inside your Apache root directory, C:rogram Filespache Software Foundationpache2.2tdocs .
Step 2: Open up your web browser. In the address bar, type in your web server domain name plus info.php as the file name. Example: http://www.syahid.com/info.php . You should get a PHP configuration page just like the one below. Congratulations! You have successfully installed and test PHP 5 on Windows!
CONFIGURATION
Configure PHP 5 to Work with MySQL with MySQL PHP Extension Previously, we have installed PHP with minimal modules / extension. To add MySQL support to PHP, you need to change your PHP installation - by adding the MySQL extension on top of your PHP installation. Please make sure that your original PHP 5 MSI installer still remains at its original place .
Step 1:  Open the Add / Remove Programs console via Windows Control Panel. Find the PHP 5.x.x entry and click “Change “.
Step 2:  Click “Next ” once you are prompted the Welcome page.
Step 3:  Click the “Change ” button to proceed.
Step 4:  Select Apache 2.2.x as shown in the picture below. Click “Next ” once again.
Step 5:  Select your Apache configuration directory (conf) - the directory where your httpd.conf resides. Click “Next ” once done.
 
Step 6:  On the “Choose items to install” screen, click on the plus (+) icon next to Extensions to expand the list. click-plus-button-to-expand-extensions-part
 
Step 7:  Select on the “X” next to “MySQL” and select “Entire feature will be installed on local hard drive”. Click “Next” again
Step 8:  Click the “Change” button to save all the PHP configuration changes.
Step 9:  Finally, restart your Apache 2.2 web server! You can check out that the MySQL extension support for PHP was successfully installed by checking out the info.php / index.php page that was created before.
PHP  SAMPLE PROGRAMS
Sample 1: current date in an HTML page <html> <head> <title>Example #1 TDavid's Very First PHP Script ever!</title> </head> <? print(Date(&quot;l F d, Y&quot;)); ?> <body> </body> </html>
2.current month/day/date format <html> <head> <title>Example #3 TDavid's Very First PHP Script ever!</title> </head> <? print(Date(&quot;m/j/y&quot;)); ?> <body> </body> </html>
3. current month/day/date with HTML colors & formatting <html> <head> <title>PHP Script examples!</title> </head> <font face=&quot;Arial&quot; color=&quot;#FF00FF&quot;><strong><? print(Date(&quot;m/j/y&quot;)); ?> </strong></font> <body> </body> </html>
4. change background color based on day of the week using if else elseif statements <html> <head> <title>Background Colors change based on the day of the week</title> </head> <? $today = date(&quot;l&quot;); print(&quot;$today&quot;); if($today == &quot;Sunday&quot;) { $bgcolor = &quot;#FEF0C5&quot;; }
elseif($today == &quot;Monday&quot;) { $bgcolor = &quot;#FFFFFF&quot;; } elseif($today == &quot;Tuesday&quot;) { $bgcolor = &quot;#FBFFC4&quot;; } elseif($today == &quot;Wednesday&quot;) { $bgcolor = &quot;#FFE0DD&quot;; } elseif($today == &quot;Thursday&quot;){ $bgcolor = &quot;#E6EDFF&quot;;}
elseif($today == &quot;Friday&quot;) { $bgcolor = &quot;#E9FFE6&quot;; } else { // Since it is not any of the days above it must be Saturday $bgcolor = &quot;#F0F4F1&quot;; } print(&quot;<body bgcolor=amp;quot;$bgcoloramp;quot;>&quot;); ?> <br>This just changes the color of the screen based on the day of the week </body> </html>
<html> <head> <title>Background Colors change based on the day of the week</title></head> <?$today = date(&quot;w&quot;); $bgcolor = array( &quot;#FEF0C5&quot;, &quot;#FFFFFF&quot;, &quot;#FBFFC4&quot;, &quot;#FFE0DD&quot;, &quot;#E6EDFF&quot;, &quot;#E9FFE6&quot;, &quot;#F0F4F1&quot; ); ?> <body bgcolor=&quot;<?print(&quot;$bgcolor[$today]&quot;);?>&quot;> <br>This just changes the color of the screen based on the day of the week </body> </html>
5. Add date time stamp &quot;page last updated on..&quot; using filemtime function using forms, cookies, flat file databases, random number generation <html> <head> <title>Page last updated on month/date/year hour:min PHP Script</title> </head> <? $last_modified = filemtime(&quot;example7.php3&quot;); print(&quot;Last Modified &quot;); print(date(&quot;m/j/y h:i&quot;, $last_modified)); ?> </body> </html>
6. Setting and retrieving a cookie <? $check = &quot;test&quot;; $check .= $filename; if ($test == $check) {print(&quot;<HTML><BODY>You have already voted. Thank you.</BODY></HTML>&quot;); } else{ $rated = &quot;test&quot;; $rated .= $filename; setcookie(test, $rated, time()+86400); print(&quot;<HTML><BODY><br>You haven't voted before so I recorded your vote</BODY></HTML>&quot;); } ?>
7. Getting an average number using PHP <? $total_ratings = (3+2+3+1+5+2+3); $total_votes = 7; $average = $total_ratings / $total_votes; print(&quot;The Average Rating Is: $average&quot;); ?>
8. showing the surfer average vote statistics, using printf function <? $path = &quot;/YOUR/PATH/TO/public_html/php_diary/data&quot;; $filename = &quot;122499.dat&quot;; $x= -1; if($file = fopen(&quot;$path/$filename&quot;, &quot;r&quot;)) {  while(!feof($file)) {  $therate = fgetss($file, 255); $x++; $count = $count + $therate; } fclose($file); } $average = ($count / $x); print(&quot;Surfer Average Rating for 12/24/99: &quot;); printf(&quot;%.2f&quot;, $average); print(&quot;<br>Total Surfer Votes: $x&quot;); ?>
9. Generating a random number from 0 to 9 <? srand(time()); $random = (rand()%9); print(&quot;Random number between 0 and 9 is: $random&quot;); ?>
10. php simple slot machine - multiple random  number generation <? function slotnumber() { srand(time()); for ($i=0; $i < 3; $i++) { $random = (rand()%3); $slot[] = $random; } print(&quot;<td width=amp;quot;33%amp;quot;><center>$slot[0]</td>&quot;); print(&quot;<td width=amp;quot;33%amp;quot;><center>$slot[1]</td>&quot;); print(&quot;<td width=amp;quot;33%amp;quot;><center>$slot[2]</td>&quot;); </tr>
11. php simple slot machine - multiple random  number generation <tr> <td width=&quot;100%&quot; colspan=&quot;3&quot; bgcolor=&quot;#008080&quot;><form method=&quot;POST&quot; action=&quot;example13.php3&quot;><div align=&quot;center&quot;><center><p><input type=&quot;submit&quot; value=&quot;Spin!&quot;></p> </center></div> </form> </td> </tr> </table> </center></div>
12. random text link advertising using predefined arrays mail, regular expressions, password protection <? $random_url = array(&quot;http://www.tdscripts.com/linkorg.html&quot;, &quot;http://www.tdscripts.com/keno.html&quot;, &quot;http://www.tdscripts.com/ezibill.shtml&quot;, &quot;http://www.tdscripts.com/tdforum.shtml&quot;, &quot;http://www.tdscripts.com/picofday.html&quot;, &quot;http://www.tdscripts.com/gutsorglory.html&quot;);
$url_title = array(&quot;Link Organizer&quot;, &quot;TD Keno&quot;, &quot;eziBill *Free Promotion!&quot;, &quot;TD Forum&quot;, &quot;TD Pic of Day PHP&quot;, &quot;Guts or Glory Poker PHP&quot;); $url_desc = array(&quot;- A comprehensive link list organizer&quot;, &quot;- Offer your site visitors an engaging Keno game without the monetary risk&quot;, &quot;- Sell access to and protect your membership area using iBill and our eziBill script&quot;, &quot;- An unthreaded messageboard script to exchange ideas with your site visitors&quot;, &quot;- Run your own picture of the day script from any site anywhere with this handy script&quot;, &quot;- A casino-style card game written entirely in PHP&quot;);
srand(time()); $sizeof = count($random_url); $random = (rand()%$sizeof); print(&quot;<center><a href=amp;quot;$random_url[$random]amp;quot;>$url_title[$random]</a> $url_desc[$random]</center>&quot;); ?>
13. forcing the text in a string to be all upper or lowercase <? // force all uppercase print(strtoupper(&quot;i bet this will show up as all letters capitalized<br>&quot;)); // force all lowercase print(strtolower(&quot;I BET THIS WILL SHOW UP AS ALL LETTERS IN LOWERCASE<br>&quot;)); // force the first letter of a string to be capitalized print(ucfirst(&quot;i bet this will show the first letter of the string capitalized<br>&quot;)); // force the first letter of each WORD in a string to be capitalized print(ucwords(&quot;i bet this will show the first letter of every word capitalized<br>&quot;)); ?>
14. searching through meta tags for a search engine <HTML> <BODY> <? $all_meta = get_meta_tags(&quot;010600.php3&quot;); print($all_meta[&quot;description&quot;]); print(&quot;<br>&quot;); print($all_meta[&quot;keywords&quot;]); ?> </BODY> </HTML>
15. searching through a directory and picking out files using a regular expression <? $diary_directory = opendir(&quot;.&quot;); while($filename = readdir($diary_directory)) { $filesplit = explode(&quot;.&quot;, $filename); $check_filename = $filesplit[0]; if(ereg(&quot;[0-9]{6}&quot;, $check_filename)) { $check_filename .= &quot;.$filesplit[1]&quot;; $valid_filename[] = $check_filename; } } closedir($diary_directory); for($index = 0; $index < count($valid_filename); $index++) { print(&quot;$valid_filename[$index]<br>&quot;); } ?>
16. shuffling and &quot;cutting&quot; a deck of playing cards <? $cards = array(&quot;ah&quot;, &quot;ac&quot;, &quot;ad&quot;, &quot;as&quot;, &quot;2h&quot;, &quot;2c&quot;, &quot;2d&quot;, &quot;2s&quot;, &quot;3h&quot;, &quot;3c&quot;, &quot;3d&quot;, &quot;3s&quot;, &quot;4h&quot;, &quot;4c&quot;, &quot;4d&quot;, &quot;4s&quot;, &quot;5h&quot;, &quot;5c&quot;, &quot;5d&quot;, &quot;5s&quot;, &quot;6h&quot;, &quot;6c&quot;, &quot;6d&quot;, &quot;6s&quot;, &quot;7h&quot;, &quot;7c&quot;, &quot;7d&quot;, &quot;7s&quot;, &quot;8h&quot;, &quot;8c&quot;, &quot;8d&quot;, &quot;8s&quot;, &quot;9h&quot;, &quot;9c&quot;, &quot;9d&quot;, &quot;9s&quot;, &quot;th&quot;, &quot;tc&quot;, &quot;td&quot;, &quot;ts&quot;, &quot;jh&quot;, &quot;jc&quot;, &quot;jd&quot;, &quot;js&quot;, &quot;qh&quot;, &quot;qc&quot;, &quot;qd&quot;, &quot;qs&quot;, &quot;kh&quot;, &quot;kc&quot;, &quot;kd&quot;, &quot;ks&quot;);
srand(time()); for($i = 0; $i < 52; $i++) { $count = count($cards); $random = (rand()%$count); if($cards[$random] == &quot;&quot;) { $i--; } else { $deck[] = $cards[$random]; $cards[$random] = &quot;&quot;; } }
srand(time()); $starting_point = (rand()%51); print(&quot;Starting point for cut cards is: $starting_point<p>&quot;); // display shuffled cards (EXAMPLE ONLY) for ($index = 0; $index < 52; $index++) { if ($starting_point == 52) { $starting_point = 0; } print(&quot;Uncut Point: <strong>$deck[$index]</strong> &quot;); print(&quot;Starting Point: <strong>$deck[$starting_point]</strong><br>&quot;); $starting_point++; } ?>
17. Reader rated most useful diary entries in descending order <HTML> <HEAD> <title>Reader Rated Most Useful Entries</title> </HEAD> <BODY> <table border=&quot;0&quot; width=&quot;100%&quot;> <tr> <td width=&quot;6%&quot; bgcolor=&quot;#00FFFF&quot;><p align=&quot;center&quot;><small><font face=&quot;Verdana&quot;>Rank</font></small></td> <td width=&quot;7%&quot; bgcolor=&quot;#00FFFF&quot;><p align=&quot;center&quot;><small><font face=&quot;Verdana&quot;>Rating</font></small></td>
<td width=&quot;11%&quot; bgcolor=&quot;#00FFFF&quot;><p align=&quot;center&quot;><small><font face=&quot;Verdana&quot;>Diary Date</font></small></td> <td width=&quot;76%&quot; bgcolor=&quot;#00FFFF&quot;><p align=&quot;left&quot;><small><font face=&quot;Verdana&quot;>Description of Diary Page</font></small> </td> <script language=&quot;php&quot;> $db = &quot;DATABASE NAME&quot;; $admin = &quot;MYSQL USER NAME&quot;; $adpass = &quot;MYSQL PASSWORD&quot;; $mysql_link = mysql_connect(&quot;localhost&quot;, $admin, $adpass); mysql_select_db($db, $mysql_link);
$query = &quot;SELECT * FROM avg_tally ORDER BY average DESC&quot;; $result = mysql_query($query, $mysql_link); if(mysql_num_rows($result)) { $rank = 1; while($row = mysql_fetch_row($result)) { print(&quot;</tr><tr>&quot;); if($color == &quot;#D8DBFE&quot;) { $color = &quot;#A6ACFD&quot;; } else { $color = &quot;#D8DBFE&quot;; } print(&quot;<td width=amp;quot;6%amp;quot; bgcolor=amp;quot;$coloramp;quot;><center><small>&quot;); print(&quot;<font face=amp;quot;Verdanaamp;quot;>$rank</font></small></center></td>&quot;); print(&quot;<td width=amp;quot;7%amp;quot; bgcolor=amp;quot;$coloramp;quot;><center><small>&quot;); print(&quot;<font face=amp;quot;Verdanaamp;quot;><strong>$row[1]</strong></font></small></center></td>&quot;); print(&quot;<td width=amp;quot;11%amp;quot; bgcolor=amp;quot;$coloramp;quot;><center><small>&quot;); $url = $row[2] . &quot;.php3&quot;;
if(!file_exists($url)) { $url = $row[2] . &quot;.html&quot;; } print(&quot;<font face=amp;quot;Verdanaamp;quot;><a href=amp;quot;$urlamp;quot;>$row[2]</a></font></small></center></td>&quot;); print(&quot;<td width=amp;quot;76%amp;quot; bgcolor=amp;quot;$coloramp;quot;><left><small>&quot;); print(&quot;<font face=amp;quot;Verdanaamp;quot;>$row[3]</font></small></left></td>&quot;); $rank++; } } </script> </table> </BODY> </HTML>
18. creating a mySQL table using a PHP script <? $mysql_db = &quot;DATABASE NAME&quot;; $mysql_user = &quot;YOUR MYSQL USERNAME&quot;; $mysql_pass = &quot;YOUR MYSQL PASSWORD&quot;; $mysql_link = mysql_connect(&quot;localhost&quot;, $mysql_user, $mysql_pass); mysql_select_db($mysql_db, $mysql_link); $create_query = &quot;CREATE TABLE tds_counter ( COUNT_ID INT NOT NULL AUTO_INCREMENT, pagepath VARCHAR(250), impressions INT, reset_counter DATETIME, PRIMARY KEY (COUNT_ID)  )&quot;;
19. creating a mySQL table using a PHP script mysql_query($create_query, $mysql_link); print(&quot;Table Creation for <b>tds_counter</b> successful!<p>&quot;); $insert = &quot;INSERT into tds_counter VALUES ( 0, '/php_diary/021901.php3', 0, SYSDATE() )&quot;; mysql_query($insert, $mysql_link); print(&quot;Inserted new counter successfully for this page: http://www.php-scripts.com/php_diary/021901.php3<p>&quot;); ?>
20. mySQL based counter script for multiple pagesAutomating manual tasks, date sorting, mktime() <? $db = &quot;DATABASE NAME&quot;; $admin = &quot;MYSQL USER NAME&quot;; $adpass = &quot;MYSQL PASSWORD&quot;; $mysql_link = mysql_connect(&quot;localhost&quot;, $admin, $adpass); mysql_select_db($db, $mysql_link); $result = mysql_query(&quot;SELECT impressions from tds_counter where COUNT_ID='$cid'&quot;, $mysql_link); if(mysql_num_rows($result)) { mysql_query(&quot;UPDATE tds_counter set impressions=impressions+1 where COUNT_ID='$cid'&quot;, $mysql_link); $row = mysql_fetch_row($result); if($inv != 1) { print(&quot;$row[0]&quot;); } }?>
21. Classify Email as Bounce (DSN) or Automated Reply <?php $bounce = new COM(&quot;Chilkat.Bounce&quot;); $success = $bounce->UnlockComponent('Anything for 30-day trial'); if ($success == false) { print 'Failed to unlock component' . &quot;&quot;; exit; } $email = new COM(&quot;Chilkat.Email&quot;);
//  Load an email from a .eml file. //  (This example loads an Email object from a .eml file, //  but the object could have been read //  directly from a POP3 or IMAP mail server using //  Chilkat's POP3 or IMAP implementations.) $success = $email->LoadEml('sampleBounce.eml'); if ($success == false) { print $email->lastErrorText() . &quot;&quot;; exit; }
$success = $bounce->ExamineMail($email); if ($success == false) { print $bounce->lastErrorText() . &quot;&quot;; exit; } if ($bounce->BounceType == 1) { //  Hard bounce, log the email address print 'Hard Bounce: ' . $bounce->bounceAddress() . &quot;&quot;; } if ($bounce->BounceType == 2) { //  Soft bounce, log the email address print 'Soft Bounce: ' . $bounce->bounceAddress() . &quot;&quot;; }
if ($bounce->BounceType == 3) { //  General bounce, no email address available. print 'General Bounce: No email address' . &quot;&quot;; } if ($bounce->BounceType == 4) { //  General bounce, log the email address print 'General Bounce: ' . $bounce->bounceAddress() . &quot;&quot;; } if ($bounce->BounceType == 5) { //  Mail blocked, log the email address print 'Mail Blocked: ' . $bounce->bounceAddress() . &quot;&quot;; }
if ($bounce->BounceType == 6) { //  Auto-reply, log the email address print 'Auto-Reply: ' . $bounce->bounceAddress() . &quot;&quot;; } if ($bounce->BounceType == 7) { //  Transient (recoverable) Failure, log the email address print 'Transient Failure: ' . $bounce->bounceAddress() . &quot;&quot;; } if ($bounce->BounceType == 8) { //  Subscribe request, log the email address print 'Subscribe Request: ' . $bounce->bounceAddress() . &quot;&quot;; } if ($bounce->BounceType == 9) { //  Unsubscribe Request, log the email address print 'Unsubscribe Request: ' . $bounce->bounceAddress() . &quot;&quot;; }
if ($bounce->BounceType == 10) { //  Virus Notification, log the email address print 'Virus Notification: ' . $bounce->bounceAddress() . &quot;&quot;; } if ($bounce->BounceType == 11) { //  Suspected bounce. //  This should be rare.  It indicates that the Bounce //  component found strong evidence that this is a bounced //  email, but couldn//t quite recognize everything it //  needed to be 100% sure.  Feel free to notify //  support@chilkatsoft.com regarding emails having this //  bounce type. print 'Suspected Bounce!' . &quot;&quot;;} ?>
22. Program to print a message <html> <h3>My first PHP Program</h3> <? echo &quot;Hello world!&quot;; ?> </html>
23. PHP Array <?php $employee_names[0] = &quot;Dana&quot;; $employee_names[1] = &quot;Matt&quot;; $employee_names[2] = &quot;Susan&quot;; echo &quot;The first employee's name is &quot;.$employee_names[0]; echo &quot;<br>&quot;; echo &quot;The second employee's name is &quot;.$employee_names[1]; echo &quot;<br>&quot;; echo &quot;The third employee's name is &quot;.$employee_names[2]; ?>
24.File Upload Script <html> <head> <title>A File Upload Script</title> </head> <body> <div> <?php if ( isset( $_FILES['fupload'] ) ) { print &quot;name: &quot;.  $_FILES['fupload']['name']  .&quot;<br />&quot;; print &quot;size: &quot;.  $_FILES['fupload']['size'] .&quot; bytes<br />&quot;; print &quot;temp name: &quot;.$_FILES['fupload']['tmp_name']  .&quot;<br />&quot;; print &quot;type: &quot;.  $_FILES['fupload']['type']  .&quot;<br />&quot;; print &quot;error: &quot;.  $_FILES['fupload']['error']  .&quot;<br />&quot;; if ( $_FILES['fupload']['type'] == &quot;image/gif&quot; ) { $source = $_FILES['fupload']['tmp_name']; $target = &quot;upload/&quot;.$_FILES['fupload']['name'];
move_uploaded_file( $source, $target );// or die (&quot;Couldn't copy&quot;); $size = getImageSize( $target ); $imgstr = &quot;<p><img width=amp;quot;$size[0]amp;quot; height=amp;quot;$size[1]amp;quot; &quot;; $imgstr .= &quot;src=amp;quot;$targetamp;quot; alt=amp;quot;uploaded imageamp;quot; /></p>&quot;; print $imgstr; } } ?> </div> <form enctype=&quot;multipart/form-data&quot; action=&quot;<?php print $_SERVER['PHP_SELF']?>&quot; method=&quot;post&quot;> <p> <input type=&quot;hidden&quot; name=&quot;MAX_FILE_SIZE&quot; value=&quot;102400&quot; /> <input type=&quot;file&quot; name=&quot;fupload&quot; /><br/> <input type=&quot;submit&quot; value=&quot;upload!&quot; /> </p> </form> </body>  </html>
25.Simple File Upload Form <html> <head> <title>A Simple File Upload Form</title> </head> <body> <form enctype=&quot;multipart/form-data&quot; action=&quot;<?print $_SERVER['PHP_SELF']?>&quot; method=&quot;post&quot;> <p> <input type=&quot;hidden&quot; name=&quot;MAX_FILE_SIZE&quot; value=&quot;102400&quot; /> <input type=&quot;file&quot; name=&quot;fupload&quot; /><br/> <input type=&quot;submit&quot; value=&quot;upload!&quot; /> </p> </form> </body> </html>
26.Creating an HTML Form That Accepts Mail-Related Information <html>  <head> <title>Simple Send Mail Form</title> </head><body> <h1>Mail Form</h1> <form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;SimpleEmail.php&quot;> <table> <tr><td><b>To</b></td><td><input type=&quot;text&quot; name=&quot;mailto&quot; size=&quot;35&quot;></td></tr> <tr><td><b>Subject</b></td> <td><input type=&quot;text&quot; name=&quot;mailsubject&quot; size=&quot;35&quot;></td></tr> <tr><td><b>Message</b></td> <td><textarea name=&quot;mailbody&quot; cols=&quot;50&quot; rows=&quot;7&quot;></textarea></td> </tr> <tr><td colspan=&quot;2&quot;> <input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Send&quot;> </td></tr></table></form></body> </html>
<!-- SimpleEmail.php <?php if (empty ($mailto) ) { die ( &quot;Recipient is blank! &quot;) ; } if (empty ($mailsubject) ){ $mailsubject=&quot; &quot; ;  } if (empty ($mailbody) ) { $mailbody=&quot; &quot; ;  } $result = mail ($mailto, $mailsubject, $mailbody) ; if ($result) { echo &quot;Email sent successfully!&quot; ; }else{ echo &quot;Email could not be sent.&quot; ; } ?>
27.React to Form action <HTML> <BODY> <FORM METHOD=&quot;POST&quot; ACTION=&quot;GetFormValue.php&quot;> <H2>Contact List</H2> <BR>Nickname: <BR><INPUT TYPE=&quot;TEXT&quot; NAME=&quot;Nickname&quot;> <BR> <BR>Full Name: <BR><INPUT TYPE=&quot;TEXT&quot; NAME=&quot;Fullname&quot;>
<BR> <BR>Memo: <BR><TEXTAREA NAME=&quot;Memo&quot; ROWS=&quot;4&quot; COLS=&quot;40&quot; WRAP=&quot;PHYSICAL&quot;> </TEXTAREA> <BR>  <BR> <INPUT TYPE=&quot;SUBMIT&quot;> </FORM> </BODY> <!-- GetFormValue.php <?php echo &quot;<BR>Nickname=$Nickname&quot;; echo &quot;<BR>Fullname=$Fullname&quot;; echo &quot;<BR>Memo=$Memo&quot;; ?>
28. Build query string based on form input <?php if (isset($_POST['submit'])) { $rowID = $_POST['id']; mysql_connect(&quot;mysql153.secureserver.net&quot;,&quot;java2s&quot;,&quot;password&quot;); mysql_select_db(&quot;java2s&quot;); $query = &quot;SELECT * FROM Employee WHERE ID='$id'&quot;; $result = mysql_query($query); list($name,$productid,$price,$description) = mysql_fetch_row($result); }
?> <form action=&quot;<?php echo $_SERVER['PHP_SELF']; ?>&quot; method=&quot;post&quot;> <select name=&quot;id&quot;> <option name=&quot;&quot;>Choose a employee:</option> <option name=&quot;1&quot;>1</option> <option name=&quot;2&quot;>2</option> <option name=&quot;3&quot;>3</option> </select> <input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Submit&quot; /> </form>
29. Checking input from a checkbox or a multiple select <?php $options = array('option 1', 'option 2', 'option 3'); $valid = true; if (is_array($_GET['input'])) { $valid = true; foreach($_GET['input'] as $input) { if (!in_array($input, $options)) { $valid = false; }  } if ($valid) { //process input } } ?>
30. Validating a single checkbox <?php $value = 'yes'; echo &quot;<input type='checkbox' name='subscribe' value='yes'/> Subscribe?&quot;; if (isset($_POST['subscribe'])) { if ($_POST['subscribe'] == $value) { $subscribed = true; } else { $subscribed = false;
print 'Invalid checkbox value submitted.'; } } else { $subscribed = false; } if ($subscribed) { print 'You are subscribed.'; } else { print 'You are not subscribed'; }
31. Deal with Array Form Data <HTML> <BODY> <FORM METHOD=&quot;POST&quot; ACTION=&quot;DealWithArrayFormData.php&quot;> <H1>Contact Information</H1> <TABLE><TR> <TD>Childrens' Names:</TD> </TR> <TR> <TD><INPUT TYPE=&quot;TEXT&quot; NAME=&quot;children[]&quot;></TD> </TR> <TR> <TD><INPUT TYPE=&quot;TEXT&quot; NAME=&quot;children[]&quot;></TD> </TR> <TR> <TD><INPUT TYPE=&quot;TEXT&quot; NAME=&quot;children[]&quot;></TD> </TR>
<TR> <TD><INPUT TYPE=&quot;TEXT&quot; NAME=&quot;children[]&quot;></TD> </TR> <TR> <TD><INPUT TYPE=&quot;TEXT&quot; NAME=&quot;children[]&quot;></TD> </TR> </TABLE> <BR> <BR> <BR> <INPUT TYPE=&quot;SUBMIT&quot; VALUE=&quot;Submit&quot;> <BR> <BR> <INPUT TYPE=&quot;RESET&quot;  VALUE=&quot;Clear the Form&quot;> </FORM> </BODY> </HTML>
<!-- DealWithArrayFormData.php <?php foreach ($children as $index => $child){ echo &quot;<BR>child[$index]=$child&quot;; } echo &quot;<BR>&quot;; sort($children); foreach ($children as $index => $child){ echo &quot;<BR>child[$index]=$child&quot;; } ?> -->
32. A process_form() Function <?php function process_form($data) { $msg = &quot;The form at {$_SERVER['PHP_SELF']} was submitted with these values: &quot;; foreach($data as $key=>$val) { $msg .= &quot;$key => $val&quot;; } mail(&quot;joeuser@somewhere.com&quot;, &quot;form submission&quot;, $msg); } ?>
33. Access widget's form value <INPUT TYPE=&quot;text&quot; NAME=&quot;myform.email&quot;> would be accessed in PHP as the following: <?php echo $_GET['myform_email'];  ?>
34. Accessing multiple submitted values <form method=&quot;POST&quot; action=&quot;index.php&quot;> <select name=&quot;lunch[]&quot; multiple> <option value=&quot;a&quot;>A</option> <option value=&quot;b&quot;>B</option> <option value=&quot;c&quot;>C</option> <option value=&quot;d&quot;>D</option> <option value=&quot;e&quot;>E</option> </select> <input type=&quot;submit&quot; name=&quot;submit&quot;> </form> Selected buns: <br/><?php foreach ($_POST['lunch'] as $choice) { print &quot;You want a $choice bun. <br/>&quot;; } ?>
35. Forms and PHP //index.htm <html> <body> <form action=&quot;index.php&quot; method=&quot;post&quot;> Your Name:<br> <input type=&quot;text&quot; name=&quot;name&quot; size=&quot;20&quot; maxlength=&quot;20&quot; value=&quot;&quot;><br> Your Email:<br> <input type=&quot;text&quot; name=&quot;email&quot; size=&quot;20&quot; maxlength=&quot;40&quot; value=&quot;&quot;><br> <input type=&quot;submit&quot; value=&quot;go!&quot;> </form> </body> </html>
//index.php <html> <head> <title></title> </head> <body> <? print &quot;Hi, $name!. Your email address is $email&quot;; ?> </body> </html>
36. Handling Special Characters <html> <body> <?php if ($_POST['submitted'] == &quot;yes&quot;){ $yourname = $_POST['yourname']; $yourname = trim ($yourname); $yourname = strip_tags ($yourname); $yourname = htmlspecialchars ($yourname); $yourname = addslashes ($yourname); echo $yourname . &quot;<br />&quot;; ?><a href=&quot;index.php&quot;>Try Again</a><?php }
if ($_POST['submitted'] != &quot;yes&quot;){ ?> <form action=&quot;index.php&quot; method=&quot;post&quot;> <p>Example:</p> <input type=&quot;hidden&quot; name=&quot;submitted&quot; value=&quot;yes&quot; /> Your Name: <input type=&quot;text&quot; name=&quot;yourname&quot; maxlength=&quot;150&quot; /><br /> <input type=&quot;submit&quot; value=&quot;Submit&quot; style=&quot;margin-top: 10px;&quot; /> </form> <?php } ?> </div> </body> </html>
37. Saying &quot;Hello&quot; <? if (array_key_exists('my_name',$_POST)) { print &quot;Hello, &quot;. $_POST['my_name']; } else { print<<<_HTML_ <form method=&quot;post&quot; action=&quot;$_SERVER[PHP_SELF]&quot;> Your name: <input type=&quot;text&quot; name=&quot;my_name&quot;> <br/> <input type=&quot;submit&quot; value=&quot;Say Hello&quot;> </form> _HTML_; } ?>
38. An HTML Form That Calls Itself <html> <head> <title>An HTML Form that Calls Itself</title> </head><body> <div> <?php if ( ! empty( $_POST['guess'] ) ) { print &quot;last guess: &quot;.$_POST['guess']; }?> <form method=&quot;post&quot; action=&quot;<?php print $_SERVER['PHP_SELF']?>&quot;> <p> Type your guess here: <input type=&quot;text&quot; name=&quot;guess&quot; /> </p></form></div> </body> </html>
39. Form submitting <?php if (isset($_POST['submit'])){ echo &quot;Hi &quot;.$_POST['name'].&quot;!<br />&quot;; echo &quot;The address &quot;.$_POST['email'].&quot; will soon be a spam-magnet!<br />&quot;;  } ?> <form action=&quot;index.php&quot; method=&quot;post&quot;> Name:<input type=&quot;text&quot; name=&quot;name&quot; size=&quot;20&quot; maxlength=&quot;40&quot; value=&quot;&quot; /> Email Address: <input type=&quot;text&quot; name=&quot;email&quot; size=&quot;20&quot; maxlength=&quot;40&quot; value=&quot;&quot; /> <input type=&quot;submit&quot; name = &quot;submit&quot; value=&quot;Go!&quot; /> </form>
40. One-script form processing //File: index.php <html> <head> <title></title> </head> <body> <? $form = &quot;<form action=amp;quot;index.phpamp;quot; method=amp;quot;postamp;quot;> <input type=amp;quot;hiddenamp;quot; name=amp;quot;seenformamp;quot; value=amp;quot;yamp;quot;> <b>Give us some information!</b><br> Your Name:<br> <input type=amp;quot;textamp;quot; name=amp;quot;nameamp;quot; size=amp;quot;20amp;quot; maxlength=amp;quot;20amp;quot; value=amp;quot;amp;quot;><br>
Your Email:<br> <input type=amp;quot;textamp;quot; name=amp;quot;emailamp;quot; size=amp;quot;20amp;quot; maxlength=amp;quot;40amp;quot; value=amp;quot;amp;quot;><br> <input type=amp;quot;submitamp;quot; value=amp;quot;subscribe!amp;quot;> </form>&quot;; if ($seenform != &quot;y&quot;): print &quot;$form&quot;; else : print &quot;Hi, $name!. Your email address is $email&quot;; endif; ?> </body> </html>
41. Preventing Multiple Submissions on the Client Side <html> <script language=&quot;javascript&quot; type=&quot;text/javascript&quot;>  function checkandsubmit() {  document.test.submitbut.disabled = true;  document.test.submit();  }  </script> <body> <form action=&quot;index.php&quot; method=&quot;post&quot; name=&quot;test&quot; onsubmit=&quot;return checkandsubmit ()&quot;> <input type=&quot;hidden&quot; name=&quot;submitted&quot; value=&quot;yes&quot; /> Your Name: <input type=&quot;text&quot; name=&quot;yourname&quot; maxlength=&quot;150&quot; />
<input type=&quot;submit&quot; value=&quot;Submit&quot; id=&quot;submitbut&quot; name&quot;submitbut&quot; /></form> </body> </html> <?php if ($file = fopen ( &quot;test.txt&quot;, &quot;w+&quot; )) { fwrite ( $file, &quot;Processing&quot; ); } else { echo &quot;Error opening file.&quot;; } echo $_POST ['yourname']; ?>
42. Preventing Multiple Submissions on the Server Side <html> <body> <form action=&quot;index.php&quot; method=&quot;post&quot;> <input type=&quot;hidden&quot; name=&quot;submitted&quot; value=&quot;yes&quot; /> Your Name: <input type=&quot;text&quot; name=&quot;yourname&quot; maxlength=&quot;150&quot; /><br /> <input type=&quot;submit&quot; value=&quot;Submit&quot; style=&quot;margin-top: 10px;&quot; /></form> </body> </html> <?php session_start (); if (! isset ( $_SESSION ['processing'] )) { $_SESSION ['processing'] = false;}
if ($_SESSION ['processing'] == false) { $_SESSION ['processing'] = true; //validation  if ($file = fopen ( &quot;test.txt&quot;, &quot;w+&quot; )) { fwrite ( $file, &quot;Processing&quot; ); } else { echo &quot;Error opening file.&quot;; } echo $_POST ['yourname']; unset ( $_SESSION ['processing'] ); } ?>
43. Authenticate user: Database based <?php function authenticate_user() { header('WWW-Authenticate: Basic realm=&quot;Secret Stash&quot;'); header(&quot;HTTP/1.0 401 Unauthorized&quot;); exit; } if (! isset($_SERVER['PHP_AUTH_USER'])) { authenticate_user(); } else { mysql_pconnect(&quot;localhost&quot;,&quot;authenticator&quot;,&quot;secret&quot;) or die(&quot;Can't connect to database server!&quot;); mysql_select_db(&quot;java2s&quot;) or die(&quot;Can't select authentication database!&quot;);
$query = &quot;SELECT username, pswd FROM user WHERE username='$_SERVER[PHP_AUTH_USER]' AND pswd=MD5('$_SERVER[PHP_AUTH_PW]')&quot;; $result = mysql_query($query); // If nothing was found, reprompt the user for the login information. if (mysql_num_rows($result) == 0) { authenticate_user(); } } ?>
44. Prompt Browser password dialog  <?php if (($_SERVER['PHP_AUTH_USER'] != 'specialuser') || ($_SERVER['PHP_AUTH_PW'] != 'secretpassword')) { header('WWW-Authenticate: Basic Realm=&quot;Secret Stash&quot;'); header('HTTP/1.0 401 Unauthorized'); print('You must provide the proper credentials!'); exit; } ?>
45. Open browser password dialog and authenticate user based on database <?php function authenticate_user() { header('WWW-Authenticate: Basic realm=&quot;Secret Stash&quot;'); header(&quot;HTTP/1.0 401 Unauthorized&quot;); exit; } if(! isset($_SERVER['PHP_AUTH_USER'])) { authenticate_user(); }
else { mysql_connect(&quot;localhost&quot;,&quot;authenticator&quot;,&quot;secret&quot;) or die(&quot;Can't connect to database server!&quot;); mysql_select_db(&quot;gilmorebook&quot;) or die(&quot;Can't select authentication database!&quot;); $query = &quot;SELECT username, pswd FROM user WHERE username='$_SERVER[PHP_AUTH_USER]'  AND pswd=MD5('$_SERVER[PHP_AUTH_PW]') AND ipAddress='$_SERVER[REMOTE_ADDR]'&quot;; $result = mysql_query($query); if (mysql_num_rows($result) == 0) authenticate_user(); mysql_close(); }?>
46. Login ID Options <HTML> <HEAD> <TITLE>Displaying Login ID Options</TITLE> </HEAD>  <BODY> <Hl><CENTER>Generating Login IDs for Dave</CENTER></Hl> <?php  $loginfo = array ( FirstName => &quot;Joe&quot;, LastName => &quot;Howrod&quot;, Sex => &quot;Male&quot;, Location => &quot;Arizona&quot;, Age => &quot;24&quot;, MusicChoice => &quot;Pop&quot;, Hobby => &quot;Dance&quot;, Occupation => &quot;Author&quot;); echo &quot;<H3>The information entered by JOe:<BR></H3>&quot;;  foreach ($loginfo as $key => $val) { echo &quot;<B>$key</B> => $val<BR>&quot;;  }
echo &quot;<BR> &quot;; echo &quot;<H3>The login options are:<BR></H3>&quot;; $loginone = array_slice ($loginfo, 0, 2); $logintwo = array_slice ($loginfo, 3, 2); $loginthree = array_slice ($loginfo, 5, 2); $loginfour = array_slice ($loginfo, 6, 2); $loginfive = array_merge ($loginfour, &quot;2001&quot;); echo &quot;The first login option:<BR>&quot;; foreach ($loginone as $optionone) { echo &quot;<B>$optionone</B>&quot;; }  echo &quot;<BR>&quot;; echo &quot;The second login option:<BR>&quot;; foreach ($loginone as $optiontwo) { echo &quot;<B>$optiontwo</B>&quot;; }  echo &quot;<BR>&quot;;
echo &quot;The third login option:<BR>&quot;; foreach ($loginthree as $optionthree) { echo &quot;<B>$optionthree</B>&quot;; }  echo &quot;<BR>&quot;; echo &quot;The fourth login option:<BR>&quot;; foreach ($loginfour as $optionfour) { echo &quot;<B>$optionfour</B>&quot;; }  echo &quot;<BR>&quot;; echo &quot;The fifth login option:<BR>&quot;; foreach ($loginfive as $optionfive) { echo &quot;<B>$optionfive</B>&quot;; } echo &quot;<BR>&quot;;  ?> </BODY> </HTML>
47. Get uniqid <? $id = uniqid(&quot;phpuser&quot;); echo &quot;$id&quot;; ?>
48. Use md5 function to encrypt text <?php $val = &quot;secret&quot;; echo &quot;Pre-hash string: $val <br />&quot;; $hash_val = md5 ($val); echo &quot;Hashed outcome: $hash_val&quot;; ?>
49. md5 and uniqid <? $id = md5(uniqid(rand())); echo &quot;$id&quot;; ?>
50. A user registration process create table user_info ( user_id char(18), fname char(15), email char(35)); //File: index.php <? $form = &quot; <form action=amp;quot;index.phpamp;quot; method=amp;quot;postamp;quot;> <input type=amp;quot;hiddenamp;quot; name=amp;quot;seenformamp;quot; value=amp;quot;yamp;quot;> Your first name?:<br> <input type=amp;quot;textamp;quot; name=amp;quot;fnameamp;quot; value=amp;quot;amp;quot;><br> Your email?:<br> <input type=amp;quot;textamp;quot; name=amp;quot;emailamp;quot; value=amp;quot;amp;quot;><br> <input type=amp;quot;submitamp;quot; value=amp;quot;Register!amp;quot;> </form> &quot;;
if ((! isset ($seenform)) && (! isset ($userid))) : print $form; elseif (isset ($seenform) && (! isset ($userid))) : $uniq_id = uniqid(rand()); @mysql_pconnect(&quot;localhost&quot;, &quot;root&quot;, &quot;&quot;) or die(&quot;Could not connect to MySQL server!&quot;); @mysql_select_db(&quot;user&quot;) or die(&quot;Could not select user database!&quot;); $query = &quot;INSERT INTO user_info VALUES('$uniq_id', '$fname', '$email')&quot;; $result = mysql_query($query) or die(&quot;Could not insert user information!&quot;); setcookie (&quot;userid&quot;, $uniq_id, time()+2592000); print &quot;Congratulations $fname! You are now registered!.&quot;;
elseif (isset($userid)) : @mysql_pconnect(&quot;localhost&quot;, &quot;root&quot;, &quot;&quot;) or die(&quot;Could not connect to MySQL server!&quot;); @mysql_select_db(&quot;user&quot;) or die(&quot;Could not select user database!&quot;); $query = &quot;SELECT * FROM user_info WHERE user_id = '$userid'&quot;; $result = mysql_query($query) or die(&quot;Could not extract user information!&quot;); $row = mysql_fetch_array($result); print &quot;Hi &quot;.$row[&quot;fname&quot;].&quot;,<br>&quot;; print &quot;Your email address is &quot;.$row[&quot;email&quot;]; endif; ?>
 

Mais conteúdo relacionado

Mais procurados (15)

Phpvsjsp
PhpvsjspPhpvsjsp
Phpvsjsp
 
Sphinx 1.1 i18n 機能紹介
Sphinx 1.1 i18n 機能紹介Sphinx 1.1 i18n 機能紹介
Sphinx 1.1 i18n 機能紹介
 
Css by tanbircox
Css by tanbircoxCss by tanbircox
Css by tanbircox
 
Phpwebdevelping
PhpwebdevelpingPhpwebdevelping
Phpwebdevelping
 
Web 2.0 Lessonplan Day1
Web 2.0 Lessonplan Day1Web 2.0 Lessonplan Day1
Web 2.0 Lessonplan Day1
 
Html by tanbircox
Html by tanbircoxHtml by tanbircox
Html by tanbircox
 
WordPress Development Confoo 2010
WordPress Development Confoo 2010WordPress Development Confoo 2010
WordPress Development Confoo 2010
 
The Loop
The LoopThe Loop
The Loop
 
Getting More Traffic From Search Advanced Seo For Developers Presentation
Getting More Traffic From Search  Advanced Seo For Developers PresentationGetting More Traffic From Search  Advanced Seo For Developers Presentation
Getting More Traffic From Search Advanced Seo For Developers Presentation
 
Web programming & design using internet by tanbircox
Web programming & design using internet by tanbircoxWeb programming & design using internet by tanbircox
Web programming & design using internet by tanbircox
 
Advanced SEO for Web Developers
Advanced SEO for Web DevelopersAdvanced SEO for Web Developers
Advanced SEO for Web Developers
 
Facebook Development with Zend Framework
Facebook Development with Zend FrameworkFacebook Development with Zend Framework
Facebook Development with Zend Framework
 
.htaccess for SEOs - A presentation by Roxana Stingu
.htaccess for SEOs - A presentation by Roxana Stingu.htaccess for SEOs - A presentation by Roxana Stingu
.htaccess for SEOs - A presentation by Roxana Stingu
 
Php tutorial
Php  tutorialPhp  tutorial
Php tutorial
 
Flash Templates- Joomla!Days NL 2009 #jd09nl
Flash Templates- Joomla!Days NL 2009 #jd09nlFlash Templates- Joomla!Days NL 2009 #jd09nl
Flash Templates- Joomla!Days NL 2009 #jd09nl
 

Destaque

PHP Training In Ambala! BATRA COMPUTER CENTRE
PHP Training In Ambala! BATRA COMPUTER CENTREPHP Training In Ambala! BATRA COMPUTER CENTRE
PHP Training In Ambala! BATRA COMPUTER CENTREjatin batra
 
Php vulnerability presentation
Php vulnerability presentationPhp vulnerability presentation
Php vulnerability presentationSqa Enthusiast
 
PHP Course in pune , PHP Training in Pimpri chinchwad ,PHP training in Pune
PHP Course in pune , PHP Training in Pimpri chinchwad ,PHP training in PunePHP Course in pune , PHP Training in Pimpri chinchwad ,PHP training in Pune
PHP Course in pune , PHP Training in Pimpri chinchwad ,PHP training in PuneCNC WEB WORLD
 
PHP Training in Chandigarh - Industrial Training
PHP Training in Chandigarh - Industrial TrainingPHP Training in Chandigarh - Industrial Training
PHP Training in Chandigarh - Industrial TrainingConjoinix Xscademy
 
PHP Training in Ambala ! BATRA COMPUTER CENTRE
PHP Training in Ambala ! BATRA COMPUTER CENTREPHP Training in Ambala ! BATRA COMPUTER CENTRE
PHP Training in Ambala ! BATRA COMPUTER CENTREjatin batra
 
PHP Training In Ambala Cantt! Batra Computer Centre
PHP Training In Ambala Cantt! Batra Computer Centre PHP Training In Ambala Cantt! Batra Computer Centre
PHP Training In Ambala Cantt! Batra Computer Centre groversimrans
 
PHP Hub in Ambala ! Batra Computer Centre
PHP Hub in Ambala ! Batra Computer CentrePHP Hub in Ambala ! Batra Computer Centre
PHP Hub in Ambala ! Batra Computer Centrejatin batra
 
6 Week / Month Industrial Training in Hoshiarpur Punjab- PHP Project Report
6 Week / Month Industrial Training in Hoshiarpur Punjab- PHP Project Report 6 Week / Month Industrial Training in Hoshiarpur Punjab- PHP Project Report
6 Week / Month Industrial Training in Hoshiarpur Punjab- PHP Project Report c-tac
 
PHP Summer Training Presentation
PHP Summer Training PresentationPHP Summer Training Presentation
PHP Summer Training PresentationNitesh Sharma
 
Beginners PHP Tutorial
Beginners PHP TutorialBeginners PHP Tutorial
Beginners PHP Tutorialalexjones89
 

Destaque (16)

PHP Training In Ambala! BATRA COMPUTER CENTRE
PHP Training In Ambala! BATRA COMPUTER CENTREPHP Training In Ambala! BATRA COMPUTER CENTRE
PHP Training In Ambala! BATRA COMPUTER CENTRE
 
Php live project training
Php live project trainingPhp live project training
Php live project training
 
Php vulnerability presentation
Php vulnerability presentationPhp vulnerability presentation
Php vulnerability presentation
 
PHP Course in pune , PHP Training in Pimpri chinchwad ,PHP training in Pune
PHP Course in pune , PHP Training in Pimpri chinchwad ,PHP training in PunePHP Course in pune , PHP Training in Pimpri chinchwad ,PHP training in Pune
PHP Course in pune , PHP Training in Pimpri chinchwad ,PHP training in Pune
 
Php training in ahmedabad
Php training in ahmedabadPhp training in ahmedabad
Php training in ahmedabad
 
PHP Training in Chandigarh - Industrial Training
PHP Training in Chandigarh - Industrial TrainingPHP Training in Chandigarh - Industrial Training
PHP Training in Chandigarh - Industrial Training
 
PHP Training in Ambala ! BATRA COMPUTER CENTRE
PHP Training in Ambala ! BATRA COMPUTER CENTREPHP Training in Ambala ! BATRA COMPUTER CENTRE
PHP Training in Ambala ! BATRA COMPUTER CENTRE
 
PHP Training In Ambala Cantt! Batra Computer Centre
PHP Training In Ambala Cantt! Batra Computer Centre PHP Training In Ambala Cantt! Batra Computer Centre
PHP Training In Ambala Cantt! Batra Computer Centre
 
PHP
PHPPHP
PHP
 
PHP Training in Hyderabad
PHP Training in Hyderabad PHP Training in Hyderabad
PHP Training in Hyderabad
 
php
phpphp
php
 
PHP Hub in Ambala ! Batra Computer Centre
PHP Hub in Ambala ! Batra Computer CentrePHP Hub in Ambala ! Batra Computer Centre
PHP Hub in Ambala ! Batra Computer Centre
 
6 Week / Month Industrial Training in Hoshiarpur Punjab- PHP Project Report
6 Week / Month Industrial Training in Hoshiarpur Punjab- PHP Project Report 6 Week / Month Industrial Training in Hoshiarpur Punjab- PHP Project Report
6 Week / Month Industrial Training in Hoshiarpur Punjab- PHP Project Report
 
Php Ppt
Php PptPhp Ppt
Php Ppt
 
PHP Summer Training Presentation
PHP Summer Training PresentationPHP Summer Training Presentation
PHP Summer Training Presentation
 
Beginners PHP Tutorial
Beginners PHP TutorialBeginners PHP Tutorial
Beginners PHP Tutorial
 

Semelhante a PHP

Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power pointjustmeanscsr
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power pointjustmeanscsr
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power pointjustmeanscsr
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power pointjustmeanscsr
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power pointjustmeanscsr
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power pointjustmeanscsr
 
Mantis Installation for Windows Box
Mantis Installation for Windows BoxMantis Installation for Windows Box
Mantis Installation for Windows Boxguest34a3a419
 
Mantis Installation for Windows Box
Mantis Installation for Windows BoxMantis Installation for Windows Box
Mantis Installation for Windows BoxJayanta Dash
 
PHP tutorials , php tutorials for beginners , tutorials for php
PHP tutorials , php tutorials for beginners , tutorials for phpPHP tutorials , php tutorials for beginners , tutorials for php
PHP tutorials , php tutorials for beginners , tutorials for phpaimaq9a
 
Article 01 What Is Php
Article 01   What Is PhpArticle 01   What Is Php
Article 01 What Is Phpdrperl
 
How and Why to extend Firefox
How and Why to extend FirefoxHow and Why to extend Firefox
How and Why to extend FirefoxGraham King
 
Php hypertext Preprocessor
Php hypertext PreprocessorPhp hypertext Preprocessor
Php hypertext PreprocessorMrsRLakshmiIT
 
Installation instruction of Testlink
Installation instruction of TestlinkInstallation instruction of Testlink
Installation instruction of Testlinkusha kannappan
 
PHP Hypertext Preprocessor
PHP Hypertext PreprocessorPHP Hypertext Preprocessor
PHP Hypertext Preprocessoradeel990
 
Setting up a debugging environment for Drupal
Setting up a debugging environment for DrupalSetting up a debugging environment for Drupal
Setting up a debugging environment for Drupaljonlee554
 

Semelhante a PHP (20)

Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
 
Justmeans power point
Justmeans power pointJustmeans power point
Justmeans power point
 
Php intro
Php introPhp intro
Php intro
 
Php
PhpPhp
Php
 
Mantis Installation for Windows Box
Mantis Installation for Windows BoxMantis Installation for Windows Box
Mantis Installation for Windows Box
 
Mantis Installation for Windows Box
Mantis Installation for Windows BoxMantis Installation for Windows Box
Mantis Installation for Windows Box
 
PHP tutorials , php tutorials for beginners , tutorials for php
PHP tutorials , php tutorials for beginners , tutorials for phpPHP tutorials , php tutorials for beginners , tutorials for php
PHP tutorials , php tutorials for beginners , tutorials for php
 
Article 01 What Is Php
Article 01   What Is PhpArticle 01   What Is Php
Article 01 What Is Php
 
How and Why to extend Firefox
How and Why to extend FirefoxHow and Why to extend Firefox
How and Why to extend Firefox
 
Php hypertext Preprocessor
Php hypertext PreprocessorPhp hypertext Preprocessor
Php hypertext Preprocessor
 
Installation instruction of Testlink
Installation instruction of TestlinkInstallation instruction of Testlink
Installation instruction of Testlink
 
PHP Hypertext Preprocessor
PHP Hypertext PreprocessorPHP Hypertext Preprocessor
PHP Hypertext Preprocessor
 
Php
PhpPhp
Php
 
Setting up a debugging environment for Drupal
Setting up a debugging environment for DrupalSetting up a debugging environment for Drupal
Setting up a debugging environment for Drupal
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
 
Php Presentation
Php PresentationPhp Presentation
Php Presentation
 

Mais de Gouthaman V

Professional Ethics Assignment II
Professional Ethics Assignment IIProfessional Ethics Assignment II
Professional Ethics Assignment IIGouthaman V
 
Scholastic averages sheet-2
Scholastic averages sheet-2Scholastic averages sheet-2
Scholastic averages sheet-2Gouthaman V
 
Eligibility criteria and instructions for Infosys Placement
Eligibility criteria and instructions for Infosys PlacementEligibility criteria and instructions for Infosys Placement
Eligibility criteria and instructions for Infosys PlacementGouthaman V
 
Answers for 2 Marks Unit Test I (RMW)
Answers for 2 Marks Unit Test I (RMW)Answers for 2 Marks Unit Test I (RMW)
Answers for 2 Marks Unit Test I (RMW)Gouthaman V
 
Anwers for 2 marks - RMW
Anwers for 2 marks - RMWAnwers for 2 marks - RMW
Anwers for 2 marks - RMWGouthaman V
 
Rmw unit test question papers
Rmw unit test question papersRmw unit test question papers
Rmw unit test question papersGouthaman V
 
Circular and semicircular cavity resonator
Circular and semicircular cavity resonatorCircular and semicircular cavity resonator
Circular and semicircular cavity resonatorGouthaman V
 
VLSI Anna University Practical Examination
VLSI Anna University Practical ExaminationVLSI Anna University Practical Examination
VLSI Anna University Practical ExaminationGouthaman V
 
VLSI Sequential Circuits II
VLSI Sequential Circuits IIVLSI Sequential Circuits II
VLSI Sequential Circuits IIGouthaman V
 
VI Semester Examination Time Table
VI Semester Examination Time TableVI Semester Examination Time Table
VI Semester Examination Time TableGouthaman V
 
Antenna and Wave Propagation Assignment I
Antenna and Wave Propagation Assignment IAntenna and Wave Propagation Assignment I
Antenna and Wave Propagation Assignment IGouthaman V
 
Antenna and Wave Propagation Assignment I
Antenna and Wave Propagation Assignment IAntenna and Wave Propagation Assignment I
Antenna and Wave Propagation Assignment IGouthaman V
 
Computer Networks Unit Test II Questions
Computer Networks Unit Test II QuestionsComputer Networks Unit Test II Questions
Computer Networks Unit Test II QuestionsGouthaman V
 
Sequential Circuits I VLSI 9th experiment
Sequential Circuits I VLSI 9th experimentSequential Circuits I VLSI 9th experiment
Sequential Circuits I VLSI 9th experimentGouthaman V
 
Antenna Unit Test II Questions
Antenna Unit Test II QuestionsAntenna Unit Test II Questions
Antenna Unit Test II QuestionsGouthaman V
 
Antenna Unit Test II questions
Antenna Unit Test II questionsAntenna Unit Test II questions
Antenna Unit Test II questionsGouthaman V
 
Combinational circuits II outputs
Combinational circuits II outputsCombinational circuits II outputs
Combinational circuits II outputsGouthaman V
 

Mais de Gouthaman V (20)

Professional Ethics Assignment II
Professional Ethics Assignment IIProfessional Ethics Assignment II
Professional Ethics Assignment II
 
Dip Unit Test-I
Dip Unit Test-IDip Unit Test-I
Dip Unit Test-I
 
Scholastic averages sheet-2
Scholastic averages sheet-2Scholastic averages sheet-2
Scholastic averages sheet-2
 
Eligibility criteria and instructions for Infosys Placement
Eligibility criteria and instructions for Infosys PlacementEligibility criteria and instructions for Infosys Placement
Eligibility criteria and instructions for Infosys Placement
 
Answers for 2 Marks Unit Test I (RMW)
Answers for 2 Marks Unit Test I (RMW)Answers for 2 Marks Unit Test I (RMW)
Answers for 2 Marks Unit Test I (RMW)
 
Anwers for 2 marks - RMW
Anwers for 2 marks - RMWAnwers for 2 marks - RMW
Anwers for 2 marks - RMW
 
Rmw unit test question papers
Rmw unit test question papersRmw unit test question papers
Rmw unit test question papers
 
Circular and semicircular cavity resonator
Circular and semicircular cavity resonatorCircular and semicircular cavity resonator
Circular and semicircular cavity resonator
 
VLSI Anna University Practical Examination
VLSI Anna University Practical ExaminationVLSI Anna University Practical Examination
VLSI Anna University Practical Examination
 
HCL IPT
HCL IPTHCL IPT
HCL IPT
 
VLSI Sequential Circuits II
VLSI Sequential Circuits IIVLSI Sequential Circuits II
VLSI Sequential Circuits II
 
VI Semester Examination Time Table
VI Semester Examination Time TableVI Semester Examination Time Table
VI Semester Examination Time Table
 
Email
EmailEmail
Email
 
Antenna and Wave Propagation Assignment I
Antenna and Wave Propagation Assignment IAntenna and Wave Propagation Assignment I
Antenna and Wave Propagation Assignment I
 
Antenna and Wave Propagation Assignment I
Antenna and Wave Propagation Assignment IAntenna and Wave Propagation Assignment I
Antenna and Wave Propagation Assignment I
 
Computer Networks Unit Test II Questions
Computer Networks Unit Test II QuestionsComputer Networks Unit Test II Questions
Computer Networks Unit Test II Questions
 
Sequential Circuits I VLSI 9th experiment
Sequential Circuits I VLSI 9th experimentSequential Circuits I VLSI 9th experiment
Sequential Circuits I VLSI 9th experiment
 
Antenna Unit Test II Questions
Antenna Unit Test II QuestionsAntenna Unit Test II Questions
Antenna Unit Test II Questions
 
Antenna Unit Test II questions
Antenna Unit Test II questionsAntenna Unit Test II questions
Antenna Unit Test II questions
 
Combinational circuits II outputs
Combinational circuits II outputsCombinational circuits II outputs
Combinational circuits II outputs
 

Último

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 

Último (20)

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 

PHP

  • 1. -By V.Gouthaman
  • 2. INTRODUCTION PHP: Hypertext Preprocessor is a widely used, general-purpose scripting language that was originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document. As a general-purpose programming language, PHP code is processed by an interpreter application in command-line mode performing desired operating system operations and producing program output on its standard output channel.
  • 3. It may also function as a graphical application. PHP is available as a processor for most modern web servers and as standalone interpreter on most operating systems and computing platforms. PHP was originally created by Rasmus Lerdorf in 1995 and has been in continuous development ever since. The main implementation of PHP is now produced by The PHP Group and serves as the de facto standard for PHP as there is no formal specification. PHP is free software released under the PHP License.
  • 5. Step 1: Download the latest Windows PHP Binaries (MSI file) from “http://www.php.net/get/php-5.2.4-win32-installer.msi/from/a/mirror” . I choose the eZNetworking mirror because it is the closest one to Malaysia. Choose a mirror that is nearer to your country for a faster file download. The latest PHP version that I downloaded is 5.2.4. Save the file to your Desktop. Step 2: Right click on the file and click “Install“.
  • 6. Step 3: Click “Next ” once the Welcome page is displayed.
  • 7. Step 4: Select “I accept the license agreement” and click “Next “.
  • 8. Step 5: Change your PHP installation path OR just accept the default path - C:rogram FilesHPand click “Next “.
  • 9. Step 6: On the Web Server Setup screen, select the Apache 2.2.x Module and click “Next “. select-webserver-to-install-php-on-apache-2
  • 10. Step 7: On the Apache Configuration Directory screen, browse for the Apache configuration directory (conf) OR just enter C:rogram Filespache Software Foundationpache2.2onfand click “Next ” to proceed with the installation.
  • 11. Step 8: For now, accept the default selection and click “Next”.
  • 12. Step 9: Click “Install ” to install PHP 5 on Windows.
  • 13. Step 10: Click “Finish ” once completed. PHP 5 is successfully installed.
  • 14. Step 11: Start your Apache 2.2 server using the “Monitor Apache Servers” console (Start -> Apache HTTP Servers 2.2.4 -> Monitor Apache Servers ). You can see that PHP was successfully installed by checking the Apache status at the bottom of the console.
  • 15. Testing PHP 5 Installation Step 1: Open up your Windows Notepad. Type in “<?php phpinfo(); ?>” inside the file. Save this file as “info.php” inside your Apache root directory, C:rogram Filespache Software Foundationpache2.2tdocs .
  • 16. Step 2: Open up your web browser. In the address bar, type in your web server domain name plus info.php as the file name. Example: http://www.syahid.com/info.php . You should get a PHP configuration page just like the one below. Congratulations! You have successfully installed and test PHP 5 on Windows!
  • 18. Configure PHP 5 to Work with MySQL with MySQL PHP Extension Previously, we have installed PHP with minimal modules / extension. To add MySQL support to PHP, you need to change your PHP installation - by adding the MySQL extension on top of your PHP installation. Please make sure that your original PHP 5 MSI installer still remains at its original place .
  • 19. Step 1: Open the Add / Remove Programs console via Windows Control Panel. Find the PHP 5.x.x entry and click “Change “.
  • 20. Step 2: Click “Next ” once you are prompted the Welcome page.
  • 21. Step 3: Click the “Change ” button to proceed.
  • 22. Step 4: Select Apache 2.2.x as shown in the picture below. Click “Next ” once again.
  • 23. Step 5: Select your Apache configuration directory (conf) - the directory where your httpd.conf resides. Click “Next ” once done.
  • 24.  
  • 25. Step 6: On the “Choose items to install” screen, click on the plus (+) icon next to Extensions to expand the list. click-plus-button-to-expand-extensions-part
  • 26.  
  • 27. Step 7: Select on the “X” next to “MySQL” and select “Entire feature will be installed on local hard drive”. Click “Next” again
  • 28. Step 8: Click the “Change” button to save all the PHP configuration changes.
  • 29. Step 9: Finally, restart your Apache 2.2 web server! You can check out that the MySQL extension support for PHP was successfully installed by checking out the info.php / index.php page that was created before.
  • 30. PHP SAMPLE PROGRAMS
  • 31. Sample 1: current date in an HTML page <html> <head> <title>Example #1 TDavid's Very First PHP Script ever!</title> </head> <? print(Date(&quot;l F d, Y&quot;)); ?> <body> </body> </html>
  • 32. 2.current month/day/date format <html> <head> <title>Example #3 TDavid's Very First PHP Script ever!</title> </head> <? print(Date(&quot;m/j/y&quot;)); ?> <body> </body> </html>
  • 33. 3. current month/day/date with HTML colors & formatting <html> <head> <title>PHP Script examples!</title> </head> <font face=&quot;Arial&quot; color=&quot;#FF00FF&quot;><strong><? print(Date(&quot;m/j/y&quot;)); ?> </strong></font> <body> </body> </html>
  • 34. 4. change background color based on day of the week using if else elseif statements <html> <head> <title>Background Colors change based on the day of the week</title> </head> <? $today = date(&quot;l&quot;); print(&quot;$today&quot;); if($today == &quot;Sunday&quot;) { $bgcolor = &quot;#FEF0C5&quot;; }
  • 35. elseif($today == &quot;Monday&quot;) { $bgcolor = &quot;#FFFFFF&quot;; } elseif($today == &quot;Tuesday&quot;) { $bgcolor = &quot;#FBFFC4&quot;; } elseif($today == &quot;Wednesday&quot;) { $bgcolor = &quot;#FFE0DD&quot;; } elseif($today == &quot;Thursday&quot;){ $bgcolor = &quot;#E6EDFF&quot;;}
  • 36. elseif($today == &quot;Friday&quot;) { $bgcolor = &quot;#E9FFE6&quot;; } else { // Since it is not any of the days above it must be Saturday $bgcolor = &quot;#F0F4F1&quot;; } print(&quot;<body bgcolor=amp;quot;$bgcoloramp;quot;>&quot;); ?> <br>This just changes the color of the screen based on the day of the week </body> </html>
  • 37. <html> <head> <title>Background Colors change based on the day of the week</title></head> <?$today = date(&quot;w&quot;); $bgcolor = array( &quot;#FEF0C5&quot;, &quot;#FFFFFF&quot;, &quot;#FBFFC4&quot;, &quot;#FFE0DD&quot;, &quot;#E6EDFF&quot;, &quot;#E9FFE6&quot;, &quot;#F0F4F1&quot; ); ?> <body bgcolor=&quot;<?print(&quot;$bgcolor[$today]&quot;);?>&quot;> <br>This just changes the color of the screen based on the day of the week </body> </html>
  • 38. 5. Add date time stamp &quot;page last updated on..&quot; using filemtime function using forms, cookies, flat file databases, random number generation <html> <head> <title>Page last updated on month/date/year hour:min PHP Script</title> </head> <? $last_modified = filemtime(&quot;example7.php3&quot;); print(&quot;Last Modified &quot;); print(date(&quot;m/j/y h:i&quot;, $last_modified)); ?> </body> </html>
  • 39. 6. Setting and retrieving a cookie <? $check = &quot;test&quot;; $check .= $filename; if ($test == $check) {print(&quot;<HTML><BODY>You have already voted. Thank you.</BODY></HTML>&quot;); } else{ $rated = &quot;test&quot;; $rated .= $filename; setcookie(test, $rated, time()+86400); print(&quot;<HTML><BODY><br>You haven't voted before so I recorded your vote</BODY></HTML>&quot;); } ?>
  • 40. 7. Getting an average number using PHP <? $total_ratings = (3+2+3+1+5+2+3); $total_votes = 7; $average = $total_ratings / $total_votes; print(&quot;The Average Rating Is: $average&quot;); ?>
  • 41. 8. showing the surfer average vote statistics, using printf function <? $path = &quot;/YOUR/PATH/TO/public_html/php_diary/data&quot;; $filename = &quot;122499.dat&quot;; $x= -1; if($file = fopen(&quot;$path/$filename&quot;, &quot;r&quot;)) { while(!feof($file)) { $therate = fgetss($file, 255); $x++; $count = $count + $therate; } fclose($file); } $average = ($count / $x); print(&quot;Surfer Average Rating for 12/24/99: &quot;); printf(&quot;%.2f&quot;, $average); print(&quot;<br>Total Surfer Votes: $x&quot;); ?>
  • 42. 9. Generating a random number from 0 to 9 <? srand(time()); $random = (rand()%9); print(&quot;Random number between 0 and 9 is: $random&quot;); ?>
  • 43. 10. php simple slot machine - multiple random number generation <? function slotnumber() { srand(time()); for ($i=0; $i < 3; $i++) { $random = (rand()%3); $slot[] = $random; } print(&quot;<td width=amp;quot;33%amp;quot;><center>$slot[0]</td>&quot;); print(&quot;<td width=amp;quot;33%amp;quot;><center>$slot[1]</td>&quot;); print(&quot;<td width=amp;quot;33%amp;quot;><center>$slot[2]</td>&quot;); </tr>
  • 44. 11. php simple slot machine - multiple random number generation <tr> <td width=&quot;100%&quot; colspan=&quot;3&quot; bgcolor=&quot;#008080&quot;><form method=&quot;POST&quot; action=&quot;example13.php3&quot;><div align=&quot;center&quot;><center><p><input type=&quot;submit&quot; value=&quot;Spin!&quot;></p> </center></div> </form> </td> </tr> </table> </center></div>
  • 45. 12. random text link advertising using predefined arrays mail, regular expressions, password protection <? $random_url = array(&quot;http://www.tdscripts.com/linkorg.html&quot;, &quot;http://www.tdscripts.com/keno.html&quot;, &quot;http://www.tdscripts.com/ezibill.shtml&quot;, &quot;http://www.tdscripts.com/tdforum.shtml&quot;, &quot;http://www.tdscripts.com/picofday.html&quot;, &quot;http://www.tdscripts.com/gutsorglory.html&quot;);
  • 46. $url_title = array(&quot;Link Organizer&quot;, &quot;TD Keno&quot;, &quot;eziBill *Free Promotion!&quot;, &quot;TD Forum&quot;, &quot;TD Pic of Day PHP&quot;, &quot;Guts or Glory Poker PHP&quot;); $url_desc = array(&quot;- A comprehensive link list organizer&quot;, &quot;- Offer your site visitors an engaging Keno game without the monetary risk&quot;, &quot;- Sell access to and protect your membership area using iBill and our eziBill script&quot;, &quot;- An unthreaded messageboard script to exchange ideas with your site visitors&quot;, &quot;- Run your own picture of the day script from any site anywhere with this handy script&quot;, &quot;- A casino-style card game written entirely in PHP&quot;);
  • 47. srand(time()); $sizeof = count($random_url); $random = (rand()%$sizeof); print(&quot;<center><a href=amp;quot;$random_url[$random]amp;quot;>$url_title[$random]</a> $url_desc[$random]</center>&quot;); ?>
  • 48. 13. forcing the text in a string to be all upper or lowercase <? // force all uppercase print(strtoupper(&quot;i bet this will show up as all letters capitalized<br>&quot;)); // force all lowercase print(strtolower(&quot;I BET THIS WILL SHOW UP AS ALL LETTERS IN LOWERCASE<br>&quot;)); // force the first letter of a string to be capitalized print(ucfirst(&quot;i bet this will show the first letter of the string capitalized<br>&quot;)); // force the first letter of each WORD in a string to be capitalized print(ucwords(&quot;i bet this will show the first letter of every word capitalized<br>&quot;)); ?>
  • 49. 14. searching through meta tags for a search engine <HTML> <BODY> <? $all_meta = get_meta_tags(&quot;010600.php3&quot;); print($all_meta[&quot;description&quot;]); print(&quot;<br>&quot;); print($all_meta[&quot;keywords&quot;]); ?> </BODY> </HTML>
  • 50. 15. searching through a directory and picking out files using a regular expression <? $diary_directory = opendir(&quot;.&quot;); while($filename = readdir($diary_directory)) { $filesplit = explode(&quot;.&quot;, $filename); $check_filename = $filesplit[0]; if(ereg(&quot;[0-9]{6}&quot;, $check_filename)) { $check_filename .= &quot;.$filesplit[1]&quot;; $valid_filename[] = $check_filename; } } closedir($diary_directory); for($index = 0; $index < count($valid_filename); $index++) { print(&quot;$valid_filename[$index]<br>&quot;); } ?>
  • 51. 16. shuffling and &quot;cutting&quot; a deck of playing cards <? $cards = array(&quot;ah&quot;, &quot;ac&quot;, &quot;ad&quot;, &quot;as&quot;, &quot;2h&quot;, &quot;2c&quot;, &quot;2d&quot;, &quot;2s&quot;, &quot;3h&quot;, &quot;3c&quot;, &quot;3d&quot;, &quot;3s&quot;, &quot;4h&quot;, &quot;4c&quot;, &quot;4d&quot;, &quot;4s&quot;, &quot;5h&quot;, &quot;5c&quot;, &quot;5d&quot;, &quot;5s&quot;, &quot;6h&quot;, &quot;6c&quot;, &quot;6d&quot;, &quot;6s&quot;, &quot;7h&quot;, &quot;7c&quot;, &quot;7d&quot;, &quot;7s&quot;, &quot;8h&quot;, &quot;8c&quot;, &quot;8d&quot;, &quot;8s&quot;, &quot;9h&quot;, &quot;9c&quot;, &quot;9d&quot;, &quot;9s&quot;, &quot;th&quot;, &quot;tc&quot;, &quot;td&quot;, &quot;ts&quot;, &quot;jh&quot;, &quot;jc&quot;, &quot;jd&quot;, &quot;js&quot;, &quot;qh&quot;, &quot;qc&quot;, &quot;qd&quot;, &quot;qs&quot;, &quot;kh&quot;, &quot;kc&quot;, &quot;kd&quot;, &quot;ks&quot;);
  • 52. srand(time()); for($i = 0; $i < 52; $i++) { $count = count($cards); $random = (rand()%$count); if($cards[$random] == &quot;&quot;) { $i--; } else { $deck[] = $cards[$random]; $cards[$random] = &quot;&quot;; } }
  • 53. srand(time()); $starting_point = (rand()%51); print(&quot;Starting point for cut cards is: $starting_point<p>&quot;); // display shuffled cards (EXAMPLE ONLY) for ($index = 0; $index < 52; $index++) { if ($starting_point == 52) { $starting_point = 0; } print(&quot;Uncut Point: <strong>$deck[$index]</strong> &quot;); print(&quot;Starting Point: <strong>$deck[$starting_point]</strong><br>&quot;); $starting_point++; } ?>
  • 54. 17. Reader rated most useful diary entries in descending order <HTML> <HEAD> <title>Reader Rated Most Useful Entries</title> </HEAD> <BODY> <table border=&quot;0&quot; width=&quot;100%&quot;> <tr> <td width=&quot;6%&quot; bgcolor=&quot;#00FFFF&quot;><p align=&quot;center&quot;><small><font face=&quot;Verdana&quot;>Rank</font></small></td> <td width=&quot;7%&quot; bgcolor=&quot;#00FFFF&quot;><p align=&quot;center&quot;><small><font face=&quot;Verdana&quot;>Rating</font></small></td>
  • 55. <td width=&quot;11%&quot; bgcolor=&quot;#00FFFF&quot;><p align=&quot;center&quot;><small><font face=&quot;Verdana&quot;>Diary Date</font></small></td> <td width=&quot;76%&quot; bgcolor=&quot;#00FFFF&quot;><p align=&quot;left&quot;><small><font face=&quot;Verdana&quot;>Description of Diary Page</font></small> </td> <script language=&quot;php&quot;> $db = &quot;DATABASE NAME&quot;; $admin = &quot;MYSQL USER NAME&quot;; $adpass = &quot;MYSQL PASSWORD&quot;; $mysql_link = mysql_connect(&quot;localhost&quot;, $admin, $adpass); mysql_select_db($db, $mysql_link);
  • 56. $query = &quot;SELECT * FROM avg_tally ORDER BY average DESC&quot;; $result = mysql_query($query, $mysql_link); if(mysql_num_rows($result)) { $rank = 1; while($row = mysql_fetch_row($result)) { print(&quot;</tr><tr>&quot;); if($color == &quot;#D8DBFE&quot;) { $color = &quot;#A6ACFD&quot;; } else { $color = &quot;#D8DBFE&quot;; } print(&quot;<td width=amp;quot;6%amp;quot; bgcolor=amp;quot;$coloramp;quot;><center><small>&quot;); print(&quot;<font face=amp;quot;Verdanaamp;quot;>$rank</font></small></center></td>&quot;); print(&quot;<td width=amp;quot;7%amp;quot; bgcolor=amp;quot;$coloramp;quot;><center><small>&quot;); print(&quot;<font face=amp;quot;Verdanaamp;quot;><strong>$row[1]</strong></font></small></center></td>&quot;); print(&quot;<td width=amp;quot;11%amp;quot; bgcolor=amp;quot;$coloramp;quot;><center><small>&quot;); $url = $row[2] . &quot;.php3&quot;;
  • 57. if(!file_exists($url)) { $url = $row[2] . &quot;.html&quot;; } print(&quot;<font face=amp;quot;Verdanaamp;quot;><a href=amp;quot;$urlamp;quot;>$row[2]</a></font></small></center></td>&quot;); print(&quot;<td width=amp;quot;76%amp;quot; bgcolor=amp;quot;$coloramp;quot;><left><small>&quot;); print(&quot;<font face=amp;quot;Verdanaamp;quot;>$row[3]</font></small></left></td>&quot;); $rank++; } } </script> </table> </BODY> </HTML>
  • 58. 18. creating a mySQL table using a PHP script <? $mysql_db = &quot;DATABASE NAME&quot;; $mysql_user = &quot;YOUR MYSQL USERNAME&quot;; $mysql_pass = &quot;YOUR MYSQL PASSWORD&quot;; $mysql_link = mysql_connect(&quot;localhost&quot;, $mysql_user, $mysql_pass); mysql_select_db($mysql_db, $mysql_link); $create_query = &quot;CREATE TABLE tds_counter ( COUNT_ID INT NOT NULL AUTO_INCREMENT, pagepath VARCHAR(250), impressions INT, reset_counter DATETIME, PRIMARY KEY (COUNT_ID) )&quot;;
  • 59. 19. creating a mySQL table using a PHP script mysql_query($create_query, $mysql_link); print(&quot;Table Creation for <b>tds_counter</b> successful!<p>&quot;); $insert = &quot;INSERT into tds_counter VALUES ( 0, '/php_diary/021901.php3', 0, SYSDATE() )&quot;; mysql_query($insert, $mysql_link); print(&quot;Inserted new counter successfully for this page: http://www.php-scripts.com/php_diary/021901.php3<p>&quot;); ?>
  • 60. 20. mySQL based counter script for multiple pagesAutomating manual tasks, date sorting, mktime() <? $db = &quot;DATABASE NAME&quot;; $admin = &quot;MYSQL USER NAME&quot;; $adpass = &quot;MYSQL PASSWORD&quot;; $mysql_link = mysql_connect(&quot;localhost&quot;, $admin, $adpass); mysql_select_db($db, $mysql_link); $result = mysql_query(&quot;SELECT impressions from tds_counter where COUNT_ID='$cid'&quot;, $mysql_link); if(mysql_num_rows($result)) { mysql_query(&quot;UPDATE tds_counter set impressions=impressions+1 where COUNT_ID='$cid'&quot;, $mysql_link); $row = mysql_fetch_row($result); if($inv != 1) { print(&quot;$row[0]&quot;); } }?>
  • 61. 21. Classify Email as Bounce (DSN) or Automated Reply <?php $bounce = new COM(&quot;Chilkat.Bounce&quot;); $success = $bounce->UnlockComponent('Anything for 30-day trial'); if ($success == false) { print 'Failed to unlock component' . &quot;&quot;; exit; } $email = new COM(&quot;Chilkat.Email&quot;);
  • 62. // Load an email from a .eml file. // (This example loads an Email object from a .eml file, // but the object could have been read // directly from a POP3 or IMAP mail server using // Chilkat's POP3 or IMAP implementations.) $success = $email->LoadEml('sampleBounce.eml'); if ($success == false) { print $email->lastErrorText() . &quot;&quot;; exit; }
  • 63. $success = $bounce->ExamineMail($email); if ($success == false) { print $bounce->lastErrorText() . &quot;&quot;; exit; } if ($bounce->BounceType == 1) { // Hard bounce, log the email address print 'Hard Bounce: ' . $bounce->bounceAddress() . &quot;&quot;; } if ($bounce->BounceType == 2) { // Soft bounce, log the email address print 'Soft Bounce: ' . $bounce->bounceAddress() . &quot;&quot;; }
  • 64. if ($bounce->BounceType == 3) { // General bounce, no email address available. print 'General Bounce: No email address' . &quot;&quot;; } if ($bounce->BounceType == 4) { // General bounce, log the email address print 'General Bounce: ' . $bounce->bounceAddress() . &quot;&quot;; } if ($bounce->BounceType == 5) { // Mail blocked, log the email address print 'Mail Blocked: ' . $bounce->bounceAddress() . &quot;&quot;; }
  • 65. if ($bounce->BounceType == 6) { // Auto-reply, log the email address print 'Auto-Reply: ' . $bounce->bounceAddress() . &quot;&quot;; } if ($bounce->BounceType == 7) { // Transient (recoverable) Failure, log the email address print 'Transient Failure: ' . $bounce->bounceAddress() . &quot;&quot;; } if ($bounce->BounceType == 8) { // Subscribe request, log the email address print 'Subscribe Request: ' . $bounce->bounceAddress() . &quot;&quot;; } if ($bounce->BounceType == 9) { // Unsubscribe Request, log the email address print 'Unsubscribe Request: ' . $bounce->bounceAddress() . &quot;&quot;; }
  • 66. if ($bounce->BounceType == 10) { // Virus Notification, log the email address print 'Virus Notification: ' . $bounce->bounceAddress() . &quot;&quot;; } if ($bounce->BounceType == 11) { // Suspected bounce. // This should be rare. It indicates that the Bounce // component found strong evidence that this is a bounced // email, but couldn//t quite recognize everything it // needed to be 100% sure. Feel free to notify // support@chilkatsoft.com regarding emails having this // bounce type. print 'Suspected Bounce!' . &quot;&quot;;} ?>
  • 67. 22. Program to print a message <html> <h3>My first PHP Program</h3> <? echo &quot;Hello world!&quot;; ?> </html>
  • 68. 23. PHP Array <?php $employee_names[0] = &quot;Dana&quot;; $employee_names[1] = &quot;Matt&quot;; $employee_names[2] = &quot;Susan&quot;; echo &quot;The first employee's name is &quot;.$employee_names[0]; echo &quot;<br>&quot;; echo &quot;The second employee's name is &quot;.$employee_names[1]; echo &quot;<br>&quot;; echo &quot;The third employee's name is &quot;.$employee_names[2]; ?>
  • 69. 24.File Upload Script <html> <head> <title>A File Upload Script</title> </head> <body> <div> <?php if ( isset( $_FILES['fupload'] ) ) { print &quot;name: &quot;. $_FILES['fupload']['name'] .&quot;<br />&quot;; print &quot;size: &quot;. $_FILES['fupload']['size'] .&quot; bytes<br />&quot;; print &quot;temp name: &quot;.$_FILES['fupload']['tmp_name'] .&quot;<br />&quot;; print &quot;type: &quot;. $_FILES['fupload']['type'] .&quot;<br />&quot;; print &quot;error: &quot;. $_FILES['fupload']['error'] .&quot;<br />&quot;; if ( $_FILES['fupload']['type'] == &quot;image/gif&quot; ) { $source = $_FILES['fupload']['tmp_name']; $target = &quot;upload/&quot;.$_FILES['fupload']['name'];
  • 70. move_uploaded_file( $source, $target );// or die (&quot;Couldn't copy&quot;); $size = getImageSize( $target ); $imgstr = &quot;<p><img width=amp;quot;$size[0]amp;quot; height=amp;quot;$size[1]amp;quot; &quot;; $imgstr .= &quot;src=amp;quot;$targetamp;quot; alt=amp;quot;uploaded imageamp;quot; /></p>&quot;; print $imgstr; } } ?> </div> <form enctype=&quot;multipart/form-data&quot; action=&quot;<?php print $_SERVER['PHP_SELF']?>&quot; method=&quot;post&quot;> <p> <input type=&quot;hidden&quot; name=&quot;MAX_FILE_SIZE&quot; value=&quot;102400&quot; /> <input type=&quot;file&quot; name=&quot;fupload&quot; /><br/> <input type=&quot;submit&quot; value=&quot;upload!&quot; /> </p> </form> </body> </html>
  • 71. 25.Simple File Upload Form <html> <head> <title>A Simple File Upload Form</title> </head> <body> <form enctype=&quot;multipart/form-data&quot; action=&quot;<?print $_SERVER['PHP_SELF']?>&quot; method=&quot;post&quot;> <p> <input type=&quot;hidden&quot; name=&quot;MAX_FILE_SIZE&quot; value=&quot;102400&quot; /> <input type=&quot;file&quot; name=&quot;fupload&quot; /><br/> <input type=&quot;submit&quot; value=&quot;upload!&quot; /> </p> </form> </body> </html>
  • 72. 26.Creating an HTML Form That Accepts Mail-Related Information <html> <head> <title>Simple Send Mail Form</title> </head><body> <h1>Mail Form</h1> <form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;SimpleEmail.php&quot;> <table> <tr><td><b>To</b></td><td><input type=&quot;text&quot; name=&quot;mailto&quot; size=&quot;35&quot;></td></tr> <tr><td><b>Subject</b></td> <td><input type=&quot;text&quot; name=&quot;mailsubject&quot; size=&quot;35&quot;></td></tr> <tr><td><b>Message</b></td> <td><textarea name=&quot;mailbody&quot; cols=&quot;50&quot; rows=&quot;7&quot;></textarea></td> </tr> <tr><td colspan=&quot;2&quot;> <input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Send&quot;> </td></tr></table></form></body> </html>
  • 73. <!-- SimpleEmail.php <?php if (empty ($mailto) ) { die ( &quot;Recipient is blank! &quot;) ; } if (empty ($mailsubject) ){ $mailsubject=&quot; &quot; ; } if (empty ($mailbody) ) { $mailbody=&quot; &quot; ; } $result = mail ($mailto, $mailsubject, $mailbody) ; if ($result) { echo &quot;Email sent successfully!&quot; ; }else{ echo &quot;Email could not be sent.&quot; ; } ?>
  • 74. 27.React to Form action <HTML> <BODY> <FORM METHOD=&quot;POST&quot; ACTION=&quot;GetFormValue.php&quot;> <H2>Contact List</H2> <BR>Nickname: <BR><INPUT TYPE=&quot;TEXT&quot; NAME=&quot;Nickname&quot;> <BR> <BR>Full Name: <BR><INPUT TYPE=&quot;TEXT&quot; NAME=&quot;Fullname&quot;>
  • 75. <BR> <BR>Memo: <BR><TEXTAREA NAME=&quot;Memo&quot; ROWS=&quot;4&quot; COLS=&quot;40&quot; WRAP=&quot;PHYSICAL&quot;> </TEXTAREA> <BR> <BR> <INPUT TYPE=&quot;SUBMIT&quot;> </FORM> </BODY> <!-- GetFormValue.php <?php echo &quot;<BR>Nickname=$Nickname&quot;; echo &quot;<BR>Fullname=$Fullname&quot;; echo &quot;<BR>Memo=$Memo&quot;; ?>
  • 76. 28. Build query string based on form input <?php if (isset($_POST['submit'])) { $rowID = $_POST['id']; mysql_connect(&quot;mysql153.secureserver.net&quot;,&quot;java2s&quot;,&quot;password&quot;); mysql_select_db(&quot;java2s&quot;); $query = &quot;SELECT * FROM Employee WHERE ID='$id'&quot;; $result = mysql_query($query); list($name,$productid,$price,$description) = mysql_fetch_row($result); }
  • 77. ?> <form action=&quot;<?php echo $_SERVER['PHP_SELF']; ?>&quot; method=&quot;post&quot;> <select name=&quot;id&quot;> <option name=&quot;&quot;>Choose a employee:</option> <option name=&quot;1&quot;>1</option> <option name=&quot;2&quot;>2</option> <option name=&quot;3&quot;>3</option> </select> <input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Submit&quot; /> </form>
  • 78. 29. Checking input from a checkbox or a multiple select <?php $options = array('option 1', 'option 2', 'option 3'); $valid = true; if (is_array($_GET['input'])) { $valid = true; foreach($_GET['input'] as $input) { if (!in_array($input, $options)) { $valid = false; } } if ($valid) { //process input } } ?>
  • 79. 30. Validating a single checkbox <?php $value = 'yes'; echo &quot;<input type='checkbox' name='subscribe' value='yes'/> Subscribe?&quot;; if (isset($_POST['subscribe'])) { if ($_POST['subscribe'] == $value) { $subscribed = true; } else { $subscribed = false;
  • 80. print 'Invalid checkbox value submitted.'; } } else { $subscribed = false; } if ($subscribed) { print 'You are subscribed.'; } else { print 'You are not subscribed'; }
  • 81. 31. Deal with Array Form Data <HTML> <BODY> <FORM METHOD=&quot;POST&quot; ACTION=&quot;DealWithArrayFormData.php&quot;> <H1>Contact Information</H1> <TABLE><TR> <TD>Childrens' Names:</TD> </TR> <TR> <TD><INPUT TYPE=&quot;TEXT&quot; NAME=&quot;children[]&quot;></TD> </TR> <TR> <TD><INPUT TYPE=&quot;TEXT&quot; NAME=&quot;children[]&quot;></TD> </TR> <TR> <TD><INPUT TYPE=&quot;TEXT&quot; NAME=&quot;children[]&quot;></TD> </TR>
  • 82. <TR> <TD><INPUT TYPE=&quot;TEXT&quot; NAME=&quot;children[]&quot;></TD> </TR> <TR> <TD><INPUT TYPE=&quot;TEXT&quot; NAME=&quot;children[]&quot;></TD> </TR> </TABLE> <BR> <BR> <BR> <INPUT TYPE=&quot;SUBMIT&quot; VALUE=&quot;Submit&quot;> <BR> <BR> <INPUT TYPE=&quot;RESET&quot; VALUE=&quot;Clear the Form&quot;> </FORM> </BODY> </HTML>
  • 83. <!-- DealWithArrayFormData.php <?php foreach ($children as $index => $child){ echo &quot;<BR>child[$index]=$child&quot;; } echo &quot;<BR>&quot;; sort($children); foreach ($children as $index => $child){ echo &quot;<BR>child[$index]=$child&quot;; } ?> -->
  • 84. 32. A process_form() Function <?php function process_form($data) { $msg = &quot;The form at {$_SERVER['PHP_SELF']} was submitted with these values: &quot;; foreach($data as $key=>$val) { $msg .= &quot;$key => $val&quot;; } mail(&quot;joeuser@somewhere.com&quot;, &quot;form submission&quot;, $msg); } ?>
  • 85. 33. Access widget's form value <INPUT TYPE=&quot;text&quot; NAME=&quot;myform.email&quot;> would be accessed in PHP as the following: <?php echo $_GET['myform_email']; ?>
  • 86. 34. Accessing multiple submitted values <form method=&quot;POST&quot; action=&quot;index.php&quot;> <select name=&quot;lunch[]&quot; multiple> <option value=&quot;a&quot;>A</option> <option value=&quot;b&quot;>B</option> <option value=&quot;c&quot;>C</option> <option value=&quot;d&quot;>D</option> <option value=&quot;e&quot;>E</option> </select> <input type=&quot;submit&quot; name=&quot;submit&quot;> </form> Selected buns: <br/><?php foreach ($_POST['lunch'] as $choice) { print &quot;You want a $choice bun. <br/>&quot;; } ?>
  • 87. 35. Forms and PHP //index.htm <html> <body> <form action=&quot;index.php&quot; method=&quot;post&quot;> Your Name:<br> <input type=&quot;text&quot; name=&quot;name&quot; size=&quot;20&quot; maxlength=&quot;20&quot; value=&quot;&quot;><br> Your Email:<br> <input type=&quot;text&quot; name=&quot;email&quot; size=&quot;20&quot; maxlength=&quot;40&quot; value=&quot;&quot;><br> <input type=&quot;submit&quot; value=&quot;go!&quot;> </form> </body> </html>
  • 88. //index.php <html> <head> <title></title> </head> <body> <? print &quot;Hi, $name!. Your email address is $email&quot;; ?> </body> </html>
  • 89. 36. Handling Special Characters <html> <body> <?php if ($_POST['submitted'] == &quot;yes&quot;){ $yourname = $_POST['yourname']; $yourname = trim ($yourname); $yourname = strip_tags ($yourname); $yourname = htmlspecialchars ($yourname); $yourname = addslashes ($yourname); echo $yourname . &quot;<br />&quot;; ?><a href=&quot;index.php&quot;>Try Again</a><?php }
  • 90. if ($_POST['submitted'] != &quot;yes&quot;){ ?> <form action=&quot;index.php&quot; method=&quot;post&quot;> <p>Example:</p> <input type=&quot;hidden&quot; name=&quot;submitted&quot; value=&quot;yes&quot; /> Your Name: <input type=&quot;text&quot; name=&quot;yourname&quot; maxlength=&quot;150&quot; /><br /> <input type=&quot;submit&quot; value=&quot;Submit&quot; style=&quot;margin-top: 10px;&quot; /> </form> <?php } ?> </div> </body> </html>
  • 91. 37. Saying &quot;Hello&quot; <? if (array_key_exists('my_name',$_POST)) { print &quot;Hello, &quot;. $_POST['my_name']; } else { print<<<_HTML_ <form method=&quot;post&quot; action=&quot;$_SERVER[PHP_SELF]&quot;> Your name: <input type=&quot;text&quot; name=&quot;my_name&quot;> <br/> <input type=&quot;submit&quot; value=&quot;Say Hello&quot;> </form> _HTML_; } ?>
  • 92. 38. An HTML Form That Calls Itself <html> <head> <title>An HTML Form that Calls Itself</title> </head><body> <div> <?php if ( ! empty( $_POST['guess'] ) ) { print &quot;last guess: &quot;.$_POST['guess']; }?> <form method=&quot;post&quot; action=&quot;<?php print $_SERVER['PHP_SELF']?>&quot;> <p> Type your guess here: <input type=&quot;text&quot; name=&quot;guess&quot; /> </p></form></div> </body> </html>
  • 93. 39. Form submitting <?php if (isset($_POST['submit'])){ echo &quot;Hi &quot;.$_POST['name'].&quot;!<br />&quot;; echo &quot;The address &quot;.$_POST['email'].&quot; will soon be a spam-magnet!<br />&quot;; } ?> <form action=&quot;index.php&quot; method=&quot;post&quot;> Name:<input type=&quot;text&quot; name=&quot;name&quot; size=&quot;20&quot; maxlength=&quot;40&quot; value=&quot;&quot; /> Email Address: <input type=&quot;text&quot; name=&quot;email&quot; size=&quot;20&quot; maxlength=&quot;40&quot; value=&quot;&quot; /> <input type=&quot;submit&quot; name = &quot;submit&quot; value=&quot;Go!&quot; /> </form>
  • 94. 40. One-script form processing //File: index.php <html> <head> <title></title> </head> <body> <? $form = &quot;<form action=amp;quot;index.phpamp;quot; method=amp;quot;postamp;quot;> <input type=amp;quot;hiddenamp;quot; name=amp;quot;seenformamp;quot; value=amp;quot;yamp;quot;> <b>Give us some information!</b><br> Your Name:<br> <input type=amp;quot;textamp;quot; name=amp;quot;nameamp;quot; size=amp;quot;20amp;quot; maxlength=amp;quot;20amp;quot; value=amp;quot;amp;quot;><br>
  • 95. Your Email:<br> <input type=amp;quot;textamp;quot; name=amp;quot;emailamp;quot; size=amp;quot;20amp;quot; maxlength=amp;quot;40amp;quot; value=amp;quot;amp;quot;><br> <input type=amp;quot;submitamp;quot; value=amp;quot;subscribe!amp;quot;> </form>&quot;; if ($seenform != &quot;y&quot;): print &quot;$form&quot;; else : print &quot;Hi, $name!. Your email address is $email&quot;; endif; ?> </body> </html>
  • 96. 41. Preventing Multiple Submissions on the Client Side <html> <script language=&quot;javascript&quot; type=&quot;text/javascript&quot;> function checkandsubmit() { document.test.submitbut.disabled = true; document.test.submit(); } </script> <body> <form action=&quot;index.php&quot; method=&quot;post&quot; name=&quot;test&quot; onsubmit=&quot;return checkandsubmit ()&quot;> <input type=&quot;hidden&quot; name=&quot;submitted&quot; value=&quot;yes&quot; /> Your Name: <input type=&quot;text&quot; name=&quot;yourname&quot; maxlength=&quot;150&quot; />
  • 97. <input type=&quot;submit&quot; value=&quot;Submit&quot; id=&quot;submitbut&quot; name&quot;submitbut&quot; /></form> </body> </html> <?php if ($file = fopen ( &quot;test.txt&quot;, &quot;w+&quot; )) { fwrite ( $file, &quot;Processing&quot; ); } else { echo &quot;Error opening file.&quot;; } echo $_POST ['yourname']; ?>
  • 98. 42. Preventing Multiple Submissions on the Server Side <html> <body> <form action=&quot;index.php&quot; method=&quot;post&quot;> <input type=&quot;hidden&quot; name=&quot;submitted&quot; value=&quot;yes&quot; /> Your Name: <input type=&quot;text&quot; name=&quot;yourname&quot; maxlength=&quot;150&quot; /><br /> <input type=&quot;submit&quot; value=&quot;Submit&quot; style=&quot;margin-top: 10px;&quot; /></form> </body> </html> <?php session_start (); if (! isset ( $_SESSION ['processing'] )) { $_SESSION ['processing'] = false;}
  • 99. if ($_SESSION ['processing'] == false) { $_SESSION ['processing'] = true; //validation if ($file = fopen ( &quot;test.txt&quot;, &quot;w+&quot; )) { fwrite ( $file, &quot;Processing&quot; ); } else { echo &quot;Error opening file.&quot;; } echo $_POST ['yourname']; unset ( $_SESSION ['processing'] ); } ?>
  • 100. 43. Authenticate user: Database based <?php function authenticate_user() { header('WWW-Authenticate: Basic realm=&quot;Secret Stash&quot;'); header(&quot;HTTP/1.0 401 Unauthorized&quot;); exit; } if (! isset($_SERVER['PHP_AUTH_USER'])) { authenticate_user(); } else { mysql_pconnect(&quot;localhost&quot;,&quot;authenticator&quot;,&quot;secret&quot;) or die(&quot;Can't connect to database server!&quot;); mysql_select_db(&quot;java2s&quot;) or die(&quot;Can't select authentication database!&quot;);
  • 101. $query = &quot;SELECT username, pswd FROM user WHERE username='$_SERVER[PHP_AUTH_USER]' AND pswd=MD5('$_SERVER[PHP_AUTH_PW]')&quot;; $result = mysql_query($query); // If nothing was found, reprompt the user for the login information. if (mysql_num_rows($result) == 0) { authenticate_user(); } } ?>
  • 102. 44. Prompt Browser password dialog <?php if (($_SERVER['PHP_AUTH_USER'] != 'specialuser') || ($_SERVER['PHP_AUTH_PW'] != 'secretpassword')) { header('WWW-Authenticate: Basic Realm=&quot;Secret Stash&quot;'); header('HTTP/1.0 401 Unauthorized'); print('You must provide the proper credentials!'); exit; } ?>
  • 103. 45. Open browser password dialog and authenticate user based on database <?php function authenticate_user() { header('WWW-Authenticate: Basic realm=&quot;Secret Stash&quot;'); header(&quot;HTTP/1.0 401 Unauthorized&quot;); exit; } if(! isset($_SERVER['PHP_AUTH_USER'])) { authenticate_user(); }
  • 104. else { mysql_connect(&quot;localhost&quot;,&quot;authenticator&quot;,&quot;secret&quot;) or die(&quot;Can't connect to database server!&quot;); mysql_select_db(&quot;gilmorebook&quot;) or die(&quot;Can't select authentication database!&quot;); $query = &quot;SELECT username, pswd FROM user WHERE username='$_SERVER[PHP_AUTH_USER]' AND pswd=MD5('$_SERVER[PHP_AUTH_PW]') AND ipAddress='$_SERVER[REMOTE_ADDR]'&quot;; $result = mysql_query($query); if (mysql_num_rows($result) == 0) authenticate_user(); mysql_close(); }?>
  • 105. 46. Login ID Options <HTML> <HEAD> <TITLE>Displaying Login ID Options</TITLE> </HEAD> <BODY> <Hl><CENTER>Generating Login IDs for Dave</CENTER></Hl> <?php $loginfo = array ( FirstName => &quot;Joe&quot;, LastName => &quot;Howrod&quot;, Sex => &quot;Male&quot;, Location => &quot;Arizona&quot;, Age => &quot;24&quot;, MusicChoice => &quot;Pop&quot;, Hobby => &quot;Dance&quot;, Occupation => &quot;Author&quot;); echo &quot;<H3>The information entered by JOe:<BR></H3>&quot;; foreach ($loginfo as $key => $val) { echo &quot;<B>$key</B> => $val<BR>&quot;; }
  • 106. echo &quot;<BR> &quot;; echo &quot;<H3>The login options are:<BR></H3>&quot;; $loginone = array_slice ($loginfo, 0, 2); $logintwo = array_slice ($loginfo, 3, 2); $loginthree = array_slice ($loginfo, 5, 2); $loginfour = array_slice ($loginfo, 6, 2); $loginfive = array_merge ($loginfour, &quot;2001&quot;); echo &quot;The first login option:<BR>&quot;; foreach ($loginone as $optionone) { echo &quot;<B>$optionone</B>&quot;; } echo &quot;<BR>&quot;; echo &quot;The second login option:<BR>&quot;; foreach ($loginone as $optiontwo) { echo &quot;<B>$optiontwo</B>&quot;; } echo &quot;<BR>&quot;;
  • 107. echo &quot;The third login option:<BR>&quot;; foreach ($loginthree as $optionthree) { echo &quot;<B>$optionthree</B>&quot;; } echo &quot;<BR>&quot;; echo &quot;The fourth login option:<BR>&quot;; foreach ($loginfour as $optionfour) { echo &quot;<B>$optionfour</B>&quot;; } echo &quot;<BR>&quot;; echo &quot;The fifth login option:<BR>&quot;; foreach ($loginfive as $optionfive) { echo &quot;<B>$optionfive</B>&quot;; } echo &quot;<BR>&quot;; ?> </BODY> </HTML>
  • 108. 47. Get uniqid <? $id = uniqid(&quot;phpuser&quot;); echo &quot;$id&quot;; ?>
  • 109. 48. Use md5 function to encrypt text <?php $val = &quot;secret&quot;; echo &quot;Pre-hash string: $val <br />&quot;; $hash_val = md5 ($val); echo &quot;Hashed outcome: $hash_val&quot;; ?>
  • 110. 49. md5 and uniqid <? $id = md5(uniqid(rand())); echo &quot;$id&quot;; ?>
  • 111. 50. A user registration process create table user_info ( user_id char(18), fname char(15), email char(35)); //File: index.php <? $form = &quot; <form action=amp;quot;index.phpamp;quot; method=amp;quot;postamp;quot;> <input type=amp;quot;hiddenamp;quot; name=amp;quot;seenformamp;quot; value=amp;quot;yamp;quot;> Your first name?:<br> <input type=amp;quot;textamp;quot; name=amp;quot;fnameamp;quot; value=amp;quot;amp;quot;><br> Your email?:<br> <input type=amp;quot;textamp;quot; name=amp;quot;emailamp;quot; value=amp;quot;amp;quot;><br> <input type=amp;quot;submitamp;quot; value=amp;quot;Register!amp;quot;> </form> &quot;;
  • 112. if ((! isset ($seenform)) && (! isset ($userid))) : print $form; elseif (isset ($seenform) && (! isset ($userid))) : $uniq_id = uniqid(rand()); @mysql_pconnect(&quot;localhost&quot;, &quot;root&quot;, &quot;&quot;) or die(&quot;Could not connect to MySQL server!&quot;); @mysql_select_db(&quot;user&quot;) or die(&quot;Could not select user database!&quot;); $query = &quot;INSERT INTO user_info VALUES('$uniq_id', '$fname', '$email')&quot;; $result = mysql_query($query) or die(&quot;Could not insert user information!&quot;); setcookie (&quot;userid&quot;, $uniq_id, time()+2592000); print &quot;Congratulations $fname! You are now registered!.&quot;;
  • 113. elseif (isset($userid)) : @mysql_pconnect(&quot;localhost&quot;, &quot;root&quot;, &quot;&quot;) or die(&quot;Could not connect to MySQL server!&quot;); @mysql_select_db(&quot;user&quot;) or die(&quot;Could not select user database!&quot;); $query = &quot;SELECT * FROM user_info WHERE user_id = '$userid'&quot;; $result = mysql_query($query) or die(&quot;Could not extract user information!&quot;); $row = mysql_fetch_array($result); print &quot;Hi &quot;.$row[&quot;fname&quot;].&quot;,<br>&quot;; print &quot;Your email address is &quot;.$row[&quot;email&quot;]; endif; ?>
  • 114.