SlideShare ist ein Scribd-Unternehmen logo
1 von 20
PHP for hacks
                   Tom Praison
      (tpraison@yahoo-inc.com)
What is PHP?
• Server side language
• Very easy to learn
• Available on LAMP stack (Linux Apache Mysql
  PHP)
• Does not require any special tools. Create a file
  with .php extension and your done.
What we need to learn?
•   Enough PHP to handle simple request
•   How to talk to backend data store using PHP
•   How to parse XML/JSON in PHP
•   How to generate JSON in PHP
Getting Started
•   You need a local server with PHP enabled.
•   XAMPP for windows
•   MAMP for Mac OSx
•   Linux has it by default
Getting Started



Create a file hello.php into htdocs and call it like this
http://localhost:8888/hello.php
           <?php
            $school="iit-kgp";
            echo "Hello, World $school";
           ?>
• PHP blocks start with <?php and end with ?> -
• Every line of PHP has to end with a semicolon
  ";”
• Variables in PHP start with a $
• You print out content to the document in PHP
  with the echo command.
• $school is variable and it can be printed out
• You can jump in and out of PHP anywhere in the
  document. So if you intersperse PHP with HTML
  blocks, that is totally fine. For example:
Mix Match

<?php
 $origin = 'Outer Space';
 $planet = 'Earth';
 $plan = 9;
 $sceneryType = "awful";
?>
<h1>Synopsis</h1><p>It was a peaceful time on
planet <?php echo $planet;?> and people in the
<?php echo $sceneryType;?> scenery were
unaware of the diabolic plan <?php echo
$plan;?> from <?php echo $origin;?> that will
take their senses to the edge of what can be
endured.</p>



                                                 demo1.php
Displaying more complex data
• You can define arrays in PHP using the array()
  method
    $lampstack = array('Linux','Apache','MySQL','PHP');
• If you simply want to display a complex
  datatype like this in PHP for debugging you can
  use the print_r() command
   $lampstack = array('Linux','Apache','MySQL','PHP');
print_r($lampstack);




                                                         demo2.php
Arrays

<ul>
<?php
$lampstack = array('Linux','Apache','MySQL','PHP');
echo '<li>Operating System:'.$lampstack[0] . '</li>';
echo '<li>Server:' . $lampstack[1] . '</li>';
echo '<li>Database:' . $lampstack[2] . '</li>';
echo '<li>Language:' . $lampstack[3] . '</li>';
?>
</ul>




                                                        demo3.php
Arrays


<ul>
<?php
$lampstack = array('Linux','Apache','MySQL','PHP');
$labels = array('OperatingSystem','Server','Database','Language');
$length = sizeof($lampstack);
for( $i = 0;$i < $length;$i++ ){
  echo '<li>' . $labels[$i] . ':' . $lampstack[$i] . '</li>';
}
?>
</ul>
      sizeof($array) - this will return the size of the array




                                                                demo4.php
Associative Arrays

<ul>
<?php
$lampstack = array(
  'Operating System' => 'Linux',
  'Server' => 'Apache',
  'Database' => 'MySQL',
  'Language' => 'PHP'
);
$length = sizeof($lampstack);
$keys = array_keys($lampstack);
for( $i = 0;$i < $length;$i++ ){
  echo '<li>' . $keys[$i] . ':' . $lampstack[$keys[$i]] . '</li>';
}
?>
</ul>


                                                                     demo5.php
Functions
<?php
function renderList($array){
  if( sizeof($array) > 0 ){
    echo '<ul>';
foreach( $array as $key => $item ){
      echo '<li>' . $key . ':' . $item . '</li>';
    }
    echo '</ul>';
  }
}
$lampstack = array(
  'Operating System' => 'Linux',
  'Server' => 'Apache',
  'Database' => 'MySQL',
  'Language' => 'PHP'
);
renderList($lampstack);
?>                                                  demo6.php
Interacting with the web - URL
                        parameters
<?php
$name = 'Tom';

