CIS 388 Internet Programming

Slides:



Advertisements
Similar presentations
PHP II Interacting with Database Data. The whole idea of a database-driven website is to enable the content of the site to reside in a database, and to.
Advertisements

PHP SQL. Connection code:- mysql_connect("server", "username", "password"); Connect to the Database Server with the authorised user and password. Eg $connect.
PHP and MySQL Database. Connecting to MySQL Note: you need to make sure that you have MySQL software properly installed on your computer before you attempt.
© Yanbu University College YANBU UNIVERSITY COLLEGE Management Science Department © Yanbu University College Module 6:WEB SERVER AND SERVER SIDE SCRPTING,
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
Website Security ISYS 475. Authentication Authentication is the process that determines the identity of a user.
Create an online booking system (login/registration)
Introduction to MySQL Lab no. 10 Advance Database Management System.
School of Computing and Information Systems CS 371 Web Application Programming PHP – Forms, Cookies, Sessions and Database.
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.
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.
COOKIES and SESSIONS. COOKIES A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each.
Cookies and Sessions IDIA 618 Fall 2014 Bridget M. Blodgett.
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.
Creating A Database Driven Website 1.Setting Up Your Web Server 2.Creating a Database 3.Creating a Webpage to Display Information From a Database 4.Creating.
NMD202 Web Scripting Week5. What we will cover today PHP & MySQL Displaying Dynamic Pages Exercises Modifying Data PHP Exercises Assignment 1.
PHP: MySQL. PHP Connect to MySQL PHP 5 and later can work with a MySQL database using: – MySQLi extension (the "i" stands for improved) – PDO (PHP Data.
PHP Database Pemrograman Internet. PHP MySQL Database With PHP, you can connect to and manipulate databases. MySQL is the most popular database system.
CHAPTER 8 PHP Advanced อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
CHAPTER 10 PHP MySQL Database
 A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests.
MySQL MySQL and PHP – interacting with a database.
INLS 623 – D ATABASE A PPLICATION D EVELOPMENT AND I NTERNET A PPLICATIONS Instructor: Jason Carter.
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.
Web Page Designing With Dreamweaver MX\Session 1\1 of 9 Session 3 PHP Advanced.
Cookies and Sessions in PHP. Arguments for the setcookie() Function There are several arguments you can use i.e. setcookie(‘name’, ‘value’, expiration,
Unit-6 Handling Sessions and Cookies. Concept of Session Session values are store in server side not in user’s machine. A session is available as long.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
PHP and MySQL Session 4: Advanced PHP Izzy
Week 7 Server side programming PHP Scripting Language MySQL Database Apache Server IT4103 Web Programming
Web Systems & Technologies
PHP Built-In Functions
PHP: MySQL Lecture 14 Kanida Sinmai
CIS 388 Internet Programming
CHAPTER 5 SERVER SIDE SCRIPTING
Introduction to Dynamic Web Programming
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Paul Jacobs The iSchool University of Maryland Thursday, Oct. 13, 2016
CGS 3066: Web Programming and Design Spring 2016
IS1500: Introduction to Web Development
PHP: Login FdSc Module 109 Server side scripting and Database design
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
19.10 Using Cookies A cookie is a piece of information that’s stored by a server in a text file on a client’s computer to maintain information about.
Web Design and Development
Server-Side Application and Data Management IT IS 3105 (FALL 2009)
Web Design and Development
Introduction to Web programming
Web Programming Language
Cookies and Sessions in PHP
PHP Overview PHP: Hypertext Preprocessor Server-Side Scripting
MySQL tutorial.
Introduction to Web programming
Ch. 3. PHP (이 강의 내용의 대부분 예들은 w3schools. com/php/default
ISC440: Web Programming 2 Server-side Scripting PHP 3
Introduction to Web programming
<?php require("header.htm"); ?>
MySQL Web Application Connecting to a MySQL database
Software Engineering for Internet Applications
PHP Hüseyin GÜNEŞ, 2018.
Paul Jacobs The iSchool University of Maryland Thursday, Oct. 12, 2017
Web Programming Language
Tutorial 6 PHP & MySQL Li Xu
MySQL Web Application Connecting to a MySQL database
Web Programming Language
Introduction to Web programming
Conection
PHP Programming Using Cloud 9 IDE.
Presentation transcript:

CIS 388 Internet Programming PHP/MySQL Part 2

Review/Sample PHP Detect IP address (redirect based on local/remote ip address) <?php // <!-- function IPredirect() { $ip = $_SERVER[“REMOTE_ADDR”]; if (substr($ip, 0, 3) == “10.”) { echo’<a href=“local.htm”>Local Link</a>’; } else { echo’<a href=“remote.htm”>Remote Link</a>’; } } // --> ?>

Advanced PHP PHP includes PHP File Handling Including an external php or html file in your PHP page – useful for reusing code/functions in many pages (navigational columns, database connections, session/cookie retrieval and validation etc…) Syntax: include 'filename'; <?php include 'footer.php';?> https://www.w3schools.com/php/php_includes.asp PHP File Handling Open/Read, Create/Modify, and Upload files with PHP https://www.w3schools.com/php/php_file_open.asp fopen(" filename.ext ", “argument") (fread(), fwrite(), and the fclose() are used with fopen) echo readfile(“filename.ext"); (useful for including external data/rss in your page) Uploading files with PHP: https://www.w3schools.com/php/php_file_upload.asp

Advanced PHP PHP Cookies PHP Session Variables PHP cookies are just like cookies in javascript and are used to trore bits of information on the client computer Syntax: setcookie(name, value, expire, path, domain, secure, httponly); "Value is: " . $_COOKIE[$cookie_name]; https://www.w3schools.com/php/php_cookies.asp PHP Session Variables PHP session variables are similar to cookies, they store bits of information on the server, and they are open with each browser “session” that connects to the server. A session is started with the session_start() function. Syntax: $_SESSION[“variablename"] = “value"; "Favorite color is " . $_SESSION["favcolor"] . ".<br>"; https://www.w3schools.com/php/php_sessions.asp

PHP and MySQL PHP allows the web page to get information from and update information stored in a MySQL database Database Connection Code (Object Oriented) <?php $servername = "localhost"; $username = "username"; $password = "password"; // Create connection $conn = new mysqli($servername, $username, $password); // Check connection if ($conn->connect_error) {     die("Connection failed: " . $conn->connect_error); }  echo "Connected successfully"; ?> https://www.w3schools.com/php/php_mysql_connect.asp

PHP and MySQL Create Database (*after MySQL Connection) $sql = "CREATE DATABASE myDB"; if ($conn->query($sql) === TRUE) {     echo "Database created successfully"; } else {     echo "Error creating database: " . $conn->error; } https://www.w3schools.com/php/php_mysql_create.asp Create Table (* after Database Created) $sql = "CREATE TABLE MyTable (ColumnName1 TYPE(),…) if ($conn->query($sql) === TRUE) {     echo "Table MyGuests created successfully"; } else {     echo "Error creating table: " . $conn->error; } $conn->close(); https://www.w3schools.com/php/php_mysql_create_table.asp

PHP and MySQL Insert Data into Database $sql = "INSERT INTO MyTable (ColumnName1) VALUES (‘samplevalue')"; if ($conn->query($sql) === TRUE) {     echo "New record created successfully"; } else {     echo "Error: " . $sql . "<br>" . $conn->error; } Select/Display Data from a Database $sql = "SELECT id, ColumnName1 FROM MyTable"; $result = $conn->query($sql); if ($result->num_rows > 0) {     // output data of each row     while($row = $result->fetch_assoc()) {         echo "id: " . $row["id"]. " – Column Value: " . $row[“ColumnName1"]. " "<br>";     } } else {     echo "0 results"; }

PHP and MySQL Delete Records from a Database $sql = "DELETE FROM MyTable WHERE id=1"; if ($conn->query($sql) === TRUE) {     echo "Record deleted successfully"; } else {     echo "Error deleting record: " . $conn->error; } Update Records in a Database $sql = "UPDATE MyTable SET ColumnName1=‘NewValue' WHERE id=1"; if ($conn->query($sql) === TRUE) {     echo "Record updated successfully"; } else {     echo "Error updating record: " . $conn->error; } SQL Reference: https://www.w3schools.com/sql/sql_quickref.asp

PHP Login Form <form action="" method="post" name="Login_Form"> <table width="400" border="0" align="center" cellpadding="5" cellspacing="1" class="Table"> <?php if(isset($msg)){?> <tr> <td colspan="2" align="center" valign="top"><?php echo $msg;?></td> </tr> <?php } ?> <td colspan="2" align="left" valign="top"><h3>Login</h3></td> <td align="right" valign="top">Username</td> <td><input name="Username" type="text" class="Input"></td> <td align="right">Password</td> <td><input name="Password" type="password" class="Input"></td> <td> </td> <td><input name="Submit" type="submit" value="Login" class="Button3"></td> </table> </form>

PHP Login Authentification Code <?php session_start(); /* Starts the session */ /* Check Login form submitted */ if(isset($_POST['Submit'])){ /* Define username and associated password array */ $logins = array('Alex' => '123456','username1' => 'password1','username2' => 'password2'); /* Check and assign submitted Username and Password to new variable */ $Username = isset($_POST['Username']) ? $_POST['Username'] : ''; $Password = isset($_POST['Password']) ? $_POST['Password'] : ''; /* Check Username and Password existence in defined array */ if (isset($logins[$Username]) && $logins[$Username] == $Password){ /* Success: Set session variables and redirect to Protected page */ $_SESSION['UserData']['Username']=$logins[$Username]; header("location:index.php"); exit; } else { /*Unsuccessful attempt: Set error message */ $msg="<span style='color:red'>Invalid Login Details</span>"; } ?>

PHP Session Variable Check <?php session_start(); /* Starts the session */ if(!isset($_SESSION['UserData']['Username'])){ header("location:login.php"); exit; } ?> Congratulation! You have logged into password protected page. <a href="logout.php">Click here</a> to Logout.

PHP Logout Session <?php session_start(); /* Starts the session */ session_destroy(); /* Destroy started session */ header("location:login.php"); /* Redirect to login page */ exit; ?>

Additional Resources W3 Schools PHP tutorial: https://www.w3schools.com/php/ PHP scripts and code resources: http://www.w3schools.in/php-script/php-login-without-using-database/ http://www.coderslexicon.com/really-simple-php-login-logout-script-example/