Thursday, March 14, 2019

CS75 Lecture #8 Part-1 Security

CS75 Lecture #8 Part-1 Security



Course Web Site by CS75.tv
Lecture 0: HTTP
Lecture 1: PHP
Lecture 2: PHP, Continued
Lecture 3: MVC, XML
Lecture 4: SQL
Lecture 5: SQL, Continued
Lecture 6: JavaScript
Lecture 7: Ajax
Lecture 9: Scalability



Friday, March 1, 2019

Object Oriented PHP (OOP) Part-1



Object Oriented PHP (OOP) Part-1

1: Introduction To Object Oriented PHP Programming 
2: Simple Explanation Of The MVC Model
3: Create Classes In Object Oriented PHP 
4: What Are Scopes In Object Oriented PHP Programming
5: Properties And Methods In Object Oriented PHP
6: MAGIC METHODS - Construct And Deconstruct Methods
7: Delete Objects In Object Oriented PHP
8: How To Use The toString Method
9: Static Properties And Methods In Object Oriented PHP
10: Initialise Object Properties In Object Oriented PHP - How to pass a parameter in a Constructor method inside a class
11: Our First Exercise Using Object Oriented PHP, Basic Calculator
12: Connect To A Database Using MySQLi 
13: How To Connect To A Database Using PDO PHP 
14: How To Query A Database Using PDO PHP

_____VID #1_____________________

Basic template for index.php



<?php
 include 'includes/php program file 1;
include 'includes/php program file 2;
?>
<!DOCTYPE html>
<html>
<head>
   <title></title>
</head>
<body>

<?php
/*
  * PHP Code Here *
*/
?>
</body>

</html>

</!DOCTYPE>

_____VID #1_____________________

1: Object Oriented PHP

====Filename ======================
index.php
===================================

<!---
/* Youtube Video https://youtu.be/w8jVNr-dDlM
* 5: Properties And Methods In Object Oriented 
* PHP Programming | 
* OOP PHP Tutorial | Learn OOP PHP
*/
--->

<?php
 include 'includes/parentclass1.inc.php';
include 'includes/newclass1.inc.php';
$object = new NewClass;
?>
<!DOCTYPE html>
<html>
<head>
   <title></title>
</head>
<body>

<?php
   echo $object ->name();
/*
* If an object $object points to a variable, like name,
* echo $object ->name; 
* the program will fail.
*/

?>
</body>

</html>

</!DOCTYPE>

====================================



====Filename ======================
includes/parentclass1.inc.php
===================================
<?php 

class ParentClass{


   //Properties and Methods go here

   public $name = "Hey there!";
}

?>


====Filename ======================
includes/newclass1.inc.php
===================================
<?php 

class NewClass extends ParentClass {

   //Properties and Methods go here
      public function name(){
  return $this -> name;
  }
}

?>



_____VID #2_____________________


Simple Explanation Of The MVC Model








_____VID #2_____________________




_____VID #3_____________________


3: Create Classes In Object Oriented PHP










_____VID #3_____________________



_____VID #4_____________________

4: What Are Scopes In Object Oriented PHP Programming




_____VID #4_____________________


_____VID #5_____________________



<!-------------------------------------------
/* Youtube Video https://youtu.be/w8jVNr-dDlM
*                     VID Lec#5
*                     index5.php
* PHP Programming|OOP PHP Tutorial | Learn OOP PHP */
-------------------------------------------->
<?php
include 'includes/newclass5.inc.php';
?>

<!DOCTYPE html>
<html>
<head>
   <title></title>
</head>
<body>
<?php
    $object = new NewClass;
    $object2 = new NewClass;
/*
* Want to access a property inside an object.
*/
     $object->setNewProperty("This is a user Daniel.");
     echo $object->getProperty()."<br>";
 
     $object2->setNewProperty("This is a user called Jon.");
     echo $object2->getProperty()."<br>";  
?>
</body>

</html>



</!DOCTYPE>

<!-------------------------------------------

*                     newclass5.inc.php
* PHP Programming|OOP PHP Tutorial | Learn OOP PHP */
-------------------------------------------->

<?php 


class NewClass {


   //Properties and Methods go here

      public $data = "I am a property";
  
  public function setNewProperty($newdata){
      $this->data = $newdata;
  
  }
  public function getProperty(){
     return $this->data;
  } 
}


?>


_____VID #6_____________________

6: MAGIC METHODS - Construct And Deconstruct Methods

<!-------------------------------------------
/* Youtube Video https://youtu.be/w8jVNr-dDlM
*                     VID Lec#6
*                     index6.php
* PHP Programming|OOP PHP Tutorial | Learn OOP PHP */
-------------------------------------------->
<?php
include 'includes/newclass6.inc.php';
?>

<!DOCTYPE html>
<html>
<head>
   <title></title>
</head>
<body>
<?php
    $object = new NewClass;
$object2 = new NewClass;
/* Want to access a property inside an object.*/
     echo $object->getProperty()."<br>";
 

?>
</body>

</html>



</!DOCTYPE>

<!-------------------------------------------

*                     newclass6.inc.php
* PHP Programming|OOP PHP Tutorial | Learn OOP PHP */
-------------------------------------------->

<?php 


class NewClass {


   //Properties and Methods go here

      public $data = "I am a property";
  
  public function __construct(){
    echo "This class has been instantiated."."<br>";
  }
  public function setNewProperty($newdata){
      $this->data = $newdata;
  }
  public function getProperty(){
     return $this->data;
  }
  public function __destruct(){
     echo "This is the end of the class!"."<br>";
  }
}



?>




_____VID #7_____________________