// if there is no language defined, switch to English
if( !isset($_GET['language']) ){
  $welcome = 'Oh, hello there, ';
}
if( $_GET['language'] == 'hindi' ){
  $welcome = 'Namastae, ';
}
switch($_GET['font']){
  case 'small':
    $size = 80;
  break;
  case 'medium':
    $size = 100;
  break;
  case 'large':
    $size = 120;
  break;
  default:
    $size = 100;
  break;
}
echo '<style>body{font-size:' . $size . '%;}</style>';
echo '<h1>'.$welcome.$name.'</h1>';
?>


                                                         demo7.php
Loading content from the web

<?php
 // define the URL to load
 $url = 'http://cricket.yahoo.com/player-profile/Sachin-
Tendulkar_2962';
 // start cURL
 $ch = curl_init();
 // tell cURL what the URL is
curl_setopt($ch, CURLOPT_URL, $url);
 // tell cURL that you want the data back from that URL
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 // run cURL
 $output = curl_exec($ch);
 // end the cURL call (this also cleans up memory so it is
 // important)
curl_close($ch);
 // display the output
 echo $output;
?>




                                                             demo8.php
Displaying XML content
• Demo




demo9.php
Displaying JSON content
• Demo




demo9.php
Putting all together
Further Reference
          http://www.php.net/
      http://developer.yahoo.com
   http://isithackday.com/hackday-
    toolbox/phpforhacks/index.html
http://www.slideshare.net/tompraison

Weitere ähnliche Inhalte

Was ist angesagt?

Webrtc mojo
Webrtc mojoWebrtc mojo
Webrtc mojobpmedley
 
PHP: The easiest language to learn.
PHP: The easiest language to learn.PHP: The easiest language to learn.
PHP: The easiest language to learn.Binny V A
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworksdiego_k
 
Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101hendrikvb
 
GettingStartedWithPHP
GettingStartedWithPHPGettingStartedWithPHP
GettingStartedWithPHPNat Weerawan
 
What's new in PHP 5.5
What's new in PHP 5.5What's new in PHP 5.5
What's new in PHP 5.5Tom Corrigan
 
PHP Basics and Demo HackU
PHP Basics and Demo HackUPHP Basics and Demo HackU
PHP Basics and Demo HackUAnshu Prateek
 
Class 6 - PHP Web Programming
Class 6 - PHP Web ProgrammingClass 6 - PHP Web Programming
Class 6 - PHP Web ProgrammingAhmed Swilam
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest UpdatesIftekhar Eather
 
Php tips-and-tricks4128
Php tips-and-tricks4128Php tips-and-tricks4128
Php tips-and-tricks4128PrinceGuru MS
 
News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 WorldFabien Potencier
 
07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboardsDenis Ristic
 

Was ist angesagt? (20)

Webrtc mojo
Webrtc mojoWebrtc mojo
Webrtc mojo
 
PHP: The easiest language to learn.
PHP: The easiest language to learn.PHP: The easiest language to learn.
PHP: The easiest language to learn.
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
 
Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101
 
Mojo as a_client
Mojo as a_clientMojo as a_client
Mojo as a_client
 
GettingStartedWithPHP
GettingStartedWithPHPGettingStartedWithPHP
GettingStartedWithPHP
 
Intermediate PHP
Intermediate PHPIntermediate PHP
Intermediate PHP
 
What's new in PHP 5.5
What's new in PHP 5.5What's new in PHP 5.5
What's new in PHP 5.5
 
Php Lecture Notes
Php Lecture NotesPhp Lecture Notes
Php Lecture Notes
 
PHP Basics and Demo HackU
PHP Basics and Demo HackUPHP Basics and Demo HackU
PHP Basics and Demo HackU
 
Class 6 - PHP Web Programming
Class 6 - PHP Web ProgrammingClass 6 - PHP Web Programming
Class 6 - PHP Web Programming
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
 
PHP5.5 is Here
PHP5.5 is HerePHP5.5 is Here
PHP5.5 is Here
 
PHP POWERPOINT SLIDES
PHP POWERPOINT SLIDESPHP POWERPOINT SLIDES
PHP POWERPOINT SLIDES
 
Php tips-and-tricks4128
Php tips-and-tricks4128Php tips-and-tricks4128
Php tips-and-tricks4128
 
Perl5i
Perl5iPerl5i
Perl5i
 
News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 World
 
Php security3895
Php security3895Php security3895
Php security3895
 
07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards07 Introduction to PHP #burningkeyboards
07 Introduction to PHP #burningkeyboards
 
