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
Tom Praison Praison
 
PPTX
Php hacku
Tom Praison Praison
 
PPTX
Phphacku iitd
Sorabh Jain
 
PPT
Php mysql
Manish Jain
 
KEY
Using PHP
Mark Casias
 
PPTX
sumana_PHP_mysql_IIT_BOMBAY_2013
Sumana Hariharan
 
PPTX
PHP Basics and Demo HackU
Anshu Prateek
 
PDF
basic concept of php(Gunikhan sonowal)
Guni Sonow
 
PHP for hacks
Tom Praison Praison
 
Phphacku iitd
Sorabh Jain
 
Php mysql
Manish Jain
 
Using PHP
Mark Casias
 
sumana_PHP_mysql_IIT_BOMBAY_2013
Sumana Hariharan
 
PHP Basics and Demo HackU
Anshu Prateek
 
basic concept of php(Gunikhan sonowal)
Guni Sonow
 

What's hot (20)

PPTX
Introduction to PHP
Collaboration Technologies
 
ODP
PHP: The easiest language to learn.
Binny V A
 
PPT
Php basic for vit university
Mandakini Kumari
 
PPT
Class 6 - PHP Web Programming
Ahmed Swilam
 
PPT
Php Lecture Notes
Santhiya Grace
 
PDF
Introduction to PHP
Bradley Holt
 
PPTX
Loops PHP 04
mohamedsaad24
 
PPT
PHP POWERPOINT SLIDES
Ismail Mukiibi
 
PPT
Introduction To PHP
Shweta A
 
PPTX
Introduction to php
Taha Malampatti
 
PPTX
Php with mysql ppt
Rajamanickam Gomathijayam
 
ODP
PHP5.5 is Here
julien pauli
 
PPS
Php security3895
PrinceGuru MS
 
PDF
Introduction to PHP - Basics of PHP
wahidullah mudaser
 
PDF
07 Introduction to PHP #burningkeyboards
Denis Ristic
 
PPT
php $_GET / $_POST / $_SESSION
tumetr1
 
KEY
Intermediate PHP
Bradley Holt
 
PPT
What Is Php
AVC
 
PPT
Intro to php
Sp Singh
 
Introduction to PHP
Collaboration Technologies
 
PHP: The easiest language to learn.
Binny V A
 
Php basic for vit university
Mandakini Kumari
 
Class 6 - PHP Web Programming
Ahmed Swilam
 
Php Lecture Notes
Santhiya Grace
 
Introduction to PHP
Bradley Holt
 
Loops PHP 04
mohamedsaad24
 
PHP POWERPOINT SLIDES
Ismail Mukiibi
 
Introduction To PHP
Shweta A
 
Introduction to php
Taha Malampatti
 
Php with mysql ppt
Rajamanickam Gomathijayam
 
PHP5.5 is Here
julien pauli
 
Php security3895
PrinceGuru MS
 
Introduction to PHP - Basics of PHP
wahidullah mudaser
 
07 Introduction to PHP #burningkeyboards
Denis Ristic
 
php $_GET / $_POST / $_SESSION
tumetr1
 
Intermediate PHP
Bradley Holt
 
What Is Php
AVC
 
Intro to php
Sp Singh
 

Similar to HackU PHP and Node.js (20)

PDF
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
PDF
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
PPTX
PHP Hypertext Preprocessor
adeel990
 
PPT
Synapseindia reviews on array php
saritasingh19866
 
PPT
PHP
sometech
 
PPT
PHP - Introduction to PHP Fundamentals
Vibrant Technologies & Computers
 
PDF
Lecture8
Majid Taghiloo
 
PPTX
PHP ITCS 323
Sleepy Head
 
PPTX
PHP language presentation
Annujj Agrawaal
 
PPTX
Server – side Technologies PHP for web dev.pptx
MarioCaday2
 
PPTX
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
DRambabu3
 
PPT
Php classes in mumbai
Vibrant Technologies & Computers
 
PPTX
Day1
IRWAA LLC
 
PPT
05php
anshkhurana01
 
PPT
Synapseindia reviews sharing intro on php
SynapseindiaComplaints
 
PPT
Synapseindia reviews sharing intro on php
SynapseindiaComplaints
 
PPT
rtwerewr
esolinhighered
 
PPT
php 1
tumetr1
 
PDF
Phpbasics
PrinceGuru MS
 
PPTX
PHP from soup to nuts Course Deck
rICh morrow
 
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
PHP Hypertext Preprocessor
adeel990
 
Synapseindia reviews on array php
saritasingh19866
 
PHP - Introduction to PHP Fundamentals
Vibrant Technologies & Computers
 
Lecture8
Majid Taghiloo
 
PHP ITCS 323
Sleepy Head
 
PHP language presentation
Annujj Agrawaal
 
Server – side Technologies PHP for web dev.pptx
MarioCaday2
 
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
DRambabu3
 
Php classes in mumbai
Vibrant Technologies & Computers
 
Day1
IRWAA LLC
 
Synapseindia reviews sharing intro on php
SynapseindiaComplaints
 
Synapseindia reviews sharing intro on php
SynapseindiaComplaints
 
rtwerewr
esolinhighered
 
php 1
tumetr1
 
Phpbasics
PrinceGuru MS
 
PHP from soup to nuts Course Deck
rICh morrow
 

Recently uploaded (20)

PPTX
Coupa-Overview _Assumptions presentation
annapureddyn
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
This slide provides an overview Technology
mineshkharadi333
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PDF
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PDF
Best ERP System for Manufacturing in India | Elite Mindz
Elite Mindz
 
PDF
Software Development Company | KodekX
KodekX
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PPTX
Smart Infrastructure and Automation through IoT Sensors
Rejig Digital
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
Coupa-Overview _Assumptions presentation
annapureddyn
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
This slide provides an overview Technology
mineshkharadi333
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Best ERP System for Manufacturing in India | Elite Mindz
Elite Mindz
 
Software Development Company | KodekX
KodekX
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
Smart Infrastructure and Automation through IoT Sensors
Rejig Digital
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 

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/