7: Delete Objects In Object Oriented PHP

<!-------------------------------------------
/* Youtube Video https://youtu.be/w8jVNr-dDlM
*                     VID Lec#7
*                     index7.php
* PHP Programming|OOP PHP Tutorial | Learn OOP PHP */
-------------------------------------------->
<?php
include 'includes/newclass7.inc.php';
?>

<!DOCTYPE html>
<html>
<head>
   <title></title>
</head>
<body>
<?php
    $object = new NewClass;
     unset($object);
     echo $object->getProperty()."<br>";

?>

</body>
</html>

</!DOCTYPE>


<!-------------------------------------------

*                     newclass7.inc.php
* PHP Programming|OOP PHP Tutorial | Learn OOP PHP */
-------------------------------------------->
<?php 

class NewClass {


   //Properties and Methods go here

      public $data = "I am a property";
  
  public function __construct(){
    echo "This class has been instantiated."."<br>";
  }
  public function setNewProperty($newdata){
      $this->data = $newdata;
  }
  public function getProperty(){
     return $this->data;
  }
  public function __destruct(){
     echo "This is the end of the class!"."<br>";
  }
}




?>


_____VID #8_____________________

8: How To Use The toString Method

<!-------------------------------------------
/* Youtube Video https://youtu.be/w8jVNr-dDlM
*                     VID Lec#8
*                     index8.php
* PHP Programming|OOP PHP Tutorial | Learn OOP PHP */
-------------------------------------------->
<?php
include 'includes/newclass8.inc.php';
?>

<!DOCTYPE html>
<html>
<head>
   <title></title>
</head>
<body>
<?php
    $object = new NewClass;
     echo $object."<br>";

?>

</body>
</html>

</!DOCTYPE>
<!-------------------------------------------
*                     newclass8.inc.php
* PHP Programming|OOP PHP Tutorial | Learn OOP PHP */
-------------------------------------------->
<?php 

class NewClass {

   //Properties and Methods go here
      public $data = "I am a property";
  public $error = "This is a class called.. ".__CLASS__."..!";
  
  public function __construct(){
    echo "This class has been instantiated."."<br>";
  }
  public function __toString(){
    echo "toString Method:";
return $this->error;
  }
  public function setNewProperty($newdata){
      $this->data = $newdata;
  }
  public function getProperty(){
     return $this->data;
  } 
  public function __destruct(){
     echo "This is the end of the class!"."<br>";
  }
}


?>


_____VID #9____________________

9: Static Properties And Methods In Object Oriented PHP_

<!-------------------------------------------
/* Youtube Video https://youtu.be/w8jVNr-dDlM
*                     VID Lec#9
*                     index9.php
* PHP Programming|OOP PHP Tutorial | Learn OOP PHP */
-------------------------------------------->
<?php
include 'includes/newclass9.inc.php';
?>

<!DOCTYPE html>
<html>
<head>
   <title></title>
</head>
<body>
<?php
   echo NewClass::staticMethod();
   
?>
</body>
</html>
</!DOCTYPE>

<!-------------------------------------------

*                     newclass9.inc.php
* PHP Programming|OOP PHP Tutorial | Learn OOP PHP */
-------------------------------------------->
<?php 

class NewClass {

   //Properties and Methods go here
      public $data = "I am a property";
  public $error = "This is a class called.. ".__CLASS__."..!";
  public static $static = 0;
  
  public function __construct(){
    echo "This class has been instantiated."."<br>";
  }
  public function __toString(){
    echo "toString Method:";
return $this->error;
  }
  public static function staticMethod(){
    return self::$static + 2;
  }
  public function setNewProperty($newdata){
      $this->data = $newdata;
  }
  public function getProperty(){
     return $this->data;
  } 
  public function __destruct(){
     echo "This is the end of the class!"."<br>";
  }
}


?>


_____VID #10____________________

10: Initialise Object Properties In Object Oriented PHP

How to pass a parameter in a Constructor method inside a class_

<!-------------------------------------------
/* Youtube Video https://youtu.be/w8jVNr-dDlM
*                     VID Lec#10
* PHP Programming|OOP PHP Tutorial | Learn OOP PHP */
-------------------------------------------->
<?php
include 'includes/newclass10.inc.php';
?>

<!DOCTYPE html>
<html>
<head>
   <title></title>
</head>
<body>
<?php
   $users = new Users('john','Doe','Blond','Brown');
   echo "Fullname: ".$users ->fullname().'<br>';
   echo "Profile".$users ->profile();
   
?>
</body>
</html>
</!DOCTYPE>
<!-------------------------------------------
*                     newclass10.inc.php
* PHP Programming|OOP PHP Tutorial | Learn OOP PHP */

-------------------------------------------->
<?php 

class Users {

   //Properties and Methods go here
  public $first;
  public $last;
  public $hairColor;
  public $eyeColor;
  
  public function __construct($first, $last, $hairColor,
  $eyeColor){
      $this->first = $first;
  $this->last = $last;
  $this->hairColor = $hairColor;
  $this->eyeColor = $eyeColor;
  }
  public function fullname(){
     return $this->first. " ".$this->last;
  }
  public function profile(){
     return $this->hairColor." and ".$this->eyeColor;
  }
  
  public function __destruct(){
  
  }
}


?>
==========================
output
==========================

Fullname: john Doe
ProfileBlond and Brown

==========================



 

MIT 6.00 コンピュータサイエンスとプログラミング秋期講座第2回

  MIT 6.00 コンピュータサイエンスとプログラミング秋期講座第2回 オープンコースウエア 大学名:MIT 講座名:6.00 Introduction to Computer Science and Programming Download course material ...