Dhananjay Kuber

Day 4 at rtCamp

Web Basics

DNS (Domain Name Server)

DNS used to map human redable address to IP address. It consist of following 4 servers.

  • DNS Recursor: DNS Recursor receives the query or request from the client. It will first check the requested website found in cache, if found it will send IP from the cache
  • Root Nameserver: Root Nameserver receives the request from DNS Recursor and send it to TLD Nameserver
  • TLD Nameserver: TLD Nameserver contain all the information of website which has same Top Level Domain (eg. .com, .in) and forward request to Authorative Nameserver
  • Authorative Nameserver: Authorative Nameserver contain mapping of domain name to its corresponding IP address. The IP address is then forwarded to the DNS Recursor

DNS

/etc/hosts

  • /etc/hosts file manual maps hostnames to IP addresses on a local machine
  • We can edit this file to add custom hostname and IP as needed
  • It can be used in Local Development as well as Blocking websites on local machine
  • Local Development
    127.0.0.1 dhananjay.example.com
  • Block Website
    0.0.0.0 www.examplewebsite.com
  • In above example www.examplewebsite.com can be redirected to invalid or local IP address

HTTP & HTTPS

HTTP & HTTPS are two way of communication over World Wide Web. It is an application layer protocol which is used to transefer text, image, audio, video etc over internet

HTTP (Hyper Text Transfer Protocol)

  • HTTP operates over plain text
  • Data transfered using HTTP can easily eavdroped and it is susceptible to Man In Middle attack
  • URL format for HTTP is http://

HTTPS (Hyper Text Transfer Protocol Secure)

  • HTTPS add extra layer of security and excryption while transfering data over internet
  • Data transfer is secured by the SSL or TLS
  • SSL and TLS certificates provides the authenticity of server to client
  • URL format for HTTPS is https://

HSTS (HTTP Strict Transport Security)

  • HSTS mechanism protects communication from Man In Middle attack
  • If broswer sends the HSTS header it converts the insecure request to secure HTTPS request

Rendering Engine

Rendering Engine refers to mechanism which transform the HTML & CSS to what we can see of the web page. There are different Rendering Engine used by different web broswers like Blink, Webkit etc. Following steps are used to render web page on the broswer

  • Parse HTML: HTML is parsed and DOM (Document Object Model) is created
  • Parse CSS: CSS is parsed and CSSOM (CSS Object Model) is created
  • Render Tree: Combine DOM and CSSOM and determine how element should look and positioned
  • Layout Flow: Determine size and location of element on web page
  • Painting: Render acutual pixel on the screen

Email

Email uses following protocols to send and receive the mail over internet

  • SMPT

  • IMAP or POP3

  • SMTP: Simple Mail Transfer Protocol is used to send email to email server

  • IMAP: Internet Management Access Protocol used to receive the email from server

  • POP3: Post Office Protocol is similar to IMAP but is download all email from server and delete from server

Email

Rsync & SSH

Rsync

  • rsync is command line utility which is used to sync the local file system to remote file system
  • rsync will only copy the changed file rather than copying all the file
  • eg rsync1 rsync1
  • In above we have created 100 file in dir1 rsync1
  • rsync -a dir1/ dir2 command is used to sync dir1 and dir2
  • Following flags can be used with rsync
    • -a: archieve preserve all file permissions, ownership
    • -v: verbose give detiled information about file transfer
    • -z: compress file during transfer
    • -p: preserve file permissions on destination

SSH (Secure Shell)

  • SSH stand for Secure Shell is used to connect with remote machine
  • When we connect with remote server using SSH a Shell Session is created which is purely text based interface
  • We can connect server using key pair
  • Key pair can be generated using sshkey-gen command
  • sshkey-gen will generate two keys public & private
  • We copy public key to server and keep private key on local machine
  • ssh-copy-id root@servername.com
  • After this secure connection is established with remote server
  • scp (secure copy) command can also be used to copy file to remote server scp filename.txt remoteserver.com/foldername

PHP String functions

  • strlen: count the length of string
  • strpos: strpos("Hello all", "all") return the position of "all" in string
  • strtoupper: convert string to uppercase
  • strtolower: convert string to lowercase
  • str_replace: str_replace("previous_word", "new_word", actual_string)
  • strrev: reverse string
  • trim: remove extra spaces before and after the string
  • explode: split the string to array eg. explode(' ', $str)

Variadic Function

Variadic function is function which take variable number of arguments

function myFunction(...$args) {
        
}

Strict Type Declaration

  • In php we can use strict_type to enable strict type checking
declare(strict_type=1);

function myFunction(int $num1, int $num2): int {
    return num1+num2;
}

Superglobal

  • In PHP Superglobals are special type of variable while are accessble throughout the execution of script. Following are some of the Superglobals in php
  • $GLOBAL: It allow us to access global variables
  • $_SERVER: It contains server related information like host, current file etc
  • $REQUEST: It used to collect form data & cookies
  • $_GET: It contains data send to script via GET method
  • $_POST: It contains data send to script via POST method
  • $_FILE: It provides the information about file uploaded via POST
  • $_COOKIE: It contain data send via cookie
  • $_SESSION: It contain session variables which are accessible accross the website