Php functions
Php functionsPhp functions
Php functions
 

Andere mochten auch

Vault finance practice guide
Vault finance practice guideVault finance practice guide
Vault finance practice guideAnuj Verma
 
Teen Drama Shows Over The Year
Teen Drama Shows Over The YearTeen Drama Shows Over The Year
Teen Drama Shows Over The YearGowthamanS
 
페차쿠차발표 김남희
페차쿠차발표 김남희페차쿠차발표 김남희
페차쿠차발표 김남희kimnamhee
 
페차쿠차 김남희
페차쿠차 김남희페차쿠차 김남희
페차쿠차 김남희kimnamhee
 
21146103 김남희
21146103 김남희21146103 김남희
21146103 김남희kimnamhee
 
페차쿠차돋움 김남희
페차쿠차돋움 김남희페차쿠차돋움 김남희
페차쿠차돋움 김남희kimnamhee
 
HackU: How to think of a great idea
HackU: How to think of a great ideaHackU: How to think of a great idea
HackU: How to think of a great ideaTom Praison Praison
 
Economics of slums in developing countries
Economics of slums in developing countries Economics of slums in developing countries
Economics of slums in developing countries pepo_pepo2000
 
Livre Blanc Niouzeo L'usage des newsletters dans les entreprises du secteu...
Livre  Blanc  Niouzeo  L'usage des newsletters dans les entreprises du secteu...Livre  Blanc  Niouzeo  L'usage des newsletters dans les entreprises du secteu...
Livre Blanc Niouzeo L'usage des newsletters dans les entreprises du secteu...Alain Planger
 
Altics : Maximiser votre potentiel de conversion en soignant le couple objet/...
Altics : Maximiser votre potentiel de conversion en soignant le couple objet/...Altics : Maximiser votre potentiel de conversion en soignant le couple objet/...
Altics : Maximiser votre potentiel de conversion en soignant le couple objet/...Alain Planger
 
Email Marketing : usages et enjeux TIC
Email Marketing : usages et enjeux TICEmail Marketing : usages et enjeux TIC
Email Marketing : usages et enjeux TICAlain Planger
 
Primo @ ULg : formation à destination du personnel des Bibliothèques de l'Uni...
Primo @ ULg : formation à destination du personnel des Bibliothèques de l'Uni...Primo @ ULg : formation à destination du personnel des Bibliothèques de l'Uni...
Primo @ ULg : formation à destination du personnel des Bibliothèques de l'Uni...François Renaville
 
34 Mots de html pour créer sa Newsletter
34 Mots de html pour créer sa Newsletter34 Mots de html pour créer sa Newsletter
34 Mots de html pour créer sa NewsletterAlain Planger
 

Andere mochten auch (20)

Cintai bahasa kebangsaan
Cintai bahasa kebangsaanCintai bahasa kebangsaan
Cintai bahasa kebangsaan
 
Print portfolio
Print portfolioPrint portfolio
Print portfolio
 
Vault finance practice guide
Vault finance practice guideVault finance practice guide
Vault finance practice guide
 
Nilai murni
Nilai murniNilai murni
Nilai murni
 
Subir dibujo
Subir dibujoSubir dibujo
Subir dibujo
 
Teen Drama Shows Over The Year
Teen Drama Shows Over The YearTeen Drama Shows Over The Year
Teen Drama Shows Over The Year
 
페차쿠차발표 김남희
페차쿠차발표 김남희페차쿠차발표 김남희
페차쿠차발표 김남희
 
페차쿠차 김남희
페차쿠차 김남희페차쿠차 김남희
페차쿠차 김남희
 
21146103 김남희
21146103 김남희21146103 김남희
21146103 김남희
 
Subir dibujo
Subir dibujoSubir dibujo
Subir dibujo
 
페차쿠차돋움 김남희
페차쿠차돋움 김남희페차쿠차돋움 김남희
페차쿠차돋움 김남희
 
Ascarya edit
Ascarya editAscarya edit
Ascarya edit
 
Hacking with Semantic Web
Hacking with Semantic WebHacking with Semantic Web
Hacking with Semantic Web
 
HackU: How to think of a great idea
HackU: How to think of a great ideaHackU: How to think of a great idea
HackU: How to think of a great idea
 
Economics of slums in developing countries
Economics of slums in developing countries Economics of slums in developing countries
Economics of slums in developing countries
 
Livre Blanc Niouzeo L'usage des newsletters dans les entreprises du secteu...
Livre  Blanc  Niouzeo  L'usage des newsletters dans les entreprises du secteu...Livre  Blanc  Niouzeo  L'usage des newsletters dans les entreprises du secteu...
Livre Blanc Niouzeo L'usage des newsletters dans les entreprises du secteu...
 
Altics : Maximiser votre potentiel de conversion en soignant le couple objet/...
Altics : Maximiser votre potentiel de conversion en soignant le couple objet/...Altics : Maximiser votre potentiel de conversion en soignant le couple objet/...
Altics : Maximiser votre potentiel de conversion en soignant le couple objet/...
 
Email Marketing : usages et enjeux TIC
Email Marketing : usages et enjeux TICEmail Marketing : usages et enjeux TIC
Email Marketing : usages et enjeux TIC
 
Primo @ ULg : formation à destination du personnel des Bibliothèques de l'Uni...
Primo @ ULg : formation à destination du personnel des Bibliothèques de l'Uni...Primo @ ULg : formation à destination du personnel des Bibliothèques de l'Uni...
Primo @ ULg : formation à destination du personnel des Bibliothèques de l'Uni...
 
34 Mots de html pour créer sa Newsletter
34 Mots de html pour créer sa Newsletter34 Mots de html pour créer sa Newsletter
34 Mots de html pour créer sa Newsletter
 

Ähnlich wie Php hacku

Ähnlich wie Php hacku (20)

sumana_PHP_mysql_IIT_BOMBAY_2013
sumana_PHP_mysql_IIT_BOMBAY_2013sumana_PHP_mysql_IIT_BOMBAY_2013
sumana_PHP_mysql_IIT_BOMBAY_2013
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Starting Out With PHP
Starting Out With PHPStarting Out With PHP
Starting Out With PHP
 
WT_PHP_PART1.pdf
WT_PHP_PART1.pdfWT_PHP_PART1.pdf
WT_PHP_PART1.pdf
 
Php Mysql
Php Mysql Php Mysql
Php Mysql
 
PSGI and Plack from first principles
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principles
 
PHP And Web Services: Perfect Partners
PHP And Web Services: Perfect PartnersPHP And Web Services: Perfect Partners
PHP And Web Services: Perfect Partners
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Web 8 | Introduction to PHP
Web 8 | Introduction to PHPWeb 8 | Introduction to PHP
Web 8 | Introduction to PHP
 
FYBSC IT Web Programming Unit IV PHP and MySQL
FYBSC IT Web Programming Unit IV  PHP and MySQLFYBSC IT Web Programming Unit IV  PHP and MySQL
FYBSC IT Web Programming Unit IV PHP and MySQL
 
Pecl Picks
Pecl PicksPecl Picks
Pecl Picks
 
Php with mysql ppt
Php with mysql pptPhp with mysql ppt
Php with mysql ppt
 
Modern php
Modern phpModern php
Modern php
 
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
 
The new features of PHP 7
The new features of PHP 7The new features of PHP 7
The new features of PHP 7
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
Fatc
FatcFatc
Fatc
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overview
 
Php basic for vit university
Php basic for vit universityPhp basic for vit university
Php basic for vit university
 

Kürzlich hochgeladen

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 

Kürzlich hochgeladen (20)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 

