INTERNET APPLICATION DEVELOPMENT Practical on Sessions.

Slides:



Advertisements
Similar presentations
PHP SQL. Connection code:- mysql_connect("server", "username", "password"); Connect to the Database Server with the authorised user and password. Eg $connect.
Advertisements

Cookies, Sessions. Server Side Includes You can insert the content of one file into another file before the server executes it, with the require() function.
Web Database Programming Connecting Database to Web.
XAMPP: Cross – Apache, MySQL, Php, Perl + FileZilla, Tomcat NetBeans: IDE PHP Installation.
PHP and MySQL PHP for the Web, page PHP and MySQL MySQL Resource PHP – MySQL Resource
Objectives Connect to MySQL from PHP
Website Development & Management PHP Odds & Ends Instructor: John Seydel, Ph.D. CIT Fall
PHP and MySQL Web Development tMyn1 PHP and MySQL Web Development When you install PHP, you can select from a number of extensions. The MySQL support in.
Website Development Working with MySQL. What you will achieve today! Connecting to mySql Creating tables in mySql Saving data on a server using mySql.
Application Development Description and exemplification of server-side scripting language for server connection, database selection, execution of SQL queries.
What is MySQL? MySQL is a database. The data in MySQL is stored in database objects called tables. A table is a collections of related data entries and.
© Yanbu University College YANBU UNIVERSITY COLLEGE Management Science Department © Yanbu University College Module 6:WEB SERVER AND SERVER SIDE SCRPTING,
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
CS411 Database Systems Kazuhiro Minami 07: SQL System Aspects.
MySQL in PHP – Page 1 of 17CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: MySQL in PHP Reading: Williams &
Internet and Web Application Development Revision.
INTERNET APPLICATION DEVELOPMENT For More visit:
Create an online booking system (login/registration)
PC SHOP by: Hussein Zahr ECE 3553: Multifarious Final Project.
PHP MySQL Introduction
PHP – MySQL Extensions. Table used in most examples CREATE TABLE product ( rowID INT NOT NULL AUTO_INCREMENT, productid VARCHAR(8) NOT NULL, name VARCHAR(25)
INTERNET APPLICATION DEVELOPMENT PRACTICAL ON CONNECTING TO MYSQL.
PHP Tutorial - Anas Jaghoub Chapter 2 Control Structures.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
PHP Advance. Agenda Server side Includes File Handling Cookies Sessions Error/Exception handling Database handling with MySQL sending.
Website Development & Management Getting Started with Databases Instructor: John Seydel, Ph.D. CIT Fall
Accessing MySQL with PHP IDIA 618 Fall 2014 Bridget M. Blodgett.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
Introduction to MySQL Lab no. 10 Advance Database Management System.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
School of Computing and Information Systems CS 371 Web Application Programming PHP – Forms, Cookies, Sessions and Database.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
Chapter 6 PHP Interacts with Mysql Database. Introduction In PHP, there is no consolidated interface. Instead, a set of library functions are provided.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
1. Connecting database from PHP 2. Sending query 3. Fetching data 4. Persistent connections 5. Best practices.
Lecture 10 – MYSQL and PHP (Part 2)
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
Accessing Your MySQL Database from the Web with PHP (Ch 11) 1.
Database Access with PHP and MySQL CS356 Examples from Web Database Applications, by Hugh E. Williams & David Lane, O'Reilly, 2002.
ECE 3553 Final Project by Brian Robl. What is Eventor? A simple, yet effective, website for event planning and searching.  Influence from Facebook Events.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
HTML, PHP, and MySQL: Putting It All Together. Making a Form Input tags Types: “text” “radio” “checkboxes” “submit”
CISC 3140 (CIS 20.2) Design & Implementation of Software Application II Instructor : M. Meyer Address: Course Page:
Intro to DatabasesClass 4 SQL REVIEW To talk to the database, you have to use SQL SQL is used by many databases, not just MySQL. SQL stands for Structured.
Creating PHPs to Insert, Update, and Delete Data CS 320.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP & MySQL.
Retrieving data from MySQL using PHP Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
PHP Database connectivity Connecting with RDBMS and editing, adding, and deleting databases therein are all done through PHP functions.
PHP Database Processing CIS 1715 Web Technologies.
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.
Module Review Basic SQL commands: Create Database, Create Table, Insert and Select 2. Connect an SQL Database to PHP 3. Execute SQL Commands in.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
NMD202 Web Scripting Week5. What we will cover today PHP & MySQL Displaying Dynamic Pages Exercises Modifying Data PHP Exercises Assignment 1.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
MySQL. Is a SQL (Structured Query Language) database server. Can be accessed using PHP with embedded SQL Queries Supports Large DB’s, 60,000 tables with.
 Connectivity Function :-  mysql_connect ()  mysql_select_db ()  mysql_query ()  mysql_nam_rows ()  mysql_fetch_row ()  mysql_affected_rows () 
Database Access Control IST2101. Why Implementing User Authentication? Remove a lot of redundancies in duplicate inputs of database information – Your.
Chapter 8 Manipulating MySQL Databases with PHP PHP Programming with MySQL 2 nd Edition.
CHAPTER 10 PHP MySQL Database
SESSIONS 27/2/12 Lecture 8. ? Operator Similar to the if statement but returns a value derived from one of two expressions by a colon. Syntax: (expression)
CSC 405: Web Application Engineering II8.1 Web programming using PHP What have we learnt? What have we learnt? Underlying technologies of database supported.
1 PHP HTTP After this lecture, you should be able to know: How to create and process web forms with HTML and PHP. How to create and process web forms with.
PHP with MYSQL Please use speaker notes for additional information!
Tried my best to simplify it for you!
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
PHP: Login FdSc Module 109 Server side scripting and Database design
ISC440: Web Programming 2 Server-side Scripting PHP 3
Web Programming Language
MySQL Web Application Connecting to a MySQL database
Presentation transcript:

INTERNET APPLICATION DEVELOPMENT Practical on Sessions

During this session, we will write a script for logging a user to passwored protected system. We will create the appropriate tables to store users’ data permanently. We will use php session to store the information which is needed temporarily.

First, we should think about the table. Create the needed table. For example the following table would be sufficient for this situation: The above table can be created through php as follow: User_namePasswordName

<?php $con = mysql_connect("localhost","moh","1414"); if (!$con) { die('Could not connect: '. mysql_error()); } // Create database if you dont have one if (mysql_query("CREATE DATABASE se_DB",$con)) { echo "Database created"; } else { echo "Error creating database: ". mysql_error(); } mysql_select_db(« se_DB", $con); $sql = "CREATE TABLE users( user_name varchar(25), password varchar(15))"; name varchar(15), // Execute query mysql_query($sql,$con); mysql_query("INSERT INTO users(user_name, password, name) VALUES (‘ssss', ‘0000‘,’khalid’)"); mysql_close($con); ?>

After creating the table and insertting some data, we will start thinking about the web page which will allow the user to type his credential details. This could be as the following page: Note: we have used the form tag to pass the user name and password to the next page as stated in the action attribute. user name: password:

The log in web page The above page will send the user name and password to login.php web page. So,this page should check the submitted data. if the user name and password are correct, the user should be directed to the home page. <?php // getting the user name and password from the first page $usern= $_POST["fname"]; $pass= $_POST["fpass"]; $con = mysql_connect("localhost","moh","1414"); if (!$con) { die('Could not connect: '. mysql_error()); } mysql_select_db("project_DB", $con); // now we will select the rows from the table which have the same username and password $sql="SELECT * FROM users WHERE user_name='$usern' and password='$pass'"; $result=mysql_query($sql);

Note: if the user is legal user, we will create a session and store his name in the session to retreive it later from different page without connecting to the database again. // mysql_num_row is used to count the number of rows in the result $count=mysql_num_rows($result); // If result matched $myusern and $pass, the resultset must be 1 row if($count==1){ session_start(); // find the name of user from the result that you got from the database // we use the mysql_fetch_array() function to return the first row from the recordset as an array. $row = mysql_fetch_array($result); // store the name in the session array $_SESSION['full_name']=$row['name']; // create a key regitered in the session array to track the registered user later $_SESSION['registered']="yes"; // direct the user to the protected page. header("location:home.php"); } else { header("location:first.php"); } ?>

The protected page Now, we will create the protected web page. This page should check whether there is a session or not. If there is a session, it means that the user has registered in and it will display the page. If not it will direct the user to the first page to log in. Next practical, how to destroy the session and where? <?php session_start(); if(isset($_SESSION['registered'])) { echo « you are in protected page« ; } else header("location:first.php") ?>