SlideShare a Scribd company logo
PHP for hacks
                  Souri Datta
      (sourind@yahoo-inc.com)
HackU PHP and Node.js
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 you are done.
What we need to learn (for hacks)?
•   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 and Mac OS
• Linux has it by default
Getting Started



       Create a file hello.php inside htdocs and open it in browserlike
       this http://localhost/hello.php
                 <?php
                  $school="iit-b";
                  echo "Hello, World $school";
                 ?>




demo1.php
Basics
• 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




            demo2.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);
Arrays




         demo4.php
Arrays




sizeof($array) - this will return the size of the array




                                                          demo5.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>
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
ParsingXML content
• Demo




demo9.php
ParsingJSON content
• Demo




demo9.php
Talking to Mysql db
Further Reference
         http://www.php.net/
     http://developer.yahoo.com
http://www.slideshare.net/souridatta
Nods.js
• A javascript runtime environment
• Javascript is used to write client side code, but
  with node.js, server side code can be written
• Runs over cmd line
Getting started
• Download nods.js and install it
  – http://nodejs.org/
• You are ready to go!
Hello World

Create a file hello.js




From cmd line , run : node hello.js

Open in browser : http://localhost:8888/
Advantages
• Event-driven asynchronous i/o




• Callbacks are attached to i/o
  – Avoids blocking
Further reading
• http://nodejs.org/
• http://www.nodebeginner.org/
• http://code.google.com/p/v8/
Thank you!

More Related Content

PPTX
PHP for hacks
PPTX
PPTX
Phphacku iitd
PPT
Php mysql
KEY
Using PHP
PPTX
sumana_PHP_mysql_IIT_BOMBAY_2013
PPTX
PHP Basics and Demo HackU
PDF
basic concept of php(Gunikhan sonowal)
PHP for hacks
Phphacku iitd
Php mysql
Using PHP
sumana_PHP_mysql_IIT_BOMBAY_2013
PHP Basics and Demo HackU
basic concept of php(Gunikhan sonowal)

What's hot (20)

PPTX
Introduction to PHP
ODP
PHP: The easiest language to learn.
PPT
Php basic for vit university
PPT
Class 6 - PHP Web Programming
PPT
Php Lecture Notes
PDF
Introduction to PHP
PPTX
Loops PHP 04
PPT
PHP POWERPOINT SLIDES
PPT
Introduction To PHP
PPTX
Introduction to php
PPTX
Php with mysql ppt
ODP
PHP5.5 is Here
PPS
Php security3895
PDF
Introduction to PHP - Basics of PHP
PDF
07 Introduction to PHP #burningkeyboards
PPT
php $_GET / $_POST / $_SESSION
KEY
Intermediate PHP
PPT
What Is Php
 
PPT
Intro to php
Introduction to PHP
PHP: The easiest language to learn.
Php basic for vit university
Class 6 - PHP Web Programming
Php Lecture Notes
Introduction to PHP
Loops PHP 04
PHP POWERPOINT SLIDES
Introduction To PHP
Introduction to php
Php with mysql ppt
PHP5.5 is Here
Php security3895
Introduction to PHP - Basics of PHP
07 Introduction to PHP #burningkeyboards
php $_GET / $_POST / $_SESSION
Intermediate PHP
What Is Php
 
Intro to php

Similar to HackU PHP and Node.js (20)

PPTX
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
PDF
WT_PHP_PART1.pdf
PDF
UNIT4.pdf php basic programming for begginers
PPT
Prersentation
PPTX
PHP language presentation
PPT
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
PPT
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
PPT
Php i basic chapter 3
PPT
Php with my sql
PPT
Introducation to php for beginners
PPT
php 1
PPT
Intro to PHP for Students and professionals
PDF
Pecl Picks
KEY
GettingStartedWithPHP
PPTX
PHP from soup to nuts Course Deck
PDF
Lecture2_IntroductionToPHP_Spring2023.pdf
PPT
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
WT_PHP_PART1.pdf
UNIT4.pdf php basic programming for begginers
Prersentation
PHP language presentation
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3
Php with my sql
Introducation to php for beginners
php 1
Intro to PHP for Students and professionals
Pecl Picks
GettingStartedWithPHP
PHP from soup to nuts Course Deck
Lecture2_IntroductionToPHP_Spring2023.pdf

Recently uploaded (20)

PDF
KodekX | Application Modernization Development
PDF
Electronic commerce courselecture one. Pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Modernizing your data center with Dell and AMD
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
KodekX | Application Modernization Development
Electronic commerce courselecture one. Pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Per capita expenditure prediction using model stacking based on satellite ima...
20250228 LYD VKU AI Blended-Learning.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
Empathic Computing: Creating Shared Understanding
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
NewMind AI Weekly Chronicles - August'25 Week I
Dropbox Q2 2025 Financial Results & Investor Presentation
Understanding_Digital_Forensics_Presentation.pptx
Unlocking AI with Model Context Protocol (MCP)
The AUB Centre for AI in Media Proposal.docx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
GamePlan Trading System Review: Professional Trader's Honest Take
Advanced methodologies resolving dimensionality complications for autism neur...
Modernizing your data center with Dell and AMD
Mobile App Security Testing_ A Comprehensive Guide.pdf

HackU PHP and Node.js

  • 3. 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 you are done.
  • 4. What we need to learn (for hacks)? • 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
  • 5. Getting Started • You need a local server with PHP enabled. • XAMPP for windows and Mac OS • Linux has it by default
  • 6. Getting Started Create a file hello.php inside htdocs and open it in browserlike this http://localhost/hello.php <?php $school="iit-b"; echo "Hello, World $school"; ?> demo1.php
  • 7. Basics • 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:
  • 8. Mix Match demo2.php
  • 9. 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);
  • 10. Arrays demo4.php
  • 11. Arrays sizeof($array) - this will return the size of the array demo5.php
  • 12. 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>
  • 13. 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
  • 14. 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
  • 15. 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
  • 19. Further Reference http://www.php.net/ http://developer.yahoo.com http://www.slideshare.net/souridatta
  • 20. Nods.js • A javascript runtime environment • Javascript is used to write client side code, but with node.js, server side code can be written • Runs over cmd line
  • 21. Getting started • Download nods.js and install it – http://nodejs.org/ • You are ready to go!
  • 22. Hello World Create a file hello.js From cmd line , run : node hello.js Open in browser : http://localhost:8888/
  • 23. Advantages • Event-driven asynchronous i/o • Callbacks are attached to i/o – Avoids blocking
  • 24. Further reading • http://nodejs.org/ • http://www.nodebeginner.org/ • http://code.google.com/p/v8/