Php hacku

  • 1. PHP for hacks Tom Praison (tpraison@yahoo-inc.com)
  • 2.
  • 3.
  • 4. What is PHP? • Server side language • Very easy to learn • Available on LAMP stack (Linux Apache Mysql PHP) • Does not require any special tools. Create a file with .php extension and your done.
  • 5. What we need to learn? • Enough PHP to handle simple request • How to talk to backend data store using PHP • How to parse XML/JSON in PHP • How to generate JSON in PHP
  • 6. Getting Started • You need a local server with PHP enabled. • XAMPP for windows • MAMP for Mac OSx • Linux has it by default
  • 7. Getting Started Create a file hello.php into htdocs and call it like this http://localhost:8888/hello.php <?php $school="iit-kgp"; echo "Hello, World $school"; ?>
  • 8. • PHP blocks start with <?php and end with ?> - • Every line of PHP has to end with a semicolon ";” • Variables in PHP start with a $ • You print out content to the document in PHP with the echo command. • $school is variable and it can be printed out • You can jump in and out of PHP anywhere in the document. So if you intersperse PHP with HTML blocks, that is totally fine. For example:
  • 9. Mix Match <?php $origin = 'Outer Space'; $planet = 'Earth'; $plan = 9; $sceneryType = "awful"; ?> <h1>Synopsis</h1><p>It was a peaceful time on planet <?php echo $planet;?> and people in the <?php echo $sceneryType;?> scenery were unaware of the diabolic plan <?php echo $plan;?> from <?php echo $origin;?> that will take their senses to the edge of what can be endured.</p> demo1.php
  • 10. Displaying more complex data • You can define arrays in PHP using the array() method $lampstack = array('Linux','Apache','MySQL','PHP'); • If you simply want to display a complex datatype like this in PHP for debugging you can use the print_r() command $lampstack = array('Linux','Apache','MySQL','PHP'); print_r($lampstack); demo2.php
  • 11. Arrays <ul> <?php $lampstack = array('Linux','Apache','MySQL','PHP'); echo '<li>Operating System:'.$lampstack[0] . '</li>'; echo '<li>Server:' . $lampstack[1] . '</li>'; echo '<li>Database:' . $lampstack[2] . '</li>'; echo '<li>Language:' . $lampstack[3] . '</li>'; ?> </ul> demo3.php
  • 12. Arrays <ul> <?php $lampstack = array('Linux','Apache','MySQL','PHP'); $labels = array('OperatingSystem','Server','Database','Language'); $length = sizeof($lampstack); for( $i = 0;$i < $length;$i++ ){ echo '<li>' . $labels[$i] . ':' . $lampstack[$i] . '</li>'; } ?> </ul> sizeof($array) - this will return the size of the array demo4.php
  • 13. Associative Arrays <ul> <?php $lampstack = array( 'Operating System' => 'Linux', 'Server' => 'Apache', 'Database' => 'MySQL', 'Language' => 'PHP' ); $length = sizeof($lampstack); $keys = array_keys($lampstack); for( $i = 0;$i < $length;$i++ ){ echo '<li>' . $keys[$i] . ':' . $lampstack[$keys[$i]] . '</li>'; } ?> </ul> demo5.php
  • 14. Functions <?php function renderList($array){ if( sizeof($array) > 0 ){ echo '<ul>'; foreach( $array as $key => $item ){ echo '<li>' . $key . ':' . $item . '</li>'; } echo '</ul>'; } } $lampstack = array( 'Operating System' => 'Linux', 'Server' => 'Apache', 'Database' => 'MySQL', 'Language' => 'PHP' ); renderList($lampstack); ?> demo6.php
  • 15. Interacting with the web - URL parameters <?php $name = 'Tom'; // if there is no language defined, switch to English if( !isset($_GET['language']) ){ $welcome = 'Oh, hello there, '; } if( $_GET['language'] == 'hindi' ){ $welcome = 'Namastae, '; } switch($_GET['font']){ case 'small': $size = 80; break; case 'medium': $size = 100; break; case 'large': $size = 120; break; default: $size = 100; break; } echo '<style>body{font-size:' . $size . '%;}</style>'; echo '<h1>'.$welcome.$name.'</h1>'; ?> demo7.php
  • 16. Loading content from the web <?php // define the URL to load $url = 'http://cricket.yahoo.com/player-profile/Sachin- Tendulkar_2962'; // start cURL $ch = curl_init(); // tell cURL what the URL is curl_setopt($ch, CURLOPT_URL, $url); // tell cURL that you want the data back from that URL curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // run cURL $output = curl_exec($ch); // end the cURL call (this also cleans up memory so it is // important) curl_close($ch); // display the output echo $output; ?> demo8.php
  • 17. Displaying XML content • Demo demo9.php
  • 18. Displaying JSON content • Demo demo9.php
  • 20. Further Reference http://www.php.net/ http://developer.yahoo.com http://isithackday.com/hackday- toolbox/phpforhacks/index.html http://www.slideshare.net/tompraison