SIMPLE ROUTER The slide made by Salim Malakouti. Next we will create the Router  What do I we mean by a router?  Routers work similar to a map. It receives.

Slides:



Advertisements
Similar presentations
PHP Form and File Handling
Advertisements

11 Getting Started with ASP.NET Beginning ASP.NET 4.0 in C# 2010 Chapters 5 and 6.
Dan Fleck.  WAMP – Windows Apache MySQL PHP -  LAMP – Linux Apache MySQL PHP ◦ There are.
Michelle J. Gosselin, Jennifer Schommer Guanzhong Wang.
Server-Side vs. Client-Side Scripting Languages
CS 290C: Formal Models for Web Software Lecture 10: Language Based Modeling and Analysis of Navigation Errors Instructor: Tevfik Bultan.
Creating WordPress Websites. Creating a site on your computer Local server Local WordPress installation Setting Up Dreamweaver.
Chapter Apache Installation in Linux- Mandrake. Acknowledgment The following information has been obtained directly from
Python and Web Programming
Website Development with PHP and MySQL Introduction.
1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)
 What I hate about you things people often do that hurt their Web site’s chances with search engines.
Installing and Configuring Tomcat A quick guide to getting things set up on Windows.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
ITM © Port, Kazman1 ITM 352 HTML Forms, Basic Form Processing.
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
ACM Web Development Workshop - PHP By Luis Torres.
JavaScript & jQuery the missing manual Chapter 11
PHP Hypertext PreProcessor. Documentation Available SAMS books O’Reilly Books.
Server-side Scripting Powering the webs favourite services.
The Art of Debugging Shlomy Gantz 02/13/01MDCFUG.
CSCI 6962: Server-side Design and Programming Validation Tools in Java Server Faces.
Guidelines for Homework 6. Getting Started Homework 6 requires that you complete Homework 5. –All of HW5 must run on the GridFarm. –HW6 may run elsewhere.
SNORT Tutorial Sreekanth Malladi (modifying original by N. Youngworth)
Set 13: Web Servers (configuration and security) (Chapter 21) IT452 Advanced Web and Internet Systems.
20-753: Fundamentals of Web Programming 1 Lecture 1: Introduction Fundamentals of Web Programming Lecture 1: Introduction.
Apache and... Virtual Hosts ---- aliases mod_rewrite ---- htaccess AFNOG 11 Kigali, Rwanda May 2010 Dorcas Muthoni Courtesy: Hervey Allen.
Chapter 3 Servlet Basics. 1.Recall the Servlet Role 2.Basic Servlet Structure 3.A simple servlet that generates plain text 4.A servlet that generates.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Forms and Server Side Includes. What are Forms? Forms are used to get user input We’ve all used them before. For example, ever had to sign up for courses.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
1 Apache and... Virtual Hosts ---- aliases mod_rewrite ---- htaccess AFNOG X Cairo, Egypt May 2009 Hervey Allen.
Sessions, Cookies, &.htaccess IT 210. Procedural Issues  Quiz #3 Today!  Homework #3 Due Friday at midnight UML for Lab 4  Withdraw Deadline is Wed,
.htaccess Apache server directives BTM 395: Internet Programming.
ASP (Active Server Pages) by Bülent & Resul. Presentation Outline Introduction What is an ASP file? How does ASP work? What can ASP do? Differences Between.
Controlling Web Site Access Using Logins CS 320. Basic Approach HTML form a php page that collects the username and password  Sends them to second PHP.
 Registry itself is easy and straightforward in implementation  The objects of registry are actually complicated to store and manage  Objects of Registry.
Configuring and Troubleshooting Identity and Access Solutions with Windows Server® 2008 Active Directory®
PHP Error Handling & Reporting. Error Handling Never allow a default error message or error number returned by the mysql_error() and mysql_errno() functions.
Security Issues with PHP  PHP installation  PHP programming Willa Zhu & Eugene Burger.
| imodules.com Top 10 FAQ in Application Support Kelly Schmiedeler & Amber Quayle.
CSC 405: Web Application Engineering II8.1 Web programming using PHP What have we learnt? What have we learnt? Underlying technologies of database supported.
Chap 2 – Getting Started COMP YL Professor Mattos.
Basic ActionScript and PHP Cis 126. Getting Started set up a basic folder structure so we can keep our files organized. Mirror this structure on your.
Servers- Apache Tomcat Server Server-side scripts- Java Server Pages.
Web Server Apache PHP HTTP Request User types URL into browser Address resolved if nec. We use directly Most browsers request.
ASSIGNMENT 2 Salim Malakouti. Ticketing Website  User submits tickets  Admins answer tickets or take appropriate actions.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
Web Services Essentials. What is a web service? web service: software functionality that can be invoked through the internet using common protocols like.
Cool CF Debugging Shlomy Gantz 07/29/01CF_ODYSSEY.
Building Your Own Website Using:. Install & configure LAMP. Download WordPress and run it as a local website on your Raspberry Pi. Configure WordPress.
Apache Web Server v. 2.2 Reference Manual Chapter 2 Starting Apache.
SlideSet #20: Input Validation and Cross-site Scripting Attacks (XSS) SY306 Web and Databases for Cyber Operations.
Apache and... Virtual Hosts ---- aliases mod_rewrite ---- htaccess
Redirection Allow requests to be moved about your file system or around the web ScriptAlias Allows you to run CGI scripts Simple to use.
Authentication & .htaccess
Enhanced Web Site Design Stanford University Continuing Studies CS 22
Unix System Administration
Introduction to MVC PHP Web Development Ivan Yonkov Training Manager
MapServer In its most basic form, MapServer is a CGI program that sits inactive on your Web server. When a request is sent to MapServer, it uses.
Intro to PHP & Variables
Cookies BIS1523 – Lecture 23.
Web Browser server client 3-Tier Architecture Apache web server PHP
Conditions and Ifs BIS1523 – Lecture 8.
Building Web Applications
In Class Programming BIS1523 – Lecture 11.
Lecture 5: Functions and Parameters
Client-Server Model: Requesting a Web Page
SHELLSHOCK ATTACK.
Presentation transcript:

SIMPLE ROUTER The slide made by Salim Malakouti

Next we will create the Router  What do I we mean by a router?  Routers work similar to a map. It receives the URL user is requesting and allocates the PHP|JSP|RUBY|etc file that is needed to process that request  Why? We will hide the structure of our code Simplicity: user doesn’t have to use odd long URL like pages/birthday.php Security: We don’t want the hackers to know the structure of our code Users don’t have to know the file extensions that we are using Less confusing and more secure (we don’t want the hackers to know the technology that we are using) Etc.

How to do it?  Lets go back to our own example  We want to create a router file which here will be “index.php” that will receive all requests and invoke the required php file for it?  What do you think is the first step required here?

.htaccess  We need to redirect everything to “index.php” even if they are requesting something else.  How? PHP can’t be used for that We use.htaccess file processed by Apache Server

Creating.htaccess file  Create a.htaccess file in the root directory of your project with the following content # Turn rewriting on RewriteEngine On RewriteCond %{REQUEST_URI} !=/example1/index.php RewriteRule.* /example1/index.php

What does this do? # Turn rewriting on RewriteEngine On Turns on the RewriteEngine RewriteCond %{REQUEST_URI} !=/example1/index.php We will rewrite every request except ”example1/index.php” since we want to avoid recursive redirections RewriteRule.* /example1/index.php We will change everything to “/example1/index.php”

Alternative – Use [END] Flag # Turn rewriting on RewriteEngine On Turns on the RewriteEngine RewriteRule.* /example1/index.php [END] The [END] flag will now prevent all recursive redirections without having to specify RewriteCond

Creating the router  Check $_SERVER varaible using the following command and see the content  print_r($_SERVER);  How can you use these information to find which request is sent to “index.php” and which file to invoke for it?

REDIRECT_URL  Use $_SERVER['REDIRECT_URL'] and check which page has been requested  Use conditions  How to invoke the proper php file for the request?  Use include

In Class Exercise  In this exercise, we will use.htaccess files and Apache web server URL rewriting to implement a "router" for PHP files in a directory. This improves security since only files permitted by the router can be executed. The URL rewriting engine uses PCRE regular expressions that we discussed in class.

In Class Exercise  1. Try the ex16.php code example that uses redirection to display one of choice1.php, choice2.php, and choice3.php.  2. Create a new directory and copy over the files choice1.php, choice2.php, and choice3.php.  3. Write a.htaccess file that rewrites all URLs to be replaced with "index.php". Use RewriteCond to prevent recursive redirections.

In Class Exercise  4. Write the index.php script that acts as a router for the other PHP scripts.  The router should map /1" to " /choice1.php" and the same for choice2.php and choice3.php.  Inside index.php, use preg_match to match $_SERVER['REDIRECT_URL'] against one of the three allowed URLs.  Include the appropriate PHP script on a match.  Note that redirecting the browser as in the case of redirect.php will not work since that will generate a new request to choice1.php which will be rejected by the router.  If the match fails, index.php should print "Error: Invalid Request!!!".  5. Demonstrate your site to the TA

In Class Exercise  Extra Credit (double credit if completed)  Implement the above functionality just using a.htaccess file and regular expressions and no index.php. Refer to the following URLs for hints on how to construct the regular expression  /httpd.apache.org/docs/2.0/misc/rewriteguide.html /httpd.apache.org/docs/2.0/misc/rewriteguide.html  Use the [END] flag to prevent recursions more conveniently.  Hint  for easier debugging of the regular expressions, add the line "LogLevel alert rewrite:trace3" to "xamppfiles/etc/httpd.conf" and restart the web server.  This will allow debug log to be output in "xamppfiles/logs/error_log" for each page access.