PRACTICAL PHP
 BY EXAMPLE

 Jan Leth-Kjaer
Scope and subjects
• This is not a PHP upcode class.
• This is not a Zend class.
• This is not an Power specific class.
• This is not about installation of
  Apache.
• This is not about work management
  of Pase, PHP or related areas.
• This is not a PHP security class.
So what is it then?
• I presume you all know some type of
  programming and SQL.
• I presume you know HTML at some level.
• I presume you can or know a bit of PHP or
  likewise programming languages.
• We will running through a number of practial
  PHP examples and see the frontend as well as
  the backend = code.
Data management

•   MySQL – the database.
•   Retrieve some data.
•   Show the data.
•   Give user functionality to enter/update data.
•   Update the data in database.
Data management – go get it

<?php
session_start();
require("access.php"); // Variabler til mysql hentes
$resultat = mysql_query("SELECT * FROM customer WHERE customernumber = '$number'");
while ($row = mysql_fetch_array($resultat)) {
$CompanyName = $row['CompanyName'];
$Name = $row['Name'];
$email = $row['email'];
$Address1 = $row['Address1'];
$Address2 = $row['Address2'];
....
?>

......

<form action='index.php?page1=CustomerValidate.php method='post' enctype='multipart/form-data'>
....

<tr>
<td width="193"><font face="Verdana" size="2"><b>Companyname:<font color="#FF0000">*</font></b></font></td>
<td colspan="2"><input type="text" name="T1" size="50" tabindex="1" value="<?php echo $CompanyName ; ?>" ></td>
</tr>
Data management – validate/update

$CompanyName = $_POST[‘CompanyName '];
.....

// Validate...

if(empty( $CompanyName ) ) {
      $error1 = '<br> Companyname is empty ';
      }

....

if (preg_match("/^([w|.|-|_]+)@([w||-|_]+).([w|.|-|_]+)$/i", $email-address)) {

 } else {
   $error4 = "<br> Email is not correctt!";
 }

....
Echo $error1 . $error4;
.....

mysql_query("UPDATE Customer SET CompanyName = '$CompanyName '..... Where....
File management

• File management on server.
<table border="0" width="50%" cellspacing="10" cellpadding="20">
<?php
$path = « foldername";
  // Open the folder
  $dir_handle = @opendir($path) or die("Unable to open $path");
  // Loop through the files
  while ($file = readdir($dir_handle)) {
  if($file == "." || $file == ".." || substr($file, 0, 10) != 'Nyhedsbrev') continue;
        $aar = substr($file, 11, 4);
        $month_number = substr($file, 16, 2);
        $month_name = date( 'F', mktime(0, 0, 0, $month_number) );
        echo "<tr><td width='32' align='left' valign='top'><font face='Verdana' size='2'>";
        echo "<font face='Verdana' size='2'>" . $aar . "</td><td><font face='Verdana' size='2'>" . $month_name . "</td><td>";
        echo "<font face='Verdana' size='2'><a href='/ foldername /$file'>$file</a></td></tr>";
  }
  // Close
  closedir($dir_handle);
?>
</table>
PDF creation

• PHP plugin.
<?php
require('fpdf.php');
                                                                                                http://www.fpdf.org
// Get some data – to use..
$resultat1 = mysql_query("SELECT * from meetings where active=‘NEXT'") or die(mysql_error());
while ($row = mysql_fetch_array($resultat1)) {
$firma[$p] = substr($row['CompanyName'], 0, 44);

$pdf->AddPage(P,A4);

// Create some frame – including some text
$pdf->SetFont('Arial','B', ‘$CompanyName’);
$pdf->SetTextColor(0,0,0);
$pdf->SetXY(10,10);
$pdf->SetDrawColor(240,240,240);
$pdf->Cell(90,54,"$pnavn[$a]",1,1,C);
PayPal

• Free to have - not free to use.
• You need an account.
  Hidden API buildup.
                                         https://cms.paypal.com/us/cgi-bin/?cmd=_render-
•                                        content&content_ID=developer/howto_html_landing




• Create buttons – onsite/offsite.
• Mostly European creditcards.
• Transaction-information related to e.g. invoice
  number.
• PayPal – developer site. (https://www.x.com/developers/paypal)
PayPal – standard call

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="FLFFSFSFSDFL">
<input type="hidden" name="on0" value="Faktura:

<table>
<tr><td nowrap="nowrap">
<font face="Verdana" size="2">Invoice number</font>
<font face="Verdana" size="1"> (Price 5000€.)</font></td></tr><tr><td><input type="text" name="os0" maxlength="200" value="
<?php
echo $workfaknr;
?>
" disabled></td></tr>
<tr><td>&nbsp;</td></tr>
</table>
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way
       to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/da_DK/i/scr/pixel.gif" width="1" height="1">
</form>
PayPal – build up

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="PAYPAL ACCOUNT NAME">
<input type="hidden" name="item_name" value=« Invoice total">
<table>
<tr><td><input type="hidden" name="on0" value="Faktura"><font face="Verdana" size="2">Pick Invoice</font></td></tr><tr><td><select name="os0">
<?php
while ($row = mysql_fetch_array($result1))
{ ... Get invoices... }
<tr><td>&nbsp;</td></tr>
</table>
<?php
Echo "<option value='" . $worknr . "'>" . $worknr . ": " . money_format('%.2n', $Total) . "</option>";
$harray[$worki] = "<input type='hidden' name='option_select" . $worki . "' value='" . $worknr . "'><input type='hidden' name='option_amount" . $worki . "'
        value='" . sprintf("%01.2f", $Ptotal) . "'>";
$worki++;
}
?>
<input type="hidden" name="option_index" value="0">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way
        to pay online!">
  <img alt="" border="0" src="https://www.paypalobjects.com/da_DK/i/scr/pixel.gif" width="1" height="1"></p>
</form>
SMS API

•   External function to call.
•   You may see different setup.
•   Parameter call – cross site
•   API object creation.
•   Call back – with delayed information.

• Other functions as API – e.g. Google.
SMS API

$smsnumber = $wmobil[$i];
$bruger = $_SESSION['navn'];
$nu = date("YmdHis");
$work = $i;

$smsid = $bruger . $nu . $work;

// Build Parameters (RETRY=TRUE som default)
$strParameters =
       "?username=USERNAME!!!!" .
    "&password=CODE!!!" .
    "&dialcode=45" .
    "&recipient=$smsnumber" .
    "&text=" . urlencode(utf8_encode("$sms-text")) .
       "&from=Common+CZ" .
       "&callback_url=" . urlencode("http://www.gs-gruppen.org/GS-SMSs.php?smsid=$smsid&password=RETURNPASSWORD");

//Echo $strParameters;

//Send sms and save output in $strOutput
$strOutput = file_get_contents("http://api.textreactor.com/legacy/sms.php" . $strParameters);
Thank you for your attention!
         Questions

More Related Content

DOCX
Coding part
TXT
Pp checker
PDF
SULTHAN's - PHP MySQL programs
PPTX
16.mysql stored procedures in laravel
PDF
Tutorial_4_PHP
PDF
PHP and Rich Internet Applications
PDF
Engines: Team Development on Rails (2005)
Coding part
Pp checker
SULTHAN's - PHP MySQL programs
16.mysql stored procedures in laravel
Tutorial_4_PHP
PHP and Rich Internet Applications
Engines: Team Development on Rails (2005)

What's hot (15)

PDF
PHP an intro -1
KEY
Who Needs Ruby When You've Got CodeIgniter
PDF
Pagination in PHP
PDF
Apostrophe
PDF
Payments On Rails
PDF
Moving a high traffic ZF1 Enterprise Application to SF2 - Lessons learned
PDF
Country State City Dropdown in PHP
PDF
Your Custom WordPress Admin Pages Suck
PDF
Add edit delete in Codeigniter in PHP
TXT
Posts ‹ teslaecoenergy — word press php
PDF
Make your own wp cli command in 10min
PPTX
Top 5 Magento Secure Coding Best Practices
PPTX
Database Management - Lecture 4 - PHP and Mysql
TXT
Xmpp prebind
PDF
Php (1)
PHP an intro -1
Who Needs Ruby When You've Got CodeIgniter
Pagination in PHP
Apostrophe
Payments On Rails
Moving a high traffic ZF1 Enterprise Application to SF2 - Lessons learned
Country State City Dropdown in PHP
Your Custom WordPress Admin Pages Suck
Add edit delete in Codeigniter in PHP
Posts ‹ teslaecoenergy — word press php
Make your own wp cli command in 10min
Top 5 Magento Secure Coding Best Practices
Database Management - Lecture 4 - PHP and Mysql
Xmpp prebind
Php (1)
Ad

Similar to Practical PHP by example Jan Leth-Kjaer (20)

DOC
Software development
PPTX
Software development
PDF
Php tutorial handout
PDF
How to Write the Perfect PHP Script for Your Web Development Class
PDF
Industrail training in php
PPTX
how create e_commerce website using php as a tool
PPTX
php is the most important programming language
PPT
php 1
PPTX
Quick beginner to Lower-Advanced guide/tutorial in PHP
PDF
Php summary
PDF
&lt;img src="../i/r_14.png" />
PDF
php-mysql-tutorial-part-3
PDF
php-mysql-tutorial-part-3
PDF
&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/
PPTX
BITM3730 10-24.pptx
PDF
Php Security
PPTX
BITM3730 10-25.pptx
PDF
Php my sql programing - brochure
Software development
Software development
Php tutorial handout
How to Write the Perfect PHP Script for Your Web Development Class
Industrail training in php
how create e_commerce website using php as a tool
php is the most important programming language
php 1
Quick beginner to Lower-Advanced guide/tutorial in PHP
Php summary
&lt;img src="../i/r_14.png" />
php-mysql-tutorial-part-3
php-mysql-tutorial-part-3
&lt;b>PHP&lt;/b>/MySQL &lt;b>Tutorial&lt;/b> webmonkey/programming/
BITM3730 10-24.pptx
Php Security
BITM3730 10-25.pptx
Php my sql programing - brochure
Ad

More from COMMON Europe (20)

PDF
What's New in WebSphere Application Server
PDF
Compiling the Compiler
PDF
Workload Groups overview updates
PDF
Why i - Common Europe 2012
PDF
The Ruby OpenSSL extension
PDF
Using Ruby on IBM i (i5/OS)
PDF
IBM Systems Director Navigator for i
PDF
IBM i Trends & Directions Common Europe 2012
PDF
IBM i Technology Refreshes Overview 2012 06-04
PDF
IBM i 7.1 & TRs CEC 2012
PDF
DB2 Web Query whats new
PDF
Access client solutions overview
PDF
What's new with Zend server
PDF
RPG investment
PDF
Php arrays for RPG programmers
PDF
Open source report writing tools for IBM i Vienna 2012
PDF
Moving 5.4 to 7.1 AB
PDF
Introduction to My SQL
PDF
IBM CEC 2012 Storage june 11, 2012
PDF
Getting started with PHP on IBM i
What's New in WebSphere Application Server
Compiling the Compiler
Workload Groups overview updates
Why i - Common Europe 2012
The Ruby OpenSSL extension
Using Ruby on IBM i (i5/OS)
IBM Systems Director Navigator for i
IBM i Trends & Directions Common Europe 2012
IBM i Technology Refreshes Overview 2012 06-04
IBM i 7.1 & TRs CEC 2012
DB2 Web Query whats new
Access client solutions overview
What's new with Zend server
RPG investment
Php arrays for RPG programmers
Open source report writing tools for IBM i Vienna 2012
Moving 5.4 to 7.1 AB
Introduction to My SQL
IBM CEC 2012 Storage june 11, 2012
Getting started with PHP on IBM i

Recently uploaded (20)

PDF
Domain-specific knowledge and context in large language models: challenges, c...
PDF
Slides World Game (s) Great Redesign Eco Economic Epochs.pdf
PDF
Intravenous drug administration application for pediatric patients via augmen...
PDF
The AI Revolution in Customer Service - 2025
PPTX
How to use fields_get method in Odoo 18
PPTX
Information-Technology-in-Human-Society (2).pptx
PDF
EIS-Webinar-Regulated-Industries-2025-08.pdf
PPTX
Blending method and technology for hydrogen.pptx
PDF
substrate PowerPoint Presentation basic one
PDF
“Introduction to Designing with AI Agents,” a Presentation from Amazon Web Se...
PDF
Streamline Vulnerability Management From Minimal Images to SBOMs
PDF
Optimizing bioinformatics applications: a novel approach with human protein d...
PDF
FASHION-DRIVEN TEXTILES AS A CRYSTAL OF A NEW STREAM FOR STAKEHOLDER CAPITALI...
PDF
Secure Java Applications against Quantum Threats
PDF
Decision Optimization - From Theory to Practice
PDF
Human Computer Interaction Miterm Lesson
PDF
TicketRoot: Event Tech Solutions Deck 2025
PDF
Child-friendly e-learning for artificial intelligence education in Indonesia:...
PDF
Examining Bias in AI Generated News Content.pdf
PDF
Ebook - The Future of AI A Comprehensive Guide.pdf
Domain-specific knowledge and context in large language models: challenges, c...
Slides World Game (s) Great Redesign Eco Economic Epochs.pdf
Intravenous drug administration application for pediatric patients via augmen...
The AI Revolution in Customer Service - 2025
How to use fields_get method in Odoo 18
Information-Technology-in-Human-Society (2).pptx
EIS-Webinar-Regulated-Industries-2025-08.pdf
Blending method and technology for hydrogen.pptx
substrate PowerPoint Presentation basic one
“Introduction to Designing with AI Agents,” a Presentation from Amazon Web Se...
Streamline Vulnerability Management From Minimal Images to SBOMs
Optimizing bioinformatics applications: a novel approach with human protein d...
FASHION-DRIVEN TEXTILES AS A CRYSTAL OF A NEW STREAM FOR STAKEHOLDER CAPITALI...
Secure Java Applications against Quantum Threats
Decision Optimization - From Theory to Practice
Human Computer Interaction Miterm Lesson
TicketRoot: Event Tech Solutions Deck 2025
Child-friendly e-learning for artificial intelligence education in Indonesia:...
Examining Bias in AI Generated News Content.pdf
Ebook - The Future of AI A Comprehensive Guide.pdf

Practical PHP by example Jan Leth-Kjaer

  • 1. PRACTICAL PHP BY EXAMPLE Jan Leth-Kjaer
  • 2. Scope and subjects • This is not a PHP upcode class. • This is not a Zend class. • This is not an Power specific class. • This is not about installation of Apache. • This is not about work management of Pase, PHP or related areas. • This is not a PHP security class.
  • 3. So what is it then? • I presume you all know some type of programming and SQL. • I presume you know HTML at some level. • I presume you can or know a bit of PHP or likewise programming languages. • We will running through a number of practial PHP examples and see the frontend as well as the backend = code.
  • 4. Data management • MySQL – the database. • Retrieve some data. • Show the data. • Give user functionality to enter/update data. • Update the data in database.
  • 5. Data management – go get it <?php session_start(); require("access.php"); // Variabler til mysql hentes $resultat = mysql_query("SELECT * FROM customer WHERE customernumber = '$number'"); while ($row = mysql_fetch_array($resultat)) { $CompanyName = $row['CompanyName']; $Name = $row['Name']; $email = $row['email']; $Address1 = $row['Address1']; $Address2 = $row['Address2']; .... ?> ...... <form action='index.php?page1=CustomerValidate.php method='post' enctype='multipart/form-data'> .... <tr> <td width="193"><font face="Verdana" size="2"><b>Companyname:<font color="#FF0000">*</font></b></font></td> <td colspan="2"><input type="text" name="T1" size="50" tabindex="1" value="<?php echo $CompanyName ; ?>" ></td> </tr>
  • 6. Data management – validate/update $CompanyName = $_POST[‘CompanyName ']; ..... // Validate... if(empty( $CompanyName ) ) { $error1 = '<br> Companyname is empty '; } .... if (preg_match("/^([w|.|-|_]+)@([w||-|_]+).([w|.|-|_]+)$/i", $email-address)) { } else { $error4 = "<br> Email is not correctt!"; } .... Echo $error1 . $error4; ..... mysql_query("UPDATE Customer SET CompanyName = '$CompanyName '..... Where....
  • 7. File management • File management on server. <table border="0" width="50%" cellspacing="10" cellpadding="20"> <?php $path = « foldername"; // Open the folder $dir_handle = @opendir($path) or die("Unable to open $path"); // Loop through the files while ($file = readdir($dir_handle)) { if($file == "." || $file == ".." || substr($file, 0, 10) != 'Nyhedsbrev') continue; $aar = substr($file, 11, 4); $month_number = substr($file, 16, 2); $month_name = date( 'F', mktime(0, 0, 0, $month_number) ); echo "<tr><td width='32' align='left' valign='top'><font face='Verdana' size='2'>"; echo "<font face='Verdana' size='2'>" . $aar . "</td><td><font face='Verdana' size='2'>" . $month_name . "</td><td>"; echo "<font face='Verdana' size='2'><a href='/ foldername /$file'>$file</a></td></tr>"; } // Close closedir($dir_handle); ?> </table>
  • 8. PDF creation • PHP plugin. <?php require('fpdf.php'); http://www.fpdf.org // Get some data – to use.. $resultat1 = mysql_query("SELECT * from meetings where active=‘NEXT'") or die(mysql_error()); while ($row = mysql_fetch_array($resultat1)) { $firma[$p] = substr($row['CompanyName'], 0, 44); $pdf->AddPage(P,A4); // Create some frame – including some text $pdf->SetFont('Arial','B', ‘$CompanyName’); $pdf->SetTextColor(0,0,0); $pdf->SetXY(10,10); $pdf->SetDrawColor(240,240,240); $pdf->Cell(90,54,"$pnavn[$a]",1,1,C);
  • 9. PayPal • Free to have - not free to use. • You need an account. Hidden API buildup. https://cms.paypal.com/us/cgi-bin/?cmd=_render- • content&content_ID=developer/howto_html_landing • Create buttons – onsite/offsite. • Mostly European creditcards. • Transaction-information related to e.g. invoice number. • PayPal – developer site. (https://www.x.com/developers/paypal)
  • 10. PayPal – standard call <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_s-xclick"> <input type="hidden" name="hosted_button_id" value="FLFFSFSFSDFL"> <input type="hidden" name="on0" value="Faktura: <table> <tr><td nowrap="nowrap"> <font face="Verdana" size="2">Invoice number</font> <font face="Verdana" size="1"> (Price 5000€.)</font></td></tr><tr><td><input type="text" name="os0" maxlength="200" value=" <?php echo $workfaknr; ?> " disabled></td></tr> <tr><td>&nbsp;</td></tr> </table> <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> <img alt="" border="0" src="https://www.paypalobjects.com/da_DK/i/scr/pixel.gif" width="1" height="1"> </form>
  • 11. PayPal – build up <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="business" value="PAYPAL ACCOUNT NAME"> <input type="hidden" name="item_name" value=« Invoice total"> <table> <tr><td><input type="hidden" name="on0" value="Faktura"><font face="Verdana" size="2">Pick Invoice</font></td></tr><tr><td><select name="os0"> <?php while ($row = mysql_fetch_array($result1)) { ... Get invoices... } <tr><td>&nbsp;</td></tr> </table> <?php Echo "<option value='" . $worknr . "'>" . $worknr . ": " . money_format('%.2n', $Total) . "</option>"; $harray[$worki] = "<input type='hidden' name='option_select" . $worki . "' value='" . $worknr . "'><input type='hidden' name='option_amount" . $worki . "' value='" . sprintf("%01.2f", $Ptotal) . "'>"; $worki++; } ?> <input type="hidden" name="option_index" value="0"> <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> <img alt="" border="0" src="https://www.paypalobjects.com/da_DK/i/scr/pixel.gif" width="1" height="1"></p> </form>
  • 12. SMS API • External function to call. • You may see different setup. • Parameter call – cross site • API object creation. • Call back – with delayed information. • Other functions as API – e.g. Google.
  • 13. SMS API $smsnumber = $wmobil[$i]; $bruger = $_SESSION['navn']; $nu = date("YmdHis"); $work = $i; $smsid = $bruger . $nu . $work; // Build Parameters (RETRY=TRUE som default) $strParameters = "?username=USERNAME!!!!" . "&password=CODE!!!" . "&dialcode=45" . "&recipient=$smsnumber" . "&text=" . urlencode(utf8_encode("$sms-text")) . "&from=Common+CZ" . "&callback_url=" . urlencode("http://www.gs-gruppen.org/GS-SMSs.php?smsid=$smsid&password=RETURNPASSWORD"); //Echo $strParameters; //Send sms and save output in $strOutput $strOutput = file_get_contents("http://api.textreactor.com/legacy/sms.php" . $strParameters);
  • 14. Thank you for your attention! Questions