Classes exeptions php class custom Exception extends Exception

  • Slides: 30
Download presentation

Classes Δημιουργούμε κλάσεις με συναρτήσεις τις οποίες καλούμε όταν δημιουργούνται exeptions. <? php class

Classes Δημιουργούμε κλάσεις με συναρτήσεις τις οποίες καλούμε όταν δημιουργούνται exeptions. <? php class custom. Exception extends Exception { public function error. Message() { //error message $error. Msg = 'Error on line '. $this->get. Line(). ' in '. $this->get. File() . ': <b>'. $this->get. Message(). '</b> is not a valid E-Mail address'; return $error. Msg; } } $email = "[email protected] . . com";

try { //check if if(filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE) { //throw exception if email is

try { //check if if(filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE) { //throw exception if email is not valid throw new custom. Exception($email); } } catch (custom. Exception $e) { //display custom message echo $e->error. Message(); } ? >

 PHP XML DOM PARSER (Document Object Model) DOM <? xml version="1. 0"? >

PHP XML DOM PARSER (Document Object Model) DOM <? xml version="1. 0"? > <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> note to Tove from headi ng Jani Remi nder body Don´t forget me this weekend !

Header() Το header() function στέλλει ένα raw HTTP header στον client. Παράδειγμα: <html> <?

Header() Το header() function στέλλει ένα raw HTTP header στον client. Παράδειγμα: <html> <? php // This results in an error. // The output above is before the header() call header('Location: http: //www. example. com/'); ? > Σε αυτή την περίπτωση ο client μεταφέρεται αυτόματα στην ιστοσελίδα http: //www. example. com

Login <? php session_start(); ']; Alles <? php $_SESSION['name']=$_POST['name session_start(); $_SESSION['preview']=$_POST; if($_SESSION['name']=="") login. php');

Login <? php session_start(); ']; Alles <? php $_SESSION['name']=$_POST['name session_start(); $_SESSION['preview']=$_POST; if($_SESSION['name']=="") login. php'); ? > header('Location:

$file = fopen("login. txt", "r") or exit("Unable to open file!"); $array=array(); while(!feof($file)) { $tok=strtok(fgets($file),

$file = fopen("login. txt", "r") or exit("Unable to open file!"); $array=array(); while(!feof($file)) { $tok=strtok(fgets($file), ": "); $tok 2=strtok(": "); $array[$tok]=$tok 2; } fclose($file); ? > <p> </p> <? php $array[$_POST['name']] = str_replace(' ', '', $array[$_POST['name']]); $_POST['passwd'] = str_replace(' ', '', $_POST['passwd']); $array[$_POST['name']]=substr($array[$_POS T['name']], 0, -1);

if(array_key_exists($_POST['name'], $a rray) && ($_POST['name']!="") && ($_POST['passwd']!="")) { if($array[$_POST['name']]== $_POST['passwd']) {header('Location: menu. php'); ?

if(array_key_exists($_POST['name'], $a rray) && ($_POST['name']!="") && ($_POST['passwd']!="")) { if($array[$_POST['name']]== $_POST['passwd']) {header('Location: menu. php'); ? > <? php } else {echo "Invalid Username or Password"; ? > <form action="login. php" method="link"> <p><input type="submit" value="Go back" /></p> </form> <? php }

Date: <input type="text" name="date"/> <script language="Java. Script"> new tcal ({ // form name 'formname':

Date: <input type="text" name="date"/> <script language="Java. Script"> new tcal ({ // form name 'formname': 'testform', // input name 'controlname': 'date' }); </script

Βιβλιογραφία http: //www. techteam. gr/wiki/PHP http: //forum. kahuki. com/programming/6466 -htmlvs-php. html http: //www. differencebetween.

Βιβλιογραφία http: //www. techteam. gr/wiki/PHP http: //forum. kahuki. com/programming/6466 -htmlvs-php. html http: //www. differencebetween. net/technology/diffe rence-between-php-and-html/ http: //php. about. com/od/advancedphp/ss/php_sessi ons_2. htm http: //www. w 3 schools. com/ http: //www. php. net/manual/en/language. functions. php http: //www. w 3 schools. com/php/default. asp Βιβλίο: Programming in PHP (Rasmus Lerdorf and Kevin Tatroe)