├── Chapter 1 └── helloworld.php ├── .gitattributes ├── 9781484262399.jpg ├── Chapter 4 ├── e2dog.php ├── e5lab.php ├── e3dog.php ├── e7lab.php ├── e6dog.php ├── e4dog.php ├── e8lab.php ├── e11lab.php ├── e9dog.php ├── e10dog.php ├── e13lab.php └── e12dog.php ├── Chapter 9 ├── brody.jpg ├── Errors.log ├── dog_data.xml ├── uidpass.xml ├── edog_applications.xml ├── e3ajaxdemo.css ├── eajaxcall.js ├── e4get_breeds.php ├── e81getlists.js ├── e5dog_container.php ├── evalidator.js .js ├── e5changepassword.php ├── e6readerrorlog.php ├── e3registration.php ├── e5dog_data.php ├── e4login.php └── ebreeds.xml ├── Chapter 6 ├── Errors.log ├── e1testerror.php ├── edog_applications.xml ├── e2handleerror.php ├── eget_breeds.js ├── e4get_breeds.php ├── e5dog_container.php ├── evalidator.js ├── e8readerrorlog.php ├── e7lab.html ├── elab.html ├── e3dog.php ├── e6dog_interface.php ├── e7dog_interface.php └── ebreeds.xml ├── Chapter 3 └── Chapter3ReadMe.txt ├── Chapter 2 ├── dynamichtml.php ├── callmyself.php ├── ajaxdemo.css ├── ajaxdemomobile.css ├── Ajax_Example_JavaScript.js ├── helloworldajax.html └── mobilehelloworldajax.css ├── Chapter 7 ├── 07162015070620change.log ├── e1dog_data.xml ├── 07162015100850change.log ├── e1dog_applications.xml ├── e5dog_applications.xml ├── e2testdata.php ├── eget_breeds.js .js ├── e4get_breeds.php ├── e5dog_container.php ├── evalidator.js ├── e5lab.html ├── e1dog_data.php ├── e5dog.php ├── e4displaychangelog.php ├── e5dog_interface.php ├── e3dog_data.php └── e5dog_data.php ├── errata.md ├── Chapter 8 ├── readmechapter7.txt ├── dog_data.xml ├── uidpass.xml ├── edog_applications.xml ├── eget_breeds.js ├── e4get_breeds.php ├── e5dog_container.php ├── evalidator.js ├── e2login.php ├── e3registration.php ├── e4registration.php ├── e1lab.php ├── e4lab.php ├── e5dog.php ├── e5dog_interface.php ├── e5dog_data.php ├── e4login.php ├── e5changepassword.php └── ebreeds.xml ├── Chapter 5 ├── e5get_breeds.php ├── e9dog_applications.xml ├── e11get_breeds.php ├── e15get_breeds.js ├── e0get_breeds.js ├── e10dog_container.php ├── e6validator.js ├── e2validator.js ├── e3ande4lab.php ├── e0dog.php ├── e1lab.html ├── e7ande8dog.php ├── e6lab.html ├── e7lab.php ├── e14lab.html ├── e16dog.php └── e12dog_interface.php ├── README.md ├── Contributing.md └── LICENSE.txt /Chapter 1/helloworld.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /9781484262399.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/learn-php-8/HEAD/9781484262399.jpg -------------------------------------------------------------------------------- /Chapter 4/e2dog.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Chapter 9/brody.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/learn-php-8/HEAD/Chapter 9/brody.jpg -------------------------------------------------------------------------------- /Chapter 4/e5lab.php: -------------------------------------------------------------------------------- 1 | display_properties(); 5 | ?> -------------------------------------------------------------------------------- /Chapter 6/Errors.log: -------------------------------------------------------------------------------- 1 | 06.06.2020 03:02:44 | User Error | Breed update not successful 2 | 06.06.2020 03:00:55 | User Error | Name update not successful -------------------------------------------------------------------------------- /Chapter 9/Errors.log: -------------------------------------------------------------------------------- 1 | 06.06.2020 03:02:44 | User Error | Breed update not successful 2 | 06.06.2020 03:00:55 | User Error | Name update not successful -------------------------------------------------------------------------------- /Chapter 3/Chapter3ReadMe.txt: -------------------------------------------------------------------------------- 1 | Chapter 3 Readme 2 | 3 | The user is encouraged to create the short examples in this chapter. To promote this encouragement, examples are not provided. -------------------------------------------------------------------------------- /Chapter 2/dynamichtml.php: -------------------------------------------------------------------------------- 1 | '; 3 | print 'My Program'; 4 | print ''; 5 | print '

Hello World

'; 6 | print ''; 7 | print ''; 8 | ?> -------------------------------------------------------------------------------- /Chapter 7/07162015070620change.log: -------------------------------------------------------------------------------- 1 | 07162015070620 | Insert | a:1:{i:0;a:4:{s:8:"dog_name";s:6:"stevie";s:10:"dog_weight";s:2:"45";s:9:"dog_color";s:6:"Yellow";s:9:"dog_breed";s:22:"American Water Spaniel";}} -------------------------------------------------------------------------------- /Chapter 4/e3dog.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /errata.md: -------------------------------------------------------------------------------- 1 | # Errata for *Learn PHP 8* 2 | 3 | On **page xx** [Summary of error]: 4 | 5 | Details of error here. Highlight key pieces in **bold**. 6 | 7 | *** 8 | 9 | On **page xx** [Summary of error]: 10 | 11 | Details of error here. Highlight key pieces in **bold**. 12 | 13 | *** -------------------------------------------------------------------------------- /Chapter 4/e7lab.php: -------------------------------------------------------------------------------- 1 | get_properties(); 5 | list($dog_weight, $dog_breed, $dog_color) = explode(',', $dog_properties); 6 | 7 | print "Dog weight is $dog_weight. Dog breed is $dog_breed. Dog color is $dog_color."; 8 | ?> -------------------------------------------------------------------------------- /Chapter 8/readmechapter7.txt: -------------------------------------------------------------------------------- 1 | The dog_data program is set to have the change log and error files in the same folder as the application. 2 | You will need to change the location of the error log (in dog_container) to a valid location on your system. 3 | If you do not change this information you will receive errors. 4 | -------------------------------------------------------------------------------- /Chapter 4/e6dog.php: -------------------------------------------------------------------------------- 1 | dog_weight,$this->dog_breed,$this->dog_color."; 13 | 14 | } 15 | } 16 | ?> -------------------------------------------------------------------------------- /Chapter 6/e1testerror.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Chapter 4/e4dog.php: -------------------------------------------------------------------------------- 1 | dog_weight. Dog breed is $this->dog_breed. Dog color is $this->dog_color."; 13 | 14 | } 15 | } 16 | ?> -------------------------------------------------------------------------------- /Chapter 8/dog_data.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | tester1 5 | 19 6 | Green 7 | Lab 8 | 9 | 10 | tester2 11 | 19 12 | Green 13 | Lab 14 | 15 | -------------------------------------------------------------------------------- /Chapter 7/e1dog_data.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | tester1 5 | 19 6 | Green 7 | Lab 8 | 9 | 10 | tester2 11 | 19 12 | Green 13 | Lab 14 | 15 | -------------------------------------------------------------------------------- /Chapter 9/dog_data.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SallyBee 5 | 19 6 | Yellow 7 | Akita 8 | 9 | 10 | Pete 11 | 24 12 | Black 13 | Basset Hound 14 | 15 | -------------------------------------------------------------------------------- /Chapter 5/e5get_breeds.php: -------------------------------------------------------------------------------- 1 | asXML(); 6 | print ""; 14 | 15 | ?> -------------------------------------------------------------------------------- /Chapter 2/callmyself.php: -------------------------------------------------------------------------------- 1 | Hello World "; 5 | } 6 | else 7 | { 8 | print "PHP Example"; 9 | print "
"; 10 | print ""; 11 | print "
"; 12 | print ""; 13 | } 14 | ?> -------------------------------------------------------------------------------- /Chapter 6/edog_applications.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | e3dog.php 6 | 7 | 8 | 9 | 10 | e4get_breeds.php 11 | 12 | 13 | 14 | 15 | ebreeds.xml 16 | 17 | 18 | -------------------------------------------------------------------------------- /Chapter 5/e9dog_applications.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | e16dog.php 6 | 7 | 8 | 9 | 10 | e12get_breeds.php 11 | 12 | 13 | 14 | 15 | e5breeds.xml 16 | 17 | 18 | -------------------------------------------------------------------------------- /Chapter 7/07162015100850change.log: -------------------------------------------------------------------------------- 1 | 07162015100850 | Insert | a:1:{i:0;a:4:{s:8:"dog_name";s:7:"tester1";s:10:"dog_weight";s:2:"19";s:9:"dog_color";s:5:"Green";s:9:"dog_breed";s:3:"Lab";}} 2 | 07162015100850 | Update | a:2:{i:0;a:4:{s:8:"dog_name";s:7:"tester1";s:10:"dog_weight";s:2:"19";s:9:"dog_color";s:5:"Green";s:9:"dog_breed";s:3:"Lab";}i:1;a:4:{s:8:"dog_name";s:7:"tester2";s:10:"dog_weight";s:2:"19";s:9:"dog_color";s:5:"Green";s:9:"dog_breed";s:3:"Lab";}} 3 | 07162015100850 | Delete | 1 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Apress Source Code 2 | 3 | This repository accompanies [*Learn PHP 8*](https://www.apress.com/9781484262399) by Steve Prettyman (Apress, 2020). 4 | 5 | [comment]: #cover 6 | ![Cover image](9781484262399.jpg) 7 | 8 | Download the files as a zip using the green button, or clone the repository to your machine using Git. 9 | 10 | ## Releases 11 | 12 | Release v1.0 corresponds to the code in the published book, without corrections or updates. 13 | 14 | ## Contributions 15 | 16 | See the file Contributing.md for more information on how you can contribute to this repository. -------------------------------------------------------------------------------- /Chapter 8/uidpass.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Fredfred 5 | $2y$10$VosI32FejL.bOMaCjGbBp.Jre6Ipa.tLYQrVqj9kiVpef5zZ25qQK 6 | 2020-09-03 7 | 0 8 | 08052020044229 9 | 08052020045431 10 | 11 | 12 | Poppoppop 13 | $2y$10$8xzP2XCGyEVKSuTOB7enjua5lZybhkkqXj6kOSFaEKyE3A22Am90q 14 | 2020-09-05 15 | 0 16 | 08062020042256 17 | 08062020042443 18 | 19 | -------------------------------------------------------------------------------- /Chapter 9/uidpass.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Poppoppop 5 | $2y$10$8xzP2XCGyEVKSuTOB7enjua5lZybhkkqXj6kOSFaEKyE3A22Am90q 6 | 2020-09-05 7 | 18 8 | 08062020042256 9 | 08062020042443 10 | 11 | 12 | Fredfred 13 | $2y$10$.MC43rkbLfSCEJzH8OJDw.5EboVYvTmy068eE9iEI0myvxAnQGs5i 14 | 2020-10-15 15 | 0 16 | 09172020080436 17 | 09172020080454 18 | 19 | -------------------------------------------------------------------------------- /Chapter 7/e1dog_applications.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | edog.php 6 | 7 | 8 | 9 | 10 | eget_breeds.php 11 | 12 | 13 | 14 | 15 | ebreeds.xml 16 | 17 | 18 | 19 | 20 | e1dog_data.xml 21 | 22 | 23 | 24 | 25 | e1dog_data.php 26 | 27 | 28 | -------------------------------------------------------------------------------- /Chapter 7/e5dog_applications.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | e5dog.php 6 | 7 | 8 | 9 | 10 | e4get_breeds.php 11 | 12 | 13 | 14 | 15 | ebreeds.xml 16 | 17 | 18 | 19 | 20 | e1dog_data.xml 21 | 22 | 23 | 24 | 25 | e5dog_data.php 26 | 27 | 28 | -------------------------------------------------------------------------------- /Contributing.md: -------------------------------------------------------------------------------- 1 | # Contributing to Apress Source Code 2 | 3 | Copyright for Apress source code belongs to the author(s). However, under fair use you are encouraged to fork and contribute minor corrections and updates for the benefit of the author(s) and other readers. 4 | 5 | ## How to Contribute 6 | 7 | 1. Make sure you have a GitHub account. 8 | 2. Fork the repository for the relevant book. 9 | 3. Create a new branch on which to make your change, e.g. 10 | `git checkout -b my_code_contribution` 11 | 4. Commit your change. Include a commit message describing the correction. Please note that if your commit message is not clear, the correction will not be accepted. 12 | 5. Submit a pull request. 13 | 14 | Thank you for your contribution! -------------------------------------------------------------------------------- /Chapter 7/e2testdata.php: -------------------------------------------------------------------------------- 1 | Array ( "dog_name" => "Sally", "dog_weight" => "19", "dog_color" => "Green", "dog_breed" => "Lab" )); 10 | 11 | $tester->insertRecords($records_array); 12 | 13 | print_r ($tester->readRecords("ALL")); 14 | print("



"); 15 | $records_array = Array ( 16 | 1 => Array ( "dog_name" => "Spot", "dog_weight" => "19", "dog_color" => "Green", "dog_breed" => "Lab" )); 17 | 18 | $tester->updateRecords($records_array); 19 | 20 | print_r ($tester->readRecords("ALL")); 21 | print("



"); 22 | 23 | $tester->deleteRecord(1); 24 | print_r ($tester->readRecords("ALL")); 25 | 26 | $tester = NULL; 27 | ?> -------------------------------------------------------------------------------- /Chapter 2/ajaxdemo.css: -------------------------------------------------------------------------------- 1 | body { background-color: #000000; 2 | font-family: Arial, Verdana, sans-serif; } 3 | #wrapper { margin: 0 auto; 4 | width: 85%; 5 | min-width: 800px; 6 | background-color: #cc0000; 7 | color: #000066; } 8 | #header { background-color: #ff0000; 9 | color: #00005D; 10 | font-size: 125%; 11 | padding: 20px 20px 20px 160px; 12 | background-repeat: no-repeat; } 13 | h1 { margin-bottom: 10px; } 14 | #content { background-color: #ffffff; 15 | color: #000000; 16 | padding: 10px 20px; 17 | overflow: auto; } 18 | #footer { font-size: 80%; 19 | text-align: center; 20 | padding: 5px; 21 | background-color: #0000FF; 22 | color: #ffffff; 23 | clear: both;} 24 | h2 { color: #000000; 25 | font-family: Arial, sans-serif; } 26 | #floatright { float: right; 27 | margin: 10px; } -------------------------------------------------------------------------------- /Chapter 6/e2handleerror.php: -------------------------------------------------------------------------------- 1 | throwexception(); 14 | echo "This line does not display"; 15 | $tester->produceerror(); // will not execute if line 13 is executed 16 | echo "This line does not display"; 17 | } 18 | catch (errorException $e ){ 19 | echo $e->getMessage(); } 20 | catch (userException $e) { 21 | echo $e->getMessage(); } 22 | catch (Exception $e) { 23 | echo $e->getMessage(); } 24 | echo "This line will display"; 25 | ?> -------------------------------------------------------------------------------- /Chapter 2/ajaxdemomobile.css: -------------------------------------------------------------------------------- 1 | body { background-color: #000000; 2 | font-family: Arial, Verdana, sans-serif; 3 | margin: 0; } 4 | #wrapper { margin: 0 auto; 5 | width: 100%; 6 | margin: 0; 7 | min-width: 0px; 8 | background-color: #cc0000; 9 | color: #000066; } 10 | #header { background-color: #ff0000; 11 | color: #00005D; 12 | font-size: 100%; 13 | padding: 0.5px 0.5px 0.5px 0.5px; } 14 | h1 { margin: 0px; } 15 | #content { background-color: #ffffff; 16 | color: #000000; 17 | padding: 0.5px 0.5px; 18 | overflow: auto; } 19 | #footer { font-size: 80%; 20 | text-align: left; 21 | padding: 0px; 22 | background-color: #0000FF; 23 | color: #ffffff; 24 | clear: both;} 25 | h2 { color: #000000; 26 | font-family: Arial, sans-serif; 27 | margin: 0px; } 28 | #floatright { float: none; 29 | margin: 0px; } -------------------------------------------------------------------------------- /Chapter 9/edog_applications.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | edog.php 6 | 7 | 8 | 9 | 10 | e4get_breeds.php 11 | 12 | 13 | 14 | 15 | ebreeds.xml 16 | 17 | 18 | 19 | 20 | dog_data.xml 21 | 22 | 23 | 24 | 25 | e5dog_data.php 26 | 27 | 28 | 29 | 30 | uidpass.xml 31 | 32 | 33 | -------------------------------------------------------------------------------- /Chapter 8/edog_applications.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | e5dog.php 6 | 7 | 8 | 9 | 10 | e4get_breeds.php 11 | 12 | 13 | 14 | 15 | ebreeds.xml 16 | 17 | 18 | 19 | 20 | e1dog_data.xml 21 | 22 | 23 | 24 | 25 | e5dog_data.php 26 | 27 | 28 | 29 | 30 | uidpass.xml 31 | 32 | 33 | -------------------------------------------------------------------------------- /Chapter 9/e3ajaxdemo.css: -------------------------------------------------------------------------------- 1 | body { background-color: #000000; 2 | font-family: Arial, Verdana, sans-serif; } 3 | #wrapper { margin: 0 auto; 4 | width: 85%; 5 | min-width: 800px; 6 | background-color: #cc0000; 7 | color: #000066; 8 | float: top; 9 | } 10 | #header { background-color: #ff0000; 11 | color: #00005D; 12 | font-size: 125%; 13 | text-align: center; 14 | padding: 20px 20px 20px 20px; 15 | background-repeat: no-repeat; } 16 | h1 { margin-bottom: 10px; } 17 | #content { background-color: #ffffff; 18 | color: #000000; 19 | padding: 10px 20px; 20 | overflow: auto; } 21 | #footer { font-size: 80%; 22 | text-align: center; 23 | padding: 5px; 24 | background-color: #0000FF; 25 | color: #ffffff; 26 | clear: both;} 27 | h2 { color: #000000; 28 | font-family: Arial, sans-serif; } 29 | #floatright { float: right; 30 | margin: 10px; } -------------------------------------------------------------------------------- /Chapter 2/Ajax_Example_JavaScript.js: -------------------------------------------------------------------------------- 1 | function getXMLHttp() 2 | { 3 | var xmlHttp; 4 | try 5 | { 6 | xmlHttp = new XMLHttpRequest(); 7 | } 8 | catch(e) 9 | { 10 | //Internet Explorer is different than the others 11 | try 12 | { 13 | xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); 14 | } 15 | catch(e) 16 | { 17 | try 18 | { 19 | xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 20 | } 21 | catch(e) 22 | { 23 | alert("Old browser? Upgrade today so you can use AJAX!") 24 | return false; 25 | } 26 | } 27 | } 28 | return xmlHttp; 29 | } 30 | function AjaxRequest() 31 | { 32 | var xmlHttp = getXMLHttp(); 33 | xmlHttp.onreadystatechange = function() 34 | { 35 | if(xmlHttp.readyState == 4) 36 | { 37 | HandleResponse(xmlHttp.responseText); 38 | } 39 | } 40 | xmlHttp.open("GET", "myfirstprogram.php", true); 41 | xmlHttp.send(null); 42 | } 43 | function HandleResponse(response) 44 | { 45 | document.getElementById('AjaxResponse').innerHTML = response; 46 | } -------------------------------------------------------------------------------- /Chapter 2/helloworldajax.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | PHP Ajax Demo 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 |

"Watch it!!"

12 |

The words below will be replaced by "Hello World" which is pulled from the 'myfirstprogram.php' file via AJAX.

13 |

AJAX DEMO

14 |

15 |
16 | Pay attention... Notice when you click the button that only this section changes. 17 |
18 | 20 |
21 | 22 | -------------------------------------------------------------------------------- /Chapter 5/e11get_breeds.php: -------------------------------------------------------------------------------- 1 | asXML(); 24 | 25 | $this->result = ""; 34 | 35 | return $this->result; 36 | } 37 | else 38 | { 39 | return FALSE; 40 | } 41 | 42 | 43 | } 44 | } 45 | ?> -------------------------------------------------------------------------------- /Chapter 4/e8lab.php: -------------------------------------------------------------------------------- 1 | set_dog_name('Fred'); 6 | print $dog_error_message == TRUE ? 'Name update successful
' : 'Name update not successful
'; 7 | 8 | $dog_error_message = $lab->set_dog_weight(50); 9 | print $dog_error_message == TRUE ? 'Weight update successful
' : 'Weight update not successful
'; 10 | 11 | $dog_error_message = $lab->set_dog_breed('Lab'); 12 | print $dog_error_message == TRUE ? 'Breed update successful
' : 'Breed update not successful
'; 13 | 14 | $dog_error_message = $lab->set_dog_color('Yellow'); 15 | print $dog_error_message == TRUE ? 'Color update successful
' : 'Color update not successful
'; 16 | 17 | $dog_properties = $lab->get_properties(); 18 | list($dog_weight, $dog_breed, $dog_color) = explode(',', $dog_properties); 19 | print "Dog weight is $dog_weight. Dog breed is $dog_breed. Dog color is $dog_color."; 20 | ?> -------------------------------------------------------------------------------- /Chapter 5/e15get_breeds.js: -------------------------------------------------------------------------------- 1 | function getXMLHttp() 2 | { 3 | var xmlHttp; 4 | try 5 | { 6 | xmlHttp = new XMLHttpRequest(); 7 | } 8 | catch(e) 9 | { 10 | //Internet Explorer is different than the others 11 | try 12 | { 13 | xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); 14 | } 15 | catch(e) 16 | { 17 | try 18 | { 19 | xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 20 | } 21 | catch(e) 22 | { 23 | alert("Old browser? Upgrade today so you can use AJAX!") 24 | return false; 25 | } 26 | } 27 | } 28 | return xmlHttp; 29 | } 30 | function AjaxRequest(value) 31 | { 32 | var xmlHttp = getXMLHttp(); 33 | xmlHttp.onreadystatechange = function() 34 | { 35 | if(xmlHttp.readyState == 4) 36 | { 37 | HandleResponse(xmlHttp.responseText); 38 | } 39 | } 40 | xmlHttp.open("GET", value, true); 41 | xmlHttp.send(null); 42 | } 43 | function HandleResponse(response) 44 | { 45 | document.getElementById('AjaxResponse').innerHTML = response; 46 | } -------------------------------------------------------------------------------- /Chapter 6/eget_breeds.js: -------------------------------------------------------------------------------- 1 | function getXMLHttp() 2 | { 3 | var xmlHttp; 4 | try 5 | { 6 | xmlHttp = new XMLHttpRequest(); 7 | } 8 | catch(e) 9 | { 10 | //Internet Explorer is different than the others 11 | try 12 | { 13 | xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); 14 | } 15 | catch(e) 16 | { 17 | try 18 | { 19 | xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 20 | } 21 | catch(e) 22 | { 23 | alert("Old browser? Upgrade today so you can use AJAX!") 24 | return false; 25 | } 26 | } 27 | } 28 | return xmlHttp; 29 | } 30 | function AjaxRequest(value) 31 | { 32 | var xmlHttp = getXMLHttp(); 33 | xmlHttp.onreadystatechange = function() 34 | { 35 | if(xmlHttp.readyState == 4) 36 | { 37 | HandleResponse(xmlHttp.responseText); 38 | } 39 | } 40 | xmlHttp.open("GET", value, true); 41 | xmlHttp.send(null); 42 | } 43 | function HandleResponse(response) 44 | { 45 | document.getElementById('AjaxResponse').innerHTML = response; 46 | } -------------------------------------------------------------------------------- /Chapter 8/eget_breeds.js: -------------------------------------------------------------------------------- 1 | function getXMLHttp() 2 | { 3 | var xmlHttp; 4 | try 5 | { 6 | xmlHttp = new XMLHttpRequest(); 7 | } 8 | catch(e) 9 | { 10 | //Internet Explorer is different than the others 11 | try 12 | { 13 | xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); 14 | } 15 | catch(e) 16 | { 17 | try 18 | { 19 | xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 20 | } 21 | catch(e) 22 | { 23 | alert("Old browser? Upgrade today so you can use AJAX!") 24 | return false; 25 | } 26 | } 27 | } 28 | return xmlHttp; 29 | } 30 | function AjaxRequest(value) 31 | { 32 | var xmlHttp = getXMLHttp(); 33 | xmlHttp.onreadystatechange = function() 34 | { 35 | if(xmlHttp.readyState == 4) 36 | { 37 | HandleResponse(xmlHttp.responseText); 38 | } 39 | } 40 | xmlHttp.open("GET", value, true); 41 | xmlHttp.send(null); 42 | } 43 | function HandleResponse(response) 44 | { 45 | document.getElementById('AjaxResponse').innerHTML = response; 46 | } -------------------------------------------------------------------------------- /Chapter 9/eajaxcall.js: -------------------------------------------------------------------------------- 1 | function getXMLHttp() 2 | { 3 | var xmlHttp; 4 | try 5 | { 6 | xmlHttp = new XMLHttpRequest(); 7 | } 8 | catch(e) 9 | { 10 | //Internet Explorer is different than the others 11 | try 12 | { 13 | xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); 14 | } 15 | catch(e) 16 | { 17 | try 18 | { 19 | xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 20 | } 21 | catch(e) 22 | { 23 | alert("Old browser? Upgrade today so you can use AJAX!") 24 | return false; 25 | } 26 | } 27 | } 28 | return xmlHttp; 29 | } 30 | function AjaxRequest(value) 31 | { 32 | var xmlHttp = getXMLHttp(); 33 | xmlHttp.onreadystatechange = function() 34 | { 35 | if(xmlHttp.readyState == 4) 36 | { 37 | HandleResponse(xmlHttp.responseText); 38 | } 39 | } 40 | xmlHttp.open("GET", value, true); 41 | xmlHttp.send(null); 42 | } 43 | function HandleResponse(response) 44 | { 45 | document.getElementById('AjaxResponse').innerHTML = response; 46 | } -------------------------------------------------------------------------------- /Chapter 5/e0get_breeds.js: -------------------------------------------------------------------------------- 1 | function getXMLHttp() 2 | { 3 | var xmlHttp; 4 | try 5 | { 6 | xmlHttp = new XMLHttpRequest(); 7 | } 8 | catch(e) 9 | { 10 | //Internet Explorer is different than the others 11 | try 12 | { 13 | xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); 14 | } 15 | catch(e) 16 | { 17 | try 18 | { 19 | xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 20 | } 21 | catch(e) 22 | { 23 | alert("Old browser? Upgrade today so you can use AJAX!") 24 | return false; 25 | } 26 | } 27 | } 28 | return xmlHttp; 29 | } 30 | function AjaxRequest() 31 | { 32 | var xmlHttp = getXMLHttp(); 33 | xmlHttp.onreadystatechange = function() 34 | { 35 | if(xmlHttp.readyState == 4) 36 | { 37 | HandleResponse(xmlHttp.responseText); 38 | } 39 | } 40 | xmlHttp.open("GET", "e45get_breeds.php", true); 41 | xmlHttp.send(null); 42 | } 43 | function HandleResponse(response) 44 | { 45 | document.getElementById('AjaxResponse').innerHTML = response; 46 | } -------------------------------------------------------------------------------- /Chapter 7/eget_breeds.js .js: -------------------------------------------------------------------------------- 1 | function getXMLHttp() 2 | { 3 | var xmlHttp; 4 | try 5 | { 6 | xmlHttp = new XMLHttpRequest(); 7 | } 8 | catch(e) 9 | { 10 | //Internet Explorer is different than the others 11 | try 12 | { 13 | xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); 14 | } 15 | catch(e) 16 | { 17 | try 18 | { 19 | xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 20 | } 21 | catch(e) 22 | { 23 | alert("Old browser? Upgrade today so you can use AJAX!") 24 | return false; 25 | } 26 | } 27 | } 28 | return xmlHttp; 29 | } 30 | function AjaxRequest(value) 31 | { 32 | var xmlHttp = getXMLHttp(); 33 | xmlHttp.onreadystatechange = function() 34 | { 35 | if(xmlHttp.readyState == 4) 36 | { 37 | HandleResponse(xmlHttp.responseText); 38 | } 39 | } 40 | xmlHttp.open("GET", value, true); 41 | xmlHttp.send(null); 42 | } 43 | function HandleResponse(response) 44 | { 45 | document.getElementById('AjaxResponse').innerHTML = response; 46 | } 47 | -------------------------------------------------------------------------------- /Chapter 6/e4get_breeds.php: -------------------------------------------------------------------------------- 1 | asXML(); 23 | 24 | $this->result = ""; 33 | 34 | return $this->result; 35 | } 36 | else 37 | { 38 | throw new Exception("Breed xml file missing or corrupt"); 39 | // return FALSE; 40 | } 41 | 42 | 43 | } 44 | } 45 | ?> -------------------------------------------------------------------------------- /Chapter 7/e4get_breeds.php: -------------------------------------------------------------------------------- 1 | asXML(); 23 | 24 | $this->result = ""; 33 | 34 | return $this->result; 35 | } 36 | else 37 | { 38 | throw new Exception("Breed xml file missing or corrupt"); 39 | // return FALSE; 40 | } 41 | 42 | 43 | } 44 | } 45 | ?> -------------------------------------------------------------------------------- /Chapter 8/e4get_breeds.php: -------------------------------------------------------------------------------- 1 | asXML(); 23 | 24 | $this->result = ""; 33 | 34 | return $this->result; 35 | } 36 | else 37 | { 38 | throw new Exception("Breed xml file missing or corrupt"); 39 | // return FALSE; 40 | } 41 | 42 | 43 | } 44 | } 45 | ?> -------------------------------------------------------------------------------- /Chapter 9/e4get_breeds.php: -------------------------------------------------------------------------------- 1 | asXML(); 23 | 24 | $this->result = ""; 33 | 34 | return $this->result; 35 | } 36 | else 37 | { 38 | throw new Exception("Breed xml file missing or corrupt"); 39 | // return FALSE; 40 | } 41 | 42 | 43 | } 44 | } 45 | ?> -------------------------------------------------------------------------------- /Chapter 2/mobilehelloworldajax.css: -------------------------------------------------------------------------------- 1 | 2 | PHP Ajax Demo 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 |

"Watch it!!"

13 |

The words below will be replaced by "Hello World" which is pulled from the 'myfirstprogram.php' file via AJAX.

14 |

AJAX DEMO

15 |

16 |
17 | Pay attention... Notice when you click the button that only this section changes. 18 |
19 | 21 |
22 | -------------------------------------------------------------------------------- /Chapter 9/e81getlists.js: -------------------------------------------------------------------------------- 1 | function getXMLHttp() 2 | { 3 | var xmlHttp; 4 | try 5 | { 6 | xmlHttp = new XMLHttpRequest(); 7 | } 8 | catch(e) 9 | { 10 | //Internet Explorer is different than the others 11 | try 12 | { 13 | xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); 14 | } 15 | catch(e) 16 | { 17 | try 18 | { 19 | xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 20 | } 21 | catch(e) 22 | { 23 | alert("Old browser? Upgrade today so you can use AJAX!") 24 | return false; 25 | } 26 | } 27 | } 28 | return xmlHttp; 29 | } 30 | function AjaxRequest(value) 31 | { 32 | var xmlHttp = getXMLHttp(); 33 | xmlHttp.onreadystatechange = function() 34 | { 35 | if(xmlHttp.readyState == 4) 36 | { 37 | HandleResponse(xmlHttp.responseText); 38 | } 39 | } 40 | xmlHttp.open("GET", value, true); 41 | xmlHttp.send(null); 42 | } 43 | function HandleResponse(response) 44 | { 45 | 46 | var responsevalues = response.split('|'); 47 | document.getElementById('AjaxResponse').innerHTML = responsevalues[0]; 48 | document.getElementById('AjaxReturnValue').innerHTML = responsevalues[1]; 49 | obj = JSON.parse(responsevalues[2]); 50 | 51 | } -------------------------------------------------------------------------------- /Chapter 4/e11lab.php: -------------------------------------------------------------------------------- 1 | set_dog_name('Fred'); 6 | print $dog_error_message == TRUE ? 'Name update successful
' : 'Name update not successful
'; 7 | 8 | $dog_error_message = $lab->set_dog_weight(50); 9 | print $dog_error_message == TRUE ? 'Weight update successful
' : 'Weight update not successful
'; 10 | 11 | $dog_error_message = $lab->set_dog_breed('Lab'); 12 | print $dog_error_message == TRUE ? 'Breed update successful
' : 'Breed update not successful
'; 13 | 14 | $dog_error_message = $lab->set_dog_color('Yellow'); 15 | print $dog_error_message == TRUE ? 'Color update successful
' : 'Color update not successful
'; 16 | // ------------------------------Get Properties-------------------------- 17 | print $lab->get_dog_name() . "
"; 18 | print $lab->get_dog_weight() . "
"; 19 | print $lab->get_dog_breed() . "
"; 20 | print $lab->get_dog_color() . "
"; 21 | $dog_properties = $lab->get_properties(); 22 | list($dog_weight, $dog_breed, $dog_color) = explode(',', $dog_properties); 23 | print "Dog weight is $dog_weight. Dog breed is $dog_breed. Dog color is $dog_color."; 24 | ?> -------------------------------------------------------------------------------- /Chapter 4/e9dog.php: -------------------------------------------------------------------------------- 1 | dog_name = $value : $error_message = FALSE; 15 | return $error_message; 16 | } 17 | function set_dog_weight($value) 18 | { 19 | $error_message = TRUE; 20 | (ctype_digit($value) && ($value > 0 && $value <= 120)) ? $this->dog_weight = $value : $error_message = FALSE; 21 | return $error_message; 22 | } 23 | function set_dog_breed($value) 24 | { 25 | $error_message = TRUE; 26 | (ctype_alpha($value) && strlen($value) <= 35) ? $this->dog_breed = $value : $error_message = FALSE; 27 | return $error_message; 28 | } 29 | function set_dog_color($value) 30 | { 31 | $error_message = TRUE; 32 | (ctype_alpha($value) && strlen($value) <= 15) ? $this->dog_color = $value : $error_message = FALSE; 33 | return $error_message; 34 | } 35 | 36 | function get_properties() 37 | { 38 | return "$this->dog_weight,$this->dog_breed,$this->dog_color."; 39 | } 40 | } 41 | ?> -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Freeware License, some rights reserved 2 | 3 | Copyright (c) 2020 Steve Prettyman 4 | 5 | Permission is hereby granted, free of charge, to anyone obtaining a copy 6 | of this software and associated documentation files (the "Software"), 7 | to work with the Software within the limits of freeware distribution and fair use. 8 | This includes the rights to use, copy, and modify the Software for personal use. 9 | Users are also allowed and encouraged to submit corrections and modifications 10 | to the Software for the benefit of other users. 11 | 12 | It is not allowed to reuse, modify, or redistribute the Software for 13 | commercial use in any way, or for a user’s educational materials such as books 14 | or blog articles without prior permission from the copyright holder. 15 | 16 | The above copyright notice and this permission notice need to be included 17 | in all copies or substantial portions of the software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | SOFTWARE. 26 | 27 | 28 | -------------------------------------------------------------------------------- /Chapter 5/e10dog_container.php: -------------------------------------------------------------------------------- 1 | app = $value; 14 | } 15 | else 16 | { 17 | exit; 18 | } 19 | } 20 | 21 | public function set_app($value) 22 | { 23 | $this->app = $value; 24 | } 25 | 26 | public function get_dog_application($search_value) 27 | { 28 | 29 | $xmlDoc = new DOMDocument(); 30 | 31 | if ( file_exists("e410dog_applications.xml") ) 32 | 33 | { 34 | $xmlDoc->load( 'e410dog_applications.xml' ); 35 | 36 | $searchNode = $xmlDoc->getElementsByTagName( "type" ); 37 | 38 | foreach( $searchNode as $searchNode ) 39 | { 40 | $valueID = $searchNode->getAttribute('ID'); 41 | 42 | if($valueID == $search_value) 43 | { 44 | 45 | $xmlLocation = $searchNode->getElementsByTagName( "location" ); 46 | return $xmlLocation->item(0)->nodeValue; 47 | break; 48 | 49 | } 50 | 51 | } 52 | } 53 | return FALSE; 54 | } 55 | function create_object($properties_array) 56 | { 57 | 58 | $dog_loc = $this->get_dog_application($this->app); 59 | if(($dog_loc == FALSE) || (!file_exists($dog_loc))) 60 | { 61 | return FALSE; 62 | } 63 | else 64 | { 65 | 66 | require_once($dog_loc); 67 | $class_array = get_declared_classes(); 68 | $last_position = count($class_array) - 1; 69 | $class_name = $class_array[$last_position]; 70 | $dog_object = new $class_name($properties_array); 71 | 72 | return $dog_object; 73 | } 74 | 75 | } 76 | 77 | } 78 | 79 | ?> 80 | -------------------------------------------------------------------------------- /Chapter 6/e5dog_container.php: -------------------------------------------------------------------------------- 1 | app = $value; 14 | } 15 | else 16 | { 17 | exit; 18 | } 19 | } 20 | 21 | public function set_app($value) 22 | { 23 | $this->app = $value; 24 | } 25 | 26 | public function get_dog_application($search_value) 27 | { 28 | 29 | $xmlDoc = new DOMDocument(); 30 | 31 | if ( file_exists("edog_applications.xml") ) 32 | 33 | { 34 | $xmlDoc->load( 'edog_applications.xml' ); 35 | 36 | $searchNode = $xmlDoc->getElementsByTagName( "type" ); 37 | 38 | foreach( $searchNode as $searchNode ) 39 | { 40 | $valueID = $searchNode->getAttribute('ID'); 41 | 42 | if($valueID == $search_value) 43 | { 44 | 45 | $xmlLocation = $searchNode->getElementsByTagName( "location" ); 46 | return $xmlLocation->item(0)->nodeValue; 47 | break; 48 | 49 | } 50 | 51 | } 52 | } 53 | throw new Exception("Dog applications xml file missing or corrupt"); 54 | // return FALSE; 55 | } 56 | function create_object($properties_array) 57 | { 58 | 59 | $dog_loc = $this->get_dog_application($this->app); 60 | if(($dog_loc == FALSE) || (!file_exists($dog_loc))) 61 | { 62 | 63 | throw new Exception("File $dog_loc missing or corrupt."); 64 | // return FALSE; 65 | } 66 | else 67 | { 68 | 69 | require_once($dog_loc); 70 | $class_array = get_declared_classes(); 71 | $last_position = count($class_array) - 1; 72 | $class_name = $class_array[$last_position]; 73 | $dog_object = new $class_name($properties_array); 74 | 75 | return $dog_object; 76 | } 77 | 78 | } 79 | 80 | } 81 | 82 | ?> -------------------------------------------------------------------------------- /Chapter 7/e5dog_container.php: -------------------------------------------------------------------------------- 1 | app = $value; 14 | } 15 | else 16 | { 17 | exit; 18 | } 19 | } 20 | 21 | public function set_app($value) 22 | { 23 | $this->app = $value; 24 | } 25 | 26 | public function get_dog_application($search_value) 27 | { 28 | 29 | $xmlDoc = new DOMDocument(); 30 | 31 | if ( file_exists("e5dog_applications.xml") ) 32 | 33 | { 34 | $xmlDoc->load( 'e5dog_applications.xml' ); 35 | 36 | $searchNode = $xmlDoc->getElementsByTagName( "type" ); 37 | 38 | foreach( $searchNode as $searchNode ) 39 | { 40 | $valueID = $searchNode->getAttribute('ID'); 41 | 42 | if($valueID == $search_value) 43 | { 44 | 45 | $xmlLocation = $searchNode->getElementsByTagName( "location" ); 46 | return $xmlLocation->item(0)->nodeValue; 47 | break; 48 | 49 | } 50 | 51 | } 52 | } 53 | throw new Exception("Dog applications xml file missing or corrupt"); 54 | // return FALSE; 55 | } 56 | function create_object($properties_array) 57 | { 58 | 59 | $dog_loc = $this->get_dog_application($this->app); 60 | if(($dog_loc == FALSE) || (!file_exists($dog_loc))) 61 | { 62 | 63 | throw new Exception("File $dog_loc missing or corrupt."); 64 | // return FALSE; 65 | } 66 | else 67 | { 68 | 69 | require_once($dog_loc); 70 | $class_array = get_declared_classes(); 71 | $last_position = count($class_array) - 1; 72 | $class_name = $class_array[$last_position]; 73 | $dog_object = new $class_name($properties_array); 74 | 75 | return $dog_object; 76 | } 77 | 78 | } 79 | 80 | } 81 | 82 | ?> -------------------------------------------------------------------------------- /Chapter 8/e5dog_container.php: -------------------------------------------------------------------------------- 1 | app = $value; 14 | } 15 | else 16 | { 17 | exit; 18 | } 19 | } 20 | 21 | public function set_app($value) 22 | { 23 | $this->app = $value; 24 | } 25 | 26 | public function get_dog_application($search_value) 27 | { 28 | 29 | $xmlDoc = new DOMDocument(); 30 | 31 | if ( file_exists("edog_applications.xml") ) 32 | 33 | { 34 | $xmlDoc->load( 'edog_applications.xml' ); 35 | 36 | $searchNode = $xmlDoc->getElementsByTagName( "type" ); 37 | 38 | foreach( $searchNode as $searchNode ) 39 | { 40 | $valueID = $searchNode->getAttribute('ID'); 41 | 42 | if($valueID == $search_value) 43 | { 44 | 45 | $xmlLocation = $searchNode->getElementsByTagName( "location" ); 46 | return $xmlLocation->item(0)->nodeValue; 47 | break; 48 | 49 | } 50 | 51 | } 52 | } 53 | throw new Exception("Dog applications xml file missing or corrupt"); 54 | // return FALSE; 55 | } 56 | function create_object($properties_array) 57 | { 58 | 59 | $dog_loc = $this->get_dog_application($this->app); 60 | if(($dog_loc == FALSE) || (!file_exists($dog_loc))) 61 | { 62 | 63 | throw new Exception("File $dog_loc missing or corrupt."); 64 | // return FALSE; 65 | } 66 | else 67 | { 68 | 69 | require_once($dog_loc); 70 | $class_array = get_declared_classes(); 71 | $last_position = count($class_array) - 1; 72 | $class_name = $class_array[$last_position]; 73 | $dog_object = new $class_name($properties_array); 74 | 75 | return $dog_object; 76 | } 77 | 78 | } 79 | 80 | } 81 | 82 | ?> -------------------------------------------------------------------------------- /Chapter 9/e5dog_container.php: -------------------------------------------------------------------------------- 1 | app = $value; 14 | } 15 | else 16 | { 17 | exit; 18 | } 19 | } 20 | 21 | public function set_app($value) 22 | { 23 | $this->app = $value; 24 | } 25 | 26 | public function get_dog_application($search_value) 27 | { 28 | 29 | $xmlDoc = new DOMDocument(); 30 | 31 | if ( file_exists("edog_applications.xml") ) 32 | 33 | { 34 | $xmlDoc->load( 'edog_applications.xml' ); 35 | 36 | $searchNode = $xmlDoc->getElementsByTagName( "type" ); 37 | 38 | foreach( $searchNode as $searchNode ) 39 | { 40 | $valueID = $searchNode->getAttribute('ID'); 41 | 42 | if($valueID == $search_value) 43 | { 44 | 45 | $xmlLocation = $searchNode->getElementsByTagName( "location" ); 46 | return $xmlLocation->item(0)->nodeValue; 47 | break; 48 | 49 | } 50 | 51 | } 52 | } 53 | throw new Exception("Dog applications xml file missing or corrupt"); 54 | // return FALSE; 55 | } 56 | function create_object($properties_array) 57 | { 58 | 59 | $dog_loc = $this->get_dog_application($this->app); 60 | if(($dog_loc == FALSE) || (!file_exists($dog_loc))) 61 | { 62 | 63 | throw new Exception("File $dog_loc missing or corrupt."); 64 | // return FALSE; 65 | } 66 | else 67 | { 68 | 69 | require_once($dog_loc); 70 | $class_array = get_declared_classes(); 71 | $last_position = count($class_array) - 1; 72 | $class_name = $class_array[$last_position]; 73 | $dog_object = new $class_name($properties_array); 74 | 75 | return $dog_object; 76 | } 77 | 78 | } 79 | 80 | } 81 | 82 | ?> -------------------------------------------------------------------------------- /Chapter 4/e10dog.php: -------------------------------------------------------------------------------- 1 | dog_name = $value : $error_message = FALSE; 15 | return $error_message; 16 | } 17 | function set_dog_weight($value) 18 | { 19 | $error_message = TRUE; 20 | (ctype_digit($value) && ($value > 0 && $value <= 120)) ? $this->dog_weight = $value : $error_message = FALSE; 21 | return $error_message; 22 | } 23 | function set_dog_breed($value) 24 | { 25 | $error_message = TRUE; 26 | (ctype_alpha($value) && strlen($value) <= 35) ? $this->dog_breed = $value : $error_message = FALSE; 27 | return $error_message; 28 | } 29 | function set_dog_color($value) 30 | { 31 | $error_message = TRUE; 32 | (ctype_alpha($value) && strlen($value) <= 15) ? $this->dog_color = $value : $error_message = FALSE; 33 | return $error_message; 34 | } 35 | // ----------------------------------------- Get Methods ------------------------------------------------------------ 36 | function get_dog_name() 37 | { 38 | return $this->dog_name; 39 | } 40 | function get_dog_weight() 41 | { 42 | return $this->dog_weight; 43 | } 44 | function get_dog_breed() 45 | { 46 | return $this->dog_breed; 47 | } 48 | function get_dog_color() 49 | { 50 | return $this->dog_color; 51 | } 52 | function get_properties() 53 | { 54 | return "$this->dog_weight,$this->dog_breed,$this->dog_color."; 55 | } 56 | } 57 | ?> -------------------------------------------------------------------------------- /Chapter 5/e6validator.js: -------------------------------------------------------------------------------- 1 | function allalphabetic(the_string) 2 | { 3 | 4 | var letters = /^[a-zA-Z ]+$/; 5 | 6 | if (the_string.match(letters)) 7 | { 8 | 9 | return true; 10 | 11 | } 12 | else 13 | { 14 | 15 | return false; 16 | } 17 | } 18 | 19 | function validate_dog_name(the_string) 20 | { 21 | 22 | if ((the_string.length > 0) && (allalphabetic(the_string)) && (the_string.length <= 20)) 23 | { 24 | 25 | 26 | return true; 27 | } 28 | else 29 | { 30 | 31 | return false; 32 | } 33 | } 34 | 35 | function validate_dog_breed(the_string) 36 | { 37 | 38 | if (the_string == "Select a dog breed") 39 | { 40 | 41 | return false; 42 | } 43 | else 44 | { 45 | 46 | return true; 47 | } 48 | } 49 | 50 | function validate_dog_weight(the_string) 51 | { 52 | if ((the_string > 0 && the_string <=120) && (!isNaN(the_string))) 53 | { 54 | 55 | return true; 56 | } 57 | else 58 | { 59 | 60 | return false; 61 | } 62 | } 63 | 64 | function validate_input(form) 65 | { 66 | var error_message = ""; 67 | 68 | 69 | if (!validate_dog_name(form.dog_name.value)) 70 | { 71 | 72 | error_message += "Invalid dog name. "; 73 | 74 | } 75 | 76 | 77 | if (!validate_dog_breed(form.dog_breed.value)) 78 | { 79 | 80 | error_message += "Invalid dog breed. "; 81 | } 82 | 83 | 84 | if (!validate_dog_weight(form.dog_weight.value)) 85 | { 86 | 87 | error_message += "Invalid dog weight. "; 88 | } 89 | 90 | if (error_message.length > 0) 91 | { 92 | 93 | alert(error_message); 94 | return false; 95 | 96 | } 97 | else 98 | { 99 | return true; 100 | } 101 | 102 | } -------------------------------------------------------------------------------- /Chapter 6/evalidator.js: -------------------------------------------------------------------------------- 1 | 0) && (allalphabetic(the_string)) && (the_string.length <= 20)) 23 | { 24 | 25 | 26 | return true; 27 | } 28 | else 29 | { 30 | 31 | return false; 32 | } 33 | } 34 | 35 | function validate_dog_breed(the_string) 36 | { 37 | 38 | if (the_string == "Select a dog breed") 39 | { 40 | 41 | return false; 42 | } 43 | else 44 | { 45 | 46 | return true; 47 | } 48 | } 49 | 50 | function validate_dog_weight(the_string) 51 | { 52 | if ((the_string > 0 && the_string <=120) && (!isNaN(the_string))) 53 | { 54 | 55 | return true; 56 | } 57 | else 58 | { 59 | 60 | return false; 61 | } 62 | } 63 | 64 | function validate_input(form) 65 | { 66 | var error_message = ""; 67 | 68 | 69 | if (!validate_dog_name(form.dog_name.value)) 70 | { 71 | 72 | error_message += "Invalid dog name. "; 73 | 74 | } 75 | 76 | 77 | if (!validate_dog_breed(form.dog_breed.value)) 78 | { 79 | 80 | error_message += "Invalid dog breed. "; 81 | } 82 | 83 | 84 | if (!validate_dog_weight(form.dog_weight.value)) 85 | { 86 | 87 | error_message += "Invalid dog weight. "; 88 | } 89 | 90 | if (error_message.length > 0) 91 | { 92 | 93 | alert(error_message); 94 | return false; 95 | 96 | } 97 | else 98 | { 99 | return true; 100 | } 101 | 102 | } -------------------------------------------------------------------------------- /Chapter 7/evalidator.js: -------------------------------------------------------------------------------- 1 | function allalphabetic(the_string) 2 | { 3 | 4 | var letters = /^[a-zA-Z ]+$/; 5 | 6 | if (the_string.match(letters)) 7 | { 8 | 9 | return true; 10 | 11 | } 12 | else 13 | { 14 | 15 | return false; 16 | } 17 | } 18 | 19 | function validate_dog_name(the_string) 20 | { 21 | 22 | if ((the_string.length > 0) && (allalphabetic(the_string)) && (the_string.length <= 20)) 23 | { 24 | 25 | 26 | return true; 27 | } 28 | else 29 | { 30 | 31 | return false; 32 | } 33 | } 34 | 35 | function validate_dog_breed(the_string) 36 | { 37 | 38 | if (the_string == "Select a dog breed") 39 | { 40 | 41 | return false; 42 | } 43 | else 44 | { 45 | 46 | return true; 47 | } 48 | } 49 | 50 | function validate_dog_weight(the_string) 51 | { 52 | if ((the_string > 0 && the_string <=120) && (!isNaN(the_string))) 53 | { 54 | 55 | return true; 56 | } 57 | else 58 | { 59 | 60 | return false; 61 | } 62 | } 63 | 64 | function validate_input(form) 65 | { 66 | var error_message = ""; 67 | 68 | 69 | if (!validate_dog_name(form.dog_name.value)) 70 | { 71 | 72 | error_message += "Invalid dog name. "; 73 | 74 | } 75 | 76 | 77 | if (!validate_dog_breed(form.dog_breed.value)) 78 | { 79 | 80 | error_message += "Invalid dog breed. "; 81 | } 82 | 83 | 84 | if (!validate_dog_weight(form.dog_weight.value)) 85 | { 86 | 87 | error_message += "Invalid dog weight. "; 88 | } 89 | 90 | if (error_message.length > 0) 91 | { 92 | 93 | alert(error_message); 94 | return false; 95 | 96 | } 97 | else 98 | { 99 | return true; 100 | } 101 | 102 | } -------------------------------------------------------------------------------- /Chapter 8/evalidator.js: -------------------------------------------------------------------------------- 1 | function allalphabetic(the_string) 2 | { 3 | 4 | var letters = /^[a-zA-Z ]+$/; 5 | 6 | if (the_string.match(letters)) 7 | { 8 | 9 | return true; 10 | 11 | } 12 | else 13 | { 14 | 15 | return false; 16 | } 17 | } 18 | 19 | function validate_dog_name(the_string) 20 | { 21 | 22 | if ((the_string.length > 0) && (allalphabetic(the_string)) && (the_string.length <= 20)) 23 | { 24 | 25 | 26 | return true; 27 | } 28 | else 29 | { 30 | 31 | return false; 32 | } 33 | } 34 | 35 | function validate_dog_breed(the_string) 36 | { 37 | 38 | if (the_string == "Select a dog breed") 39 | { 40 | 41 | return false; 42 | } 43 | else 44 | { 45 | 46 | return true; 47 | } 48 | } 49 | 50 | function validate_dog_weight(the_string) 51 | { 52 | if ((the_string > 0 && the_string <=120) && (!isNaN(the_string))) 53 | { 54 | 55 | return true; 56 | } 57 | else 58 | { 59 | 60 | return false; 61 | } 62 | } 63 | 64 | function validate_input(form) 65 | { 66 | var error_message = ""; 67 | 68 | 69 | if (!validate_dog_name(form.dog_name.value)) 70 | { 71 | 72 | error_message += "Invalid dog name. "; 73 | 74 | } 75 | 76 | 77 | if (!validate_dog_breed(form.dog_breed.value)) 78 | { 79 | 80 | error_message += "Invalid dog breed. "; 81 | } 82 | 83 | 84 | if (!validate_dog_weight(form.dog_weight.value)) 85 | { 86 | 87 | error_message += "Invalid dog weight. "; 88 | } 89 | 90 | if (error_message.length > 0) 91 | { 92 | 93 | alert(error_message); 94 | return false; 95 | 96 | } 97 | else 98 | { 99 | return true; 100 | } 101 | 102 | } -------------------------------------------------------------------------------- /Chapter 9/evalidator.js .js: -------------------------------------------------------------------------------- 1 | function allalphabetic(the_string) 2 | { 3 | 4 | var letters = /^[a-zA-Z ]+$/; 5 | 6 | if (the_string.match(letters)) 7 | { 8 | 9 | return true; 10 | 11 | } 12 | else 13 | { 14 | 15 | return false; 16 | } 17 | } 18 | 19 | function validate_dog_name(the_string) 20 | { 21 | 22 | if ((the_string.length > 0) && (allalphabetic(the_string)) && (the_string.length <= 20)) 23 | { 24 | 25 | 26 | return true; 27 | } 28 | else 29 | { 30 | 31 | return false; 32 | } 33 | } 34 | 35 | function validate_dog_breed(the_string) 36 | { 37 | 38 | if (the_string == "Select a dog breed") 39 | { 40 | 41 | return false; 42 | } 43 | else 44 | { 45 | 46 | return true; 47 | } 48 | } 49 | 50 | function validate_dog_weight(the_string) 51 | { 52 | if ((the_string > 0 && the_string <=120) && (!isNaN(the_string))) 53 | { 54 | 55 | return true; 56 | } 57 | else 58 | { 59 | 60 | return false; 61 | } 62 | } 63 | 64 | function validate_input(form) 65 | { 66 | var error_message = ""; 67 | 68 | 69 | if (!validate_dog_name(form.dog_name.value)) 70 | { 71 | 72 | error_message += "Invalid dog name. "; 73 | 74 | } 75 | 76 | 77 | if (!validate_dog_breed(form.dog_breed.value)) 78 | { 79 | 80 | error_message += "Invalid dog breed. "; 81 | } 82 | 83 | 84 | if (!validate_dog_weight(form.dog_weight.value)) 85 | { 86 | 87 | error_message += "Invalid dog weight. "; 88 | } 89 | 90 | if (error_message.length > 0) 91 | { 92 | 93 | alert(error_message); 94 | return false; 95 | 96 | } 97 | else 98 | { 99 | return true; 100 | } 101 | 102 | } -------------------------------------------------------------------------------- /Chapter 4/e13lab.php: -------------------------------------------------------------------------------- 1 | ' : 'Name update not successful
'; 8 | print $breed_error == 'TRUE' ? 'Breed update successful
' : 'Breed update not successful
'; 9 | print $color_error == 'TRUE' ? 'Color update successful
' : 'Color update not successful
'; 10 | print $weight_error == 'TRUE' ? 'Weight update successful
' : 'Weight update not successful
'; 11 | 12 | // ------------------------------Set Properties-------------------------- 13 | $dog_error_message = $lab->set_dog_name('Sally'); 14 | print $dog_error_message == TRUE ? 'Name update successful
' : 'Name update not successful
'; 15 | 16 | $dog_error_message = $lab->set_dog_weight('5'); 17 | print $dog_error_message == TRUE ? 'Weight update successful
' : 'Weight update not successful
'; 18 | 19 | $dog_error_message = $lab->set_dog_breed('Labrador'); 20 | print $dog_error_message == TRUE ? 'Breed update successful
' : 'Breed update not successful
'; 21 | 22 | $dog_error_message = $lab->set_dog_color('Brown'); 23 | print $dog_error_message == TRUE ? 'Color update successful
' : 'Color update not successful
'; 24 | // ------------------------------Get Properties-------------------------- 25 | print $lab->get_dog_name() . "
"; 26 | print $lab->get_dog_weight() . "
"; 27 | print $lab->get_dog_breed() . "
"; 28 | print $lab->get_dog_color() . "
"; 29 | $dog_properties = $lab->get_properties(); 30 | list($dog_weight, $dog_breed, $dog_color) = explode(',', $dog_properties); 31 | print "Dog weight is $dog_weight. Dog breed is $dog_breed. Dog color is $dog_color."; 32 | ?> -------------------------------------------------------------------------------- /Chapter 6/e8readerrorlog.php: -------------------------------------------------------------------------------- 1 | "; 33 | echo ""; 34 | echo ""; 35 | echo ""; 36 | echo ""; 37 | echo ""; 38 | 39 | for ($J=$row_Count; $J >= 0; $J--) 40 | { 41 | echo ""; 42 | 43 | for($I=0; $I < 3; $I++) 44 | { 45 | echo " "; 46 | } 47 | echo ""; 48 | } 49 | echo "
Log File: " . ERROR_LOG . "
Date/TimeError TypeError Message
Delete " . $error_Array[$J][$I] . "
"; 50 | echo ""; 51 | } 52 | 53 | const ERROR_LOG = "Errors.log"; 54 | 55 | $logFile = fopen(ERROR_LOG, "r"); 56 | $row_Count = 0; 57 | while(!feof($logFile)) 58 | { 59 | $error_Array[$row_Count] = explode(' | ', fgets($logFile)); 60 | $row_Count++; 61 | } 62 | $row_Count--; 63 | fclose($logFile); 64 | 65 | if(isset($_GET['rn'])) 66 | { 67 | 68 | deleteRecord($_GET['rn'], $row_Count, $error_Array); 69 | saveChanges($row_Count,$error_Array,ERROR_LOG); 70 | } 71 | 72 | displayRecords($row_Count,$error_Array); 73 | 74 | ?> -------------------------------------------------------------------------------- /Chapter 9/e5changepassword.php: -------------------------------------------------------------------------------- 1 | 2 | ABC Canine Shelter Reservation System 3 | 4 | 7 | 8 | 9 |
10 | 12 |
13 |
14 | Userid must contain eight or more characters.
15 | Password must contain at least one number, one uppercase and lowercase letter, and at least 8 total characters.
16 | Username:
17 | Old Password:
19 | New Password:
21 | Confirm Password: 22 | 32 | 33 |
34 |
35 | 36 |
37 | -------------------------------------------------------------------------------- /Chapter 5/e2validator.js: -------------------------------------------------------------------------------- 1 | function allalphabetic(the_string) 2 | { 3 | 4 | var letters = /^[a-zA-Z ]+$/; 5 | 6 | if (the_string.match(letters)) 7 | { 8 | 9 | return true; 10 | 11 | } 12 | else 13 | { 14 | 15 | return false; 16 | } 17 | } 18 | 19 | function validate_dog_name(the_string) 20 | { 21 | 22 | if ((the_string.length > 0) && (allalphabetic(the_string)) && (the_string.length <= 20)) 23 | { 24 | 25 | 26 | return true; 27 | } 28 | else 29 | { 30 | return false; 31 | } 32 | } 33 | 34 | function validate_dog_breed_color(the_string) 35 | { 36 | 37 | if ((the_string.length > 0) && (allalphabetic(the_string)) && (the_string.length <= 35)) 38 | { 39 | 40 | return true; 41 | } 42 | else 43 | { 44 | 45 | return false; 46 | } 47 | } 48 | 49 | function validate_dog_weight(the_string) 50 | { 51 | if ((the_string > 0 && the_string <=120) && (!isNaN(the_string))) 52 | { 53 | 54 | return true; 55 | } 56 | else 57 | { 58 | 59 | return false; 60 | } 61 | } 62 | 63 | function validate_input(form) 64 | { 65 | var error_message = ""; 66 | 67 | if (!validate_dog_name(form.dog_name.value)) 68 | { 69 | 70 | error_message += "Invalid dog name. "; 71 | } 72 | 73 | if (!validate_dog_breed_color(form.dog_breed.value)) 74 | { 75 | 76 | error_message += "Invalid dog breed. "; 77 | } 78 | 79 | if (!validate_dog_breed_color(form.dog_color.value)) 80 | { 81 | error_message += "Invalid dog color. "; 82 | } 83 | 84 | if (!validate_dog_weight(form.dog_weight.value)) 85 | { 86 | 87 | error_message += "Invalid dog weight. "; 88 | } 89 | if (error_message.length > 0) 90 | { 91 | 92 | alert(error_message); 93 | return false; 94 | 95 | } 96 | else 97 | { 98 | return true; 99 | } 100 | 101 | } -------------------------------------------------------------------------------- /Chapter 5/e3ande4lab.php: -------------------------------------------------------------------------------- 1 | ", "/", "$"); 12 | $value = str_ireplace($bad_chars,"",$value); 13 | if (get_magic_quotes_gpc()) 14 | { 15 | $value = stripslashes($value); 16 | 17 | // Gets rid of unwanted slashes 18 | } 19 | $value = htmlentities($value); 20 | 21 | // Removes any html from the string and turns it into < format 22 | $value = strip_tags($value); 23 | 24 | return $value; 25 | 26 | } 27 | 28 | if ((isset($_POST['dog_name'])) && (isset($_POST['dog_breed'])) && (isset($_POST['dog_color'])) && (isset($_POST['dog_weight']))) 29 | { 30 | 31 | $dog_name = clean_input($_POST['dog_name']); 32 | $dog_breed = clean_input($_POST['dog_breed']); 33 | $dog_color = clean_input($_POST['dog_color']); 34 | $dog_weight = clean_input($_POST['dog_weight']); 35 | 36 | $lab = new Dog($dog_name,$dog_breed,$dog_color,$dog_weight); 37 | 38 | list($name_error, $breed_error, $color_error, $weight_error) = explode(',', $lab); 39 | 40 | print $name_error == 'TRUE' ? 'Name update successful
' : 'Name update not successful
'; 41 | print $breed_error == 'TRUE' ? 'Breed update successful
' : 'Breed update not successful
'; 42 | print $color_error == 'TRUE' ? 'Color update successful
' : 'Color update not successful
'; 43 | print $weight_error == 'TRUE' ? 'Weight update successful
' : 'Weight update not successful
'; 44 | 45 | $dog_properties = $lab->get_properties(); 46 | list($dog_weight, $dog_breed, $dog_color) = explode(',', $dog_properties); 47 | print "Dog weight is $dog_weight. Dog breed is $dog_breed. Dog color is $dog_color."; 48 | } 49 | 50 | else 51 | { 52 | 53 | print "

Missing or invalid parameters. Please go back to the lab.html page to enter valid information.
"; 54 | 55 | print "Dog Creation Page"; 56 | 57 | } 58 | ?> -------------------------------------------------------------------------------- /Chapter 5/e0dog.php: -------------------------------------------------------------------------------- 1 | set_dog_name($value1) == TRUE ? 'TRUE,' : 'FALSE,'; 13 | $breed_error = $this->set_dog_breed($value2) == TRUE ? 'TRUE,' : 'FALSE,'; 14 | $color_error = $this->set_dog_color($value3) == TRUE ? 'TRUE,' : 'FALSE,'; 15 | $weight_error= $this->set_dog_weight($value4) == TRUE ? 'TRUE' : 'FALSE'; 16 | $this->error_message = $name_error . $breed_error . $color_error . $weight_error; 17 | } 18 | //------------------------------------toString-------------------------------------------------- 19 | public function __toString() 20 | { 21 | return $this->error_message; 22 | } 23 | 24 | // ---------------------------------- Set Methods ---------------------------------------------- 25 | function set_dog_name($value) 26 | { 27 | $error_message = TRUE; 28 | (ctype_alpha($value) && strlen($value) <= 20) ? $this->dog_name = $value : $error_message = FALSE; 29 | return $error_message; 30 | } 31 | function set_dog_weight($value) 32 | { 33 | $error_message = TRUE; 34 | (ctype_digit($value) && ($value > 0 && $value <= 120)) ? $this->dog_weight = $value : $error_message = FALSE; 35 | return $error_message; 36 | } 37 | function set_dog_breed($value) 38 | { 39 | $error_message = TRUE; 40 | (ctype_alpha($value) && strlen($value) <= 35) ? $this->dog_breed = $value : $error_message = FALSE; 41 | return $error_message; 42 | } 43 | function set_dog_color($value) 44 | { 45 | $error_message = TRUE; 46 | (ctype_alpha($value) && strlen($value) <= 15) ? $this->dog_color = $value : $error_message = FALSE; 47 | return $error_message; 48 | } 49 | // ----------------------------------------- Get Methods ------------------------------------------------------------ 50 | function get_dog_name() 51 | { 52 | return $this->dog_name; 53 | } 54 | function get_dog_weight() 55 | { 56 | return $this->dog_weight; 57 | } 58 | function get_dog_breed() 59 | { 60 | return $this->dog_breed; 61 | } 62 | function get_dog_color() 63 | { 64 | return $this->dog_color; 65 | } 66 | function get_properties() 67 | { 68 | return "$this->dog_weight,$this->dog_breed,$this->dog_color."; 69 | } 70 | } 71 | ?> -------------------------------------------------------------------------------- /Chapter 5/e1lab.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Dog Object 6 | 7 | 8 | 13 | 14 | 21 | 22 | 23 | 24 | 25 |

Dog Object Creater

26 |
27 |
28 |

Please complete ALL fields. Please note the required format of information.

29 | Your Dog's Name (max 20 characters, alphabetic)
30 | Your Dog's Breed (max 35 characters, alphabetic)
31 | Your Dog's Color (max 15 characters, alphabetic)
32 | Your Dog's Weight (numeric only)
33 | 34 |
35 |
36 | 48 | 49 | -------------------------------------------------------------------------------- /Chapter 4/e12dog.php: -------------------------------------------------------------------------------- 1 | set_dog_name($value1) == TRUE ? 'TRUE,' : 'FALSE,'; 15 | $breed_error = $this->set_dog_breed($value2) == TRUE ? 'TRUE,' : 'FALSE,'; 16 | $color_error = $this->set_dog_color($value3) == TRUE ? 'TRUE,' : 'FALSE,'; 17 | $weight_error= $this->set_dog_weight($value4) == TRUE ? 'TRUE' : 'FALSE'; 18 | 19 | $this->error_message = $name_error . $breed_error . $color_error . $weight_error; 20 | 21 | } 22 | //------------------------------------toString-------------------------------------------------- 23 | public function __toString() 24 | { 25 | return $this->error_message; 26 | } 27 | 28 | // ---------------------------------- Set Methods ---------------------------------------------- 29 | function set_dog_name($value) 30 | { 31 | $error_message = TRUE; 32 | (ctype_alpha($value) && strlen($value) <= 20) ? $this->dog_name = $value : $this->error_message = FALSE; 33 | return $this->error_message; 34 | } 35 | function set_dog_weight($value) 36 | { 37 | $error_message = TRUE; 38 | (ctype_digit($value) && ($value > 0 && $value <= 120)) ? $this->dog_weight = $value : $this->error_message = FALSE; 39 | return $this->error_message; 40 | } 41 | function set_dog_breed($value) 42 | { 43 | $error_message = TRUE; 44 | (ctype_alpha($value) && strlen($value) <= 35) ? $this->dog_breed = $value : $error_message = FALSE; 45 | return $this->error_message; 46 | } 47 | function set_dog_color($value) 48 | { 49 | $error_message = TRUE; 50 | (ctype_alpha($value) && strlen($value) <= 15) ? $this->dog_color = $value : $this->error_message = FALSE; 51 | return $this->error_message; 52 | } 53 | // ----------------------------------------- Get Methods ------------------------------------------------------------ 54 | function get_dog_name() 55 | { 56 | return $this->dog_name; 57 | } 58 | function get_dog_weight() 59 | { 60 | return $this->dog_weight; 61 | } 62 | function get_dog_breed() 63 | { 64 | return $this->dog_breed; 65 | } 66 | function get_dog_color() 67 | { 68 | return $this->dog_color; 69 | } 70 | function get_properties() 71 | { 72 | return "$this->dog_weight,$this->dog_breed,$this->dog_color."; 73 | } 74 | 75 | 76 | } 77 | ?> -------------------------------------------------------------------------------- /Chapter 5/e7ande8dog.php: -------------------------------------------------------------------------------- 1 | set_dog_name($value1) == TRUE ? 'TRUE,' : 'FALSE,'; 13 | $breed_error = $this->set_dog_breed($value2) == TRUE ? 'TRUE,' : 'FALSE,'; 14 | $color_error = $this->set_dog_color($value3) == TRUE ? 'TRUE,' : 'FALSE,'; 15 | $weight_error= $this->set_dog_weight($value4) == TRUE ? 'TRUE' : 'FALSE'; 16 | $this->error_message = $name_error . $breed_error . $color_error . $weight_error; 17 | } 18 | //------------------------------------toString-------------------------------------------------- 19 | public function __toString() 20 | { 21 | return $this->error_message; 22 | } 23 | // ----------------------------------General Methods-------------------------------------------- 24 | private function validator_breed($value) 25 | { 26 | $breed_file = simplexml_load_file("e5breeds.xml"); 27 | $xmlText = $breed_file->asXML(); 28 | 29 | if(stristr($xmlText, $value) === FALSE) 30 | { 31 | return FALSE; 32 | } 33 | else 34 | { 35 | return TRUE; 36 | } 37 | } 38 | 39 | // ---------------------------------- Set Methods ---------------------------------------------- 40 | function set_dog_name($value) 41 | { 42 | $error_message = TRUE; 43 | (ctype_alpha($value) && strlen($value) <= 20) ? $this->dog_name = $value : $error_message = FALSE; 44 | return $error_message; 45 | } 46 | function set_dog_weight($value) 47 | { 48 | $error_message = TRUE; 49 | (ctype_digit($value) && ($value > 0 && $value <= 120)) ? $this->dog_weight = $value : $error_message = FALSE; 50 | return $error_message; 51 | } 52 | function set_dog_breed($value) 53 | { 54 | $error_message = TRUE; 55 | ($this->validator_breed($value) === TRUE) ? $this->dog_breed = $value : $error_message = FALSE; 56 | return $error_message; 57 | } 58 | function set_dog_color($value) 59 | { 60 | $valid_array = array("Brown", "Black", "Yellow", "White", "Mixed"); 61 | $error_message = TRUE; 62 | (in_array($value, $valid_array) === TRUE) ? $this->dog_color = $value : $error_message = FALSE; 63 | return $error_message; 64 | } 65 | // ----------------------------------------- Get Methods ------------------------------------------------------------ 66 | function get_dog_name() 67 | { 68 | return $this->dog_name; 69 | } 70 | function get_dog_weight() 71 | { 72 | return $this->dog_weight; 73 | } 74 | function get_dog_breed() 75 | { 76 | return $this->dog_breed; 77 | } 78 | function get_dog_color() 79 | { 80 | return $this->dog_color; 81 | } 82 | function get_properties() 83 | { 84 | return "$this->dog_weight,$this->dog_breed,$this->dog_color."; 85 | } 86 | } 87 | ?> -------------------------------------------------------------------------------- /Chapter 8/e2login.php: -------------------------------------------------------------------------------- 1 | load( 'edog_applications.xml' ); 14 | $searchNode = $xmlDoc->getElementsByTagName( "type" ); 15 | 16 | foreach( $searchNode as $searchNode ) 17 | { 18 | $valueID = $searchNode->getAttribute('ID'); 19 | 20 | if($valueID == "UIDPASS") 21 | { 22 | 23 | $xmlLocation = $searchNode->getElementsByTagName( "location" ); 24 | $dog_data_xml = $xmlLocation->item(0)->nodeValue; 25 | 26 | break; 27 | } 28 | 29 | } 30 | } 31 | else 32 | { 33 | throw new Exception("Dog applications xml file missing or corrupt"); 34 | } 35 | $xmlfile = file_get_contents($dog_data_xml); 36 | $xmlstring = simplexml_load_string($xmlfile); 37 | 38 | if ($xmlstring === false) { 39 | $errorString = "Failed loading XML: "; 40 | foreach(libxml_get_errors() as $error) { 41 | $errorString .= $error->message . " " ; } 42 | throw new Exception($errorString); } 43 | $json = json_encode($xmlstring); 44 | 45 | $valid_useridpasswords = json_decode($json,TRUE); 46 | // …… code to verify userid and password …. 47 | $userid = $_POST['username']; 48 | $password = $_POST['password']; 49 | 50 | foreach($valid_useridpasswords as $users) 51 | { 52 | foreach($users as $user) 53 | { 54 | $hash = $user['password']; 55 | if((in_array($userid, $user)) && (password_verify($password,$hash))) 56 | { 57 | 58 | $_SESSION['username'] = $userid; 59 | $_SESSION['password'] = $password; 60 | $login_string = date('mdYhis') . " | Login | " . $userid . "\n"; 61 | error_log($login_string,3,$user_log_file); 62 | header("Location: e71lab.php"); 63 | } 64 | } 65 | } 66 | } 67 | } 68 | catch(Exception $e) 69 | { 70 | 71 | echo $e->getMessage(); 72 | } 73 | // code below executes if the user has not logged in or if it is an invalid login. 74 | ?> 75 |
76 | Userid must contain eight or more characters.
77 | Password must contain at least one number, one uppercase and lowercase letter, and at least 8 total characters.
78 | Username:
79 | Password:
81 | 82 |
-------------------------------------------------------------------------------- /Chapter 8/e3registration.php: -------------------------------------------------------------------------------- 1 | = 8))) 13 | { 14 | throw new Exception("Invalid Userid and/or Password Format"); 15 | } 16 | else 17 | { 18 | 19 | $hashed_password = password_hash($password, PASSWORD_DEFAULT); 20 | 21 | 22 | 23 | 24 | libxml_use_internal_errors(true); 25 | $xmlDoc = new DOMDocument(); 26 | if ( file_exists("edog_applications.xml") ) 27 | { 28 | $xmlDoc->load( 'edog_applications.xml' ); 29 | $searchNode = $xmlDoc->getElementsByTagName( "type" ); 30 | 31 | foreach( $searchNode as $searchNode ) 32 | { 33 | $valueID = $searchNode->getAttribute('ID'); 34 | 35 | if($valueID == "UIDPASS") 36 | { 37 | 38 | $xmlLocation = $searchNode->getElementsByTagName( "location" ); 39 | $dog_data_xml = $xmlLocation->item(0)->nodeValue; 40 | 41 | break; 42 | } 43 | 44 | } 45 | } 46 | else 47 | { 48 | throw new Exception("Dog applications xml file missing or corrupt"); 49 | } 50 | $newupstring = "\n" . $userid . "\n" . $hashed_password . "\n"; 51 | $newupstring .= "" . date('Y-m-d', strtotime('+30 days')) . "\n"; 52 | $newupstring .= "0\n" . date('mdYhis') . "\n"; 53 | $newupstring .= "" . date('mdYhis') . "\n\n"; 54 | 55 | $input = file_get_contents($dog_data_xml); 56 | 57 | $find = ""; 58 | $find_q = preg_quote($find,'/'); 59 | $output = preg_replace("/^$find_q(\n|\$)/m","",$input); 60 | 61 | $output = $output . $newupstring; 62 | 63 | file_put_contents($dog_data_xml,$output); 64 | 65 | $login_string = date('mdYhis') . " | New Userid | " . $userid . "\n"; 66 | error_log($login_string,3,$user_log_file); 67 | header("Location: e2login.php"); 68 | 69 | } 70 | } 71 | } 72 | 73 | catch(Exception $e) 74 | { 75 | 76 | echo $e->getMessage(); 77 | } 78 | 79 | ?> 80 |
81 | Userid must contain eight or more characters.
82 | Password must contain at least one number, one uppercase and lowercase letter, and at least 8 total characters.
83 | Username:
84 | Password:
86 | 87 |
-------------------------------------------------------------------------------- /Chapter 8/e4registration.php: -------------------------------------------------------------------------------- 1 | = 8))) 13 | { 14 | throw new Exception("Invalid Userid and/or Password Format"); 15 | } 16 | else 17 | { 18 | 19 | $hashed_password = password_hash($password, PASSWORD_DEFAULT); 20 | 21 | 22 | 23 | 24 | libxml_use_internal_errors(true); 25 | $xmlDoc = new DOMDocument(); 26 | if ( file_exists("edog_applications.xml") ) 27 | { 28 | $xmlDoc->load( 'edog_applications.xml' ); 29 | $searchNode = $xmlDoc->getElementsByTagName( "type" ); 30 | 31 | foreach( $searchNode as $searchNode ) 32 | { 33 | $valueID = $searchNode->getAttribute('ID'); 34 | 35 | if($valueID == "UIDPASS") 36 | { 37 | 38 | $xmlLocation = $searchNode->getElementsByTagName( "location" ); 39 | $dog_data_xml = $xmlLocation->item(0)->nodeValue; 40 | 41 | break; 42 | } 43 | 44 | } 45 | } 46 | else 47 | { 48 | throw new Exception("Dog applications xml file missing or corrupt"); 49 | } 50 | $newupstring = "\n" . $userid . "\n" . $hashed_password . "\n"; 51 | $newupstring .= "" . date('Y-m-d', strtotime('+30 days')) . "\n"; 52 | $newupstring .= "0\n" . date('mdYhis') . "\n"; 53 | $newupstring .= "" . date('mdYhis') . "\n\n"; 54 | 55 | $input = file_get_contents($dog_data_xml); 56 | 57 | $find = ""; 58 | $find_q = preg_quote($find,'/'); 59 | $output = preg_replace("/^$find_q(\n|\$)/m","",$input); 60 | 61 | $output = $output . $newupstring; 62 | 63 | file_put_contents($dog_data_xml,$output); 64 | 65 | $login_string = date('mdYhis') . " | New Userid | " . $userid . "\n"; 66 | error_log($login_string,3,$user_log_file); 67 | header("Location: e4login.php"); 68 | 69 | } 70 | } 71 | } 72 | 73 | catch(Exception $e) 74 | { 75 | 76 | echo $e->getMessage(); 77 | } 78 | 79 | ?> 80 |
81 | Userid must contain eight or more characters.
82 | Password must contain at least one number, one uppercase and lowercase letter, and at least 8 total characters.
83 | Username:
84 | Password:
86 | 87 |
-------------------------------------------------------------------------------- /Chapter 5/e6lab.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Dog Object 5 | 6 | 7 | 12 | 13 | 20 | 21 | 22 | 23 | 24 |

Dog Object Creater

25 |
26 |
27 |

Please complete ALL fields. Please note the required format of information.

28 | Enter Your Dog's Name (max 20 characters, alphabetic)

29 | Select Your Dog's Color:
30 | Brown
31 | Black
32 | Yellow
33 | White
34 | Mixed

35 | 36 | Enter Your Dog's Weight (numeric only)

37 | 40 |

41 | 42 |
43 |
44 | 62 | 63 | -------------------------------------------------------------------------------- /Chapter 6/e7lab.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Dog Object 5 | 6 | 7 | 12 | 13 | 20 | 21 | 22 | 23 | 24 |

Dog Object Creater

25 |
26 |
27 |

Please complete ALL fields. Please note the required format of information.

28 | Enter Your Dog's Name (max 20 characters, alphabetic)

29 | Select Your Dog's Color:
30 | Brown
31 | Black
32 | Yellow
33 | White
34 | Mixed

35 | 36 | Enter Your Dog's Weight (numeric only)

37 | 40 | 41 | Select Your Dog's Breed

42 | 43 |
44 |
45 | 63 | 64 | -------------------------------------------------------------------------------- /Chapter 6/elab.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Dog Object 5 | 6 | 7 | 12 | 13 | 20 | 21 | 22 | 23 | 24 |

Dog Object Creater

25 |
26 |
27 |

Please complete ALL fields. Please note the required format of information.

28 | Enter Your Dog's Name (max 20 characters, alphabetic)

29 | Select Your Dog's Color:
30 | Brown
31 | Black
32 | Yellow
33 | White
34 | Mixed

35 | 36 | Enter Your Dog's Weight (numeric only)

37 | 40 | 41 | Select Your Dog's Breed

42 | 43 |
44 |
45 | 63 | 64 | -------------------------------------------------------------------------------- /Chapter 7/e5lab.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Dog Object 5 | 6 | 7 | 12 | 13 | 20 | 21 | 22 | 23 | 24 |

Dog Object Creater

25 |
26 |
27 |

Please complete ALL fields. Please note the required format of information.

28 | Enter Your Dog's Name (max 20 characters, alphabetic)

29 | Select Your Dog's Color:
30 | Brown
31 | Black
32 | Yellow
33 | White
34 | Mixed

35 | 36 | Enter Your Dog's Weight (numeric only)

37 | 40 | 41 | Select Your Dog's Breed

42 | 43 |
44 |
45 | 63 | 64 | -------------------------------------------------------------------------------- /Chapter 5/e7lab.php: -------------------------------------------------------------------------------- 1 | ", "/", "$"); 13 | $value = str_ireplace($bad_chars,"",$value); 14 | if (get_magic_quotes_gpc()) 15 | { 16 | $value = stripslashes($value); 17 | 18 | // Gets rid of unwanted slashes 19 | } 20 | $value = htmlentities($value); 21 | 22 | // Removes any html from the string and turns it into < format 23 | $value = strip_tags($value); 24 | 25 | 26 | return $value; 27 | 28 | } 29 | 30 | if ((isset($_POST['dog_name'])) && (isset($_POST['dog_breed'])) && (isset($_POST['dog_color'])) && (isset($_POST['dog_weight']))) 31 | { 32 | 33 | $dog_name = clean_input($_POST['dog_name']); 34 | $dog_breed = clean_input($_POST['dog_breed']); 35 | $dog_color = clean_input($_POST['dog_color']); 36 | $dog_weight = clean_input($_POST['dog_weight']); 37 | 38 | 39 | 40 | $lab = new Dog($dog_name,$dog_breed,$dog_color,$dog_weight); 41 | 42 | list($name_error, $breed_error, $color_error, $weight_error) = explode(',', $lab); 43 | 44 | print $name_error == 'TRUE' ? 'Name update successful
' : 'Name update not successful
'; 45 | print $breed_error == 'TRUE' ? 'Breed update successful
' : 'Breed update not successful
'; 46 | print $color_error == 'TRUE' ? 'Color update successful
' : 'Color update not successful
'; 47 | print $weight_error == 'TRUE' ? 'Weight update successful
' : 'Weight update not successful
'; 48 | 49 | 50 | // ------------------------------Set Properties-------------------------- 51 | //$dog_error_message = $lab->set_dog_name('Sally'); 52 | //print $dog_error_message == TRUE ? 'Name update successful
' : 'Name update not successful
'; 53 | 54 | //$dog_error_message = $lab->set_dog_weight('5'); 55 | //print $dog_error_message == TRUE ? 'Weight update successful
' : 'Weight update not successful
'; 56 | 57 | //$dog_error_message = $lab->set_dog_breed('Labrador'); 58 | //print $dog_error_message == TRUE ? 'Breed update successful
' : 'Breed update not successful
'; 59 | 60 | //$dog_error_message = $lab->set_dog_color('Brown'); 61 | //print $dog_error_message == TRUE ? 'Color update successful
' : 'Color update not successful
'; 62 | // ------------------------------Get Properties-------------------------- 63 | //print $lab->get_dog_name() . "
"; 64 | //print $lab->get_dog_weight() . "
"; 65 | //print $lab->get_dog_breed() . "
"; 66 | //print $lab->get_dog_color() . "
"; 67 | $dog_properties = $lab->get_properties(); 68 | list($dog_weight, $dog_breed, $dog_color) = explode(',', $dog_properties); 69 | print "Dog weight is $dog_weight. Dog breed is $dog_breed. Dog color is $dog_color."; 70 | } 71 | 72 | else 73 | { 74 | 75 | print "

Missing or invalid parameters. Please go back to the lab.html page to enter valid information.
"; 76 | 77 | print "Dog Creation Page"; 78 | 79 | } 80 | ?> -------------------------------------------------------------------------------- /Chapter 5/e14lab.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Dog Object 5 | 6 | 7 | 12 | 13 | 20 | 21 | 22 | 23 | 24 |

Dog Object Creater

25 |
26 |
27 |

Please complete ALL fields. Please note the required format of information.

28 | Enter Your Dog's Name (max 20 characters, alphabetic)

29 | Select Your Dog's Color:
30 | Brown
31 | Black
32 | Yellow
33 | White
34 | Mixed

35 | 36 | Enter Your Dog's Weight (numeric only)

37 | 40 | 41 | Select Your Dog's Breed

42 | 43 |
44 |
45 | 63 | 64 | -------------------------------------------------------------------------------- /Chapter 9/e6readerrorlog.php: -------------------------------------------------------------------------------- 1 | ABC Canine Shelter Reservation System"; 34 | echo ""; 35 | 36 | echo ""; 38 | 39 | echo ""; 40 | echo "
"; 41 | echo ""; 42 | echo ""; 43 | echo ""; 44 | 45 | for ($J=$row_Count; $J >= 0; $J--) 46 | { 47 | echo ""; 48 | 49 | for($I=0; $I < 3; $I++) 50 | { 51 | echo " "; 52 | } 53 | echo ""; 54 | } 55 | echo "
Log File: " . ERROR_LOG . "
Date/TimeError TypeError Message
Delete " . $error_Array[$J][$I] . "
"; 56 | echo "
"; 57 | echo ""; 58 | } 59 | const ERROR_LOG = "Errors.log"; 60 | 61 | if ((!isset($_SESSION['username'])) || (!isset($_SESSION['password']))) { 62 | echo "ABC Canine Shelter Reservation System"; 63 | echo ""; 64 | echo "
"; 65 | echo "
"; 66 | echo "You must login to access the ABC Canine Shelter Reservation System"; 67 | echo "

"; 68 | echo "Login | Create an account"; 69 | echo "

"; 70 | echo "
"; 71 | echo ""; 72 | } 73 | else 74 | { 75 | 76 | $logFile = fopen(ERROR_LOG, "r"); 77 | $row_Count = 0; 78 | while(!feof($logFile)) 79 | { 80 | $error_Array[$row_Count] = explode(' | ', fgets($logFile)); 81 | $row_Count++; 82 | } 83 | $row_Count--; 84 | fclose($logFile); 85 | 86 | if(isset($_GET['rn'])) 87 | { 88 | 89 | deleteRecord($_GET['rn'], $row_Count, $error_Array); 90 | saveChanges($row_Count,$error_Array,ERROR_LOG); 91 | } 92 | 93 | displayRecords($row_Count,$error_Array); 94 | } 95 | ?> -------------------------------------------------------------------------------- /Chapter 5/e16dog.php: -------------------------------------------------------------------------------- 1 | breedxml = $properties_array[4]; 16 | $name_error = $this->set_dog_name($properties_array[0]) == TRUE ? 'TRUE,' : 'FALSE,'; 17 | $breed_error = $this->set_dog_breed($properties_array[1]) == TRUE ? 'TRUE,' : 'FALSE,'; 18 | $color_error = $this->set_dog_color($properties_array[2]) == TRUE ? 'TRUE,' : 'FALSE,'; 19 | $weight_error= $this->set_dog_weight($properties_array[3]) == TRUE ? 'TRUE' : 'FALSE'; 20 | 21 | $this->error_message = $name_error . $breed_error . $color_error . $weight_error; 22 | } 23 | else 24 | { 25 | exit; 26 | } 27 | } 28 | //------------------------------------toString-------------------------------------------------- 29 | public function __toString() 30 | { 31 | return $this->error_message; 32 | } 33 | 34 | 35 | // ---------------------------------- Set Methods ---------------------------------------------- 36 | function set_dog_name($value) 37 | { 38 | $error_message = TRUE; 39 | (ctype_alpha($value) && strlen($value) <= 20) ? $this->dog_name = $value : $this->error_message = FALSE; 40 | return $this->error_message; 41 | } 42 | function set_dog_weight($value) 43 | { 44 | $error_message = TRUE; 45 | (ctype_digit($value) && ($value > 0 && $value <= 120)) ? $this->dog_weight = $value : $this->error_message = FALSE; 46 | return $this->error_message; 47 | } 48 | function set_dog_breed($value) 49 | { 50 | $error_message = TRUE; 51 | ($this->validator_breed($value) === TRUE) ? $this->dog_breed = $value : $this->error_message = FALSE; 52 | return $this->error_message; 53 | } 54 | function set_dog_color($value) 55 | { 56 | $error_message = TRUE; 57 | (ctype_alpha($value) && strlen($value) <= 15) ? $this->dog_color = $value : $this->error_message = FALSE; 58 | return $this->error_message; 59 | } 60 | // ----------------------------------------- Get Methods ------------------------------------------------------------ 61 | function get_dog_name() 62 | { 63 | return $this->dog_name; 64 | } 65 | function get_dog_weight() 66 | { 67 | return $this->dog_weight; 68 | } 69 | function get_dog_breed() 70 | { 71 | return $this->dog_breed; 72 | } 73 | function get_dog_color() 74 | { 75 | return $this->dog_color; 76 | } 77 | function get_properties() 78 | { 79 | return "$this->dog_name,$this->dog_weight,$this->dog_breed,$this->dog_color."; 80 | } 81 | // ----------------------------------General Method--------------------------------------------- 82 | 83 | private function validator_breed($value) 84 | { 85 | 86 | $breed_file = simplexml_load_file($this->breedxml); 87 | $xmlText = $breed_file->asXML(); 88 | 89 | if(stristr($xmlText, $value) === FALSE) 90 | { 91 | return FALSE; 92 | } 93 | else 94 | { 95 | return TRUE; 96 | } 97 | } 98 | 99 | } 100 | ?> -------------------------------------------------------------------------------- /Chapter 7/e1dog_data.php: -------------------------------------------------------------------------------- 1 | load( 'e1dog_applications.xml' ); 12 | $searchNode = $xmlDoc->getElementsByTagName( "type" ); 13 | 14 | foreach( $searchNode as $searchNode ) 15 | { 16 | $valueID = $searchNode->getAttribute('ID'); 17 | 18 | if($valueID == "datastorage") 19 | { 20 | 21 | $xmlLocation = $searchNode->getElementsByTagName( "location" ); 22 | $this->dog_data_xml = $xmlLocation->item(0)->nodeValue; 23 | 24 | break; 25 | } 26 | 27 | } 28 | } 29 | else 30 | { 31 | throw new Exception("Dog applications xml file missing or corrupt"); 32 | } 33 | $xmlfile = file_get_contents($this->dog_data_xml); 34 | $xmlstring = simplexml_load_string($xmlfile); 35 | 36 | if ($xmlstring === false) { 37 | $errorString = "Failed loading XML: "; 38 | foreach(libxml_get_errors() as $error) { 39 | $errorString .= $error->message . " " ; } 40 | throw new Exception($errorString); } 41 | $json = json_encode($xmlstring); 42 | print_r($json); 43 | 44 | $this->dogs_array = json_decode($json,TRUE); 45 | 46 | } 47 | 48 | function __destruct() 49 | { 50 | $xmlstring = ''; 51 | $xmlstring .= "\n\n"; 52 | foreach ($this->dogs_array as $dogs=>$dogs_value) { 53 | foreach ($dogs_value as $dog => $dog_value) 54 | { 55 | $xmlstring .="<$dogs>\n"; 56 | foreach ($dog_value as $column => $column_value) 57 | { 58 | $xmlstring .= "<$column>" . $dog_value[$column] . "\n"; 59 | } 60 | $xmlstring .= "\n"; 61 | } 62 | } 63 | $xmlstring .= "\n"; 64 | file_put_contents($this->dog_data_xml,$xmlstring); 65 | } 66 | 67 | 68 | function deleteRecord($recordNumber) 69 | { 70 | foreach ($this->dogs_array as $dogs=>&$dogs_value) { 71 | for($J=$recordNumber; $J < count($dogs_value) -1; $J++) { 72 | 73 | foreach ($dogs_value[$J] as $column => $column_value) 74 | { 75 | $dogs_value[$J][$column] = $dogs_value[$J + 1][$column]; 76 | } 77 | 78 | } 79 | unset ($dogs_value[count($dogs_value) -1]); 80 | } 81 | } 82 | 83 | function readRecords($recordNumber) 84 | { 85 | if($recordNumber === "ALL") { 86 | return $this->dogs_array["dog"]; 87 | } 88 | else 89 | { 90 | return $this->dogs_array["dog"][$recordNumber]; 91 | } 92 | } 93 | 94 | function insertRecords($records_array) 95 | { 96 | $dogs_array_size = count($this->dogs_array["dog"]); 97 | for($I=0;$I< count($records_array);$I++) 98 | { 99 | $this->dogs_array["dog"][$dogs_array_size + $I] = $records_array[$I]; 100 | } 101 | } 102 | 103 | function updateRecords($records_array) 104 | { 105 | foreach ($records_array as $records=>$records_value) 106 | { 107 | foreach ($records_value as $record => $record_value) 108 | { 109 | $this->dogs_array["dog"][$records] = $records_array[$records]; 110 | } 111 | } 112 | } 113 | 114 | } 115 | 116 | ?> -------------------------------------------------------------------------------- /Chapter 6/e3dog.php: -------------------------------------------------------------------------------- 1 | breedxml = $properties_array[4]; 16 | 17 | $name_error = $this->set_dog_name($properties_array[0]) == TRUE ? 'TRUE,' : 'FALSE,'; 18 | $color_error = $this->set_dog_color($properties_array[2]) == TRUE ? 'TRUE,' : 'FALSE,'; 19 | $weight_error= $this->set_dog_weight($properties_array[3]) == TRUE ? 'TRUE' : 'FALSE'; 20 | $breed_error = $this->set_dog_breed($properties_array[1]) == TRUE ? 'TRUE,' : 'FALSE,'; 21 | 22 | $this->error_message = $name_error . $breed_error . $color_error . $weight_error; 23 | 24 | if(stristr($this->error_message, 'FALSE')) 25 | { 26 | throw new setException($this->error_message); 27 | } 28 | 29 | } 30 | else 31 | { 32 | exit; 33 | } 34 | } 35 | //------------------------------------toString-------------------------------------------------- 36 | //public function __toString() 37 | //{ 38 | // return $this->error_message; 39 | //} 40 | 41 | 42 | // ---------------------------------- Set Methods ---------------------------------------------- 43 | function set_dog_name($value) 44 | { 45 | $error_message = TRUE; 46 | (ctype_alpha($value) && strlen($value) <= 20) ? $this->dog_name = $value : $this->error_message = FALSE; 47 | return $this->error_message; 48 | } 49 | function set_dog_weight($value) 50 | { 51 | $error_message = TRUE; 52 | (ctype_digit($value) && ($value > 0 && $value <= 120)) ? $this->dog_weight = $value : $this->error_message = FALSE; 53 | return $this->error_message; 54 | } 55 | function set_dog_breed($value) 56 | { 57 | $error_message = TRUE; 58 | ($this->validator_breed($value) === TRUE) ? $this->dog_breed = $value : $this->error_message = FALSE; 59 | return $this->error_message; 60 | } 61 | function set_dog_color($value) 62 | { 63 | $error_message = TRUE; 64 | (ctype_alpha($value) && strlen($value) <= 15) ? $this->dog_color = $value : $this->error_message = FALSE; 65 | return $this->error_message; 66 | } 67 | // ----------------------------------------- Get Methods ------------------------------------------------------------ 68 | function get_dog_name() 69 | { 70 | return $this->dog_name; 71 | } 72 | function get_dog_weight() 73 | { 74 | return $this->dog_weight; 75 | } 76 | function get_dog_breed() 77 | { 78 | return $this->dog_breed; 79 | } 80 | function get_dog_color() 81 | { 82 | return $this->dog_color; 83 | } 84 | function get_properties() 85 | { 86 | return "$this->dog_name,$this->dog_weight,$this->dog_breed,$this->dog_color."; 87 | } 88 | // ----------------------------------General Method--------------------------------------------- 89 | 90 | private function validator_breed($value) 91 | { 92 | 93 | $breed_file = simplexml_load_file($this->breedxml); 94 | $xmlText = $breed_file->asXML(); 95 | 96 | if(stristr($xmlText, $value) === FALSE) 97 | { 98 | return FALSE; 99 | } 100 | else 101 | { 102 | return TRUE; 103 | } 104 | } 105 | 106 | } 107 | ?> -------------------------------------------------------------------------------- /Chapter 9/e3registration.php: -------------------------------------------------------------------------------- 1 | = 8))) 13 | { 14 | throw new Exception("Invalid Userid and/or Password Format"); 15 | } 16 | else 17 | { 18 | 19 | $hashed_password = password_hash($password, PASSWORD_DEFAULT); 20 | 21 | 22 | 23 | 24 | libxml_use_internal_errors(true); 25 | $xmlDoc = new DOMDocument(); 26 | if ( file_exists("edog_applications.xml") ) 27 | { 28 | $xmlDoc->load( 'edog_applications.xml' ); 29 | $searchNode = $xmlDoc->getElementsByTagName( "type" ); 30 | 31 | foreach( $searchNode as $searchNode ) 32 | { 33 | $valueID = $searchNode->getAttribute('ID'); 34 | 35 | if($valueID == "UIDPASS") 36 | { 37 | 38 | $xmlLocation = $searchNode->getElementsByTagName( "location" ); 39 | $dog_data_xml = $xmlLocation->item(0)->nodeValue; 40 | 41 | break; 42 | } 43 | 44 | } 45 | } 46 | else 47 | { 48 | throw new Exception("Dog applications xml file missing or corrupt"); 49 | } 50 | $newupstring = "\n" . $userid . "\n" . $hashed_password . "\n"; 51 | $newupstring .= "" . date('Y-m-d', strtotime('+30 days')) . "\n"; 52 | $newupstring .= "0\n" . date('mdYhis') . "\n"; 53 | $newupstring .= "" . date('mdYhis') . "\n\n"; 54 | 55 | $input = file_get_contents($dog_data_xml); 56 | 57 | $find = ""; 58 | $find_q = preg_quote($find,'/'); 59 | $output = preg_replace("/^$find_q(\n|\$)/m","",$input); 60 | 61 | $output = $output . $newupstring; 62 | 63 | file_put_contents($dog_data_xml,$output); 64 | 65 | $login_string = date('mdYhis') . " | New Userid | " . $userid . "\n"; 66 | error_log($login_string,3,$user_log_file); 67 | header("Location: elogin.php"); 68 | 69 | } 70 | } 71 | } 72 | 73 | catch(Exception $e) 74 | { 75 | 76 | echo $e->getMessage(); 77 | } 78 | 79 | ?> 80 | 81 | ABC Canine Shelter Reservation System 82 | 83 | 86 | 87 | 88 |
89 | 91 |
92 |
93 | Userid must contain eight or more characters.
94 | Password must contain at least one number, one uppercase and lowercase letter, and at least 8 total characters.
95 | Username:
96 | Password:
98 | 99 |
100 |
101 | 102 |
103 | 104 | -------------------------------------------------------------------------------- /Chapter 8/e1lab.php: -------------------------------------------------------------------------------- 1 | "; 6 | echo "Login | Create an account"; 7 | echo "

"; 8 | } 9 | else 10 | { 11 | echo "

Welcome back, " . $_SESSION['username'] . "

"; 12 | ?> 13 | 14 | 15 | 16 | Dog Object 17 | 18 | 19 | 24 | 25 | 32 | 33 | 34 | 35 | 36 |

Dog Object Creater

37 |
38 |
39 |

Please complete ALL fields. Please note the required format of information.

40 | Enter Your Dog's Name (max 20 characters, alphabetic)

41 | Select Your Dog's Color:
42 | Brown
43 | Black
44 | Yellow
45 | White
46 | Mixed

47 | 48 | Enter Your Dog's Weight (numeric only)

49 | 52 | 53 | Select Your Dog's Breed

54 | 55 |
56 |
57 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /Chapter 8/e4lab.php: -------------------------------------------------------------------------------- 1 | "; 6 | echo "Login | Create an account"; 7 | echo "

"; 8 | } 9 | else 10 | { 11 | echo "

Welcome back, " . $_SESSION['username'] . "

"; 12 | ?> 13 | 14 | 15 | 16 | Dog Object 17 | 18 | 19 | 24 | 25 | 32 | 33 | 34 | 35 | 36 |

Dog Object Creater

37 |
38 |
39 |

Please complete ALL fields. Please note the required format of information.

40 | Enter Your Dog's Name (max 20 characters, alphabetic)

41 | Select Your Dog's Color:
42 | Brown
43 | Black
44 | Yellow
45 | White
46 | Mixed

47 | 48 | Enter Your Dog's Weight (numeric only)

49 | 52 | 53 | Select Your Dog's Breed

54 | 55 |
56 |
57 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /Chapter 6/e6dog_interface.php: -------------------------------------------------------------------------------- 1 | ", "/", "$" ); 23 | $value = str_ireplace($bad_chars,"",$value); 24 | return $value; 25 | 26 | } 27 | 28 | class setException extends Exception { 29 | public function errorMessage() { 30 | 31 | list($name_error, $breed_error, $color_error, $weight_error) = explode(',', $this->getMessage()); 32 | 33 | $name_error == 'TRUE' ? $eMessage = '' : $eMessage = 'Name update not successful
'; 34 | $breed_error == 'TRUE' ? $eMessage .= '' : $eMessage .= 'Breed update not successful
'; 35 | $color_error == 'TRUE' ? $eMessage .= '' : $eMessage .= 'Color update not successful
'; 36 | $weight_error == 'TRUE' ? $eMessage .= '' : $eMessage .= 'Weight update not successful
'; 37 | 38 | return $eMessage; 39 | } 40 | } 41 | 42 | function get_dog_app_properties($lab) 43 | { 44 | 45 | print "Your dog's name is " . $lab->get_dog_name() . "
"; 46 | print "Your dog weights " . $lab->get_dog_weight() . " lbs.
"; 47 | print "Your dog's breed is " . $lab->get_dog_breed() . "
"; 48 | print "Your dog's color is " . $lab->get_dog_color() . "
"; 49 | 50 | } 51 | //----------------Main Section------------------------------------- 52 | try { 53 | if ( file_exists("e5dog_container.php")) 54 | { 55 | Require_once("e5dog_container.php"); 56 | } 57 | else 58 | { 59 | throw new Exception("Dog container file missing or corrupt"); 60 | } 61 | 62 | if (isset($_POST['dog_app'])) 63 | { 64 | 65 | if ((isset($_POST['dog_name'])) && (isset($_POST['dog_breed'])) && (isset($_POST['dog_color'])) && (isset($_POST['dog_weight']))) 66 | { 67 | 68 | $container = new dog_container(clean_input($_POST['dog_app'])); 69 | 70 | $dog_name = clean_input(filter_input(INPUT_POST, "dog_name")); 71 | $dog_breed = clean_input($_POST['dog_breed']); 72 | $dog_color = clean_input($_POST['dog_color']); 73 | $dog_weight = clean_input($_POST['dog_weight']); 74 | $breedxml = $container->get_dog_application("breeds"); 75 | 76 | $properties_array = array($dog_name,$dog_breed,$dog_color,$dog_weight,$breedxml); 77 | $lab = $container->create_object($properties_array); 78 | $container = NULL; 79 | print "Updates successful
"; 80 | get_dog_app_properties($lab); 81 | } 82 | 83 | else 84 | { 85 | 86 | print "

Missing or invalid parameters. Please go back to the dog.html page to enter valid information.
"; 87 | 88 | print "Dog Creation Page"; 89 | 90 | } 91 | } 92 | else // select box 93 | { 94 | 95 | $container = new dog_container("selectbox"); 96 | 97 | $properties_array = array("selectbox"); 98 | 99 | $lab = $container->create_object($properties_array); 100 | $container->set_app("breeds"); 101 | $dog_app = $container->get_dog_application("breeds"); 102 | $method_array = get_class_methods($lab); 103 | $last_position = count($method_array) - 1; 104 | $method_name = $method_array[$last_position]; 105 | $result = $lab->$method_name($dog_app); 106 | 107 | 108 | print $result; 109 | } 110 | } 111 | catch(setException $e) 112 | { 113 | echo $e->errorMessage(); 114 | } 115 | catch(Exception $e) 116 | { 117 | 118 | echo $e->getMessage(); 119 | } 120 | ?> -------------------------------------------------------------------------------- /Chapter 5/e12dog_interface.php: -------------------------------------------------------------------------------- 1 | ", "/", "$" ); 23 | $value = str_ireplace($bad_chars,"",$value); 24 | return $value; 25 | 26 | } 27 | 28 | function error_check_dog_app($lab) 29 | { 30 | 31 | list($name_error, $breed_error, $color_error, $weight_error) = explode(',', $lab); 32 | 33 | print $name_error == 'TRUE' ? 'Name update successful
' : 'Name update not successful
'; 34 | print $breed_error == 'TRUE' ? 'Breed update successful
' : 'Breed update not successful
'; 35 | print $color_error == 'TRUE' ? 'Color update successful
' : 'Color update not successful
'; 36 | print $weight_error == 'TRUE' ? 'Weight update successful
' : 'Weight update not successful
'; 37 | 38 | } 39 | 40 | function get_dog_app_properties($lab) 41 | { 42 | 43 | print "Your dog's name is " . $lab->get_dog_name() . "
"; 44 | print "Your dog weights " . $lab->get_dog_weight() . " lbs.
"; 45 | print "Your dog's breed is " . $lab->get_dog_breed() . "
"; 46 | print "Your dog's color is " . $lab->get_dog_color() . "
"; 47 | 48 | } 49 | //----------------Main Section------------------------------------- 50 | 51 | if ( file_exists("e11dog_container.php")) 52 | { 53 | Require_once("e11dog_container.php"); 54 | } 55 | else 56 | { 57 | print "System Error #1"; 58 | exit; 59 | } 60 | 61 | if (isset($_POST['dog_app'])) 62 | { 63 | 64 | if ((isset($_POST['dog_name'])) && (isset($_POST['dog_breed'])) && (isset($_POST['dog_color'])) && (isset($_POST['dog_weight']))) 65 | { 66 | 67 | $container = new dog_container(clean_input($_POST['dog_app'])); 68 | 69 | $dog_name = clean_input(filter_input(INPUT_POST, "dog_name")); 70 | $dog_breed = clean_input($_POST['dog_breed']); 71 | $dog_color = clean_input($_POST['dog_color']); 72 | $dog_weight = clean_input($_POST['dog_weight']); 73 | $breedxml = $container->get_dog_application("breeds"); 74 | 75 | $properties_array = array($dog_name,$dog_breed,$dog_color,$dog_weight,$breedxml); 76 | $lab = $container->create_object($properties_array); 77 | 78 | if ($lab != FALSE) 79 | { 80 | error_check_dog_app($lab); 81 | get_dog_app_properties($lab); 82 | } 83 | else 84 | { 85 | print "System Error #2"; 86 | } 87 | } 88 | 89 | else 90 | { 91 | 92 | print "

Missing or invalid parameters. Please go back to the dog.html page to enter valid information.
"; 93 | 94 | print "Dog Creation Page"; 95 | 96 | } 97 | } 98 | else // select box 99 | { 100 | 101 | $container = new dog_container("selectbox"); 102 | 103 | $properties_array = array("selectbox"); 104 | 105 | $lab = $container->create_object($properties_array); 106 | 107 | 108 | if ($lab != FALSE) 109 | { 110 | 111 | $container->set_app("breeds"); 112 | $dog_app = $container->get_dog_application("breeds"); 113 | $method_array = get_class_methods($lab); 114 | $last_position = count($method_array) - 1; 115 | $method_name = $method_array[$last_position]; 116 | $result = $lab->$method_name($dog_app); 117 | 118 | if ( $result == FALSE) 119 | { 120 | print "System Error #3"; 121 | } 122 | else 123 | { 124 | print $result; 125 | } 126 | } 127 | else 128 | { 129 | print "System Error #4"; 130 | } 131 | 132 | } 133 | ?> -------------------------------------------------------------------------------- /Chapter 7/e5dog.php: -------------------------------------------------------------------------------- 1 | breedxml = $properties_array[4]; 16 | 17 | $name_error = $this->set_dog_name($properties_array[0]) == TRUE ? 'TRUE,' : 'FALSE,'; 18 | $color_error = $this->set_dog_color($properties_array[2]) == TRUE ? 'TRUE,' : 'FALSE,'; 19 | $weight_error= $this->set_dog_weight($properties_array[3]) == TRUE ? 'TRUE' : 'FALSE'; 20 | $breed_error = $this->set_dog_breed($properties_array[1]) == TRUE ? 'TRUE,' : 'FALSE,'; 21 | 22 | $this->error_message = $name_error . $breed_error . $color_error . $weight_error; 23 | $this->save_dog_data(); 24 | if(stristr($this->error_message, 'FALSE')) 25 | { 26 | throw new setException($this->error_message); 27 | } 28 | 29 | } 30 | else 31 | { 32 | exit; 33 | } 34 | } 35 | function clean_input() { } 36 | private function save_dog_data() 37 | { 38 | if ( file_exists("e5dog_container.php")) { 39 | require_once("e5dog_container.php"); // use chapter 5 container w exception handling 40 | } else { 41 | throw new Exception("Dog container file missing or corrupt"); 42 | } 43 | 44 | $container = new dog_container("dogdata"); // sets the tag name to look for in XML file 45 | $properties_array = array("dogdata"); // not used but must be passed into create_object 46 | $dog_data = $container->create_object($properties_array); // creates dog_data object 47 | $method_array = get_class_methods($dog_data); 48 | $last_position = count($method_array) - 1; 49 | $method_name = $method_array[$last_position]; 50 | $record_Array = array(array('dog_name'=>"$this->dog_name", 'dog_weight'=>"$this->dog_weight", 'dog_color'=>"$this->dog_color", 'dog_breed'=>"$this->dog_breed")); 51 | $dog_data->$method_name("Insert",$record_Array); 52 | $dog_data = NULL; 53 | 54 | } 55 | 56 | function set_dog_name($value) 57 | { 58 | $error_message = TRUE; 59 | (ctype_alpha($value) && strlen($value) <= 20) ? $this->dog_name = $value : $this->error_message = FALSE; 60 | return $this->error_message; 61 | } 62 | function set_dog_weight($value) 63 | { 64 | $error_message = TRUE; 65 | (ctype_digit($value) && ($value > 0 && $value <= 120)) ? $this->dog_weight = $value : $this->error_message = FALSE; 66 | return $this->error_message; 67 | } 68 | function set_dog_breed($value) 69 | { 70 | $error_message = TRUE; 71 | ($this->validator_breed($value) === TRUE) ? $this->dog_breed = $value : $this->error_message = FALSE; 72 | return $this->error_message; 73 | } 74 | function set_dog_color($value) 75 | { 76 | $error_message = TRUE; 77 | (ctype_alpha($value) && strlen($value) <= 15) ? $this->dog_color = $value : $this->error_message = FALSE; 78 | return $this->error_message; 79 | } 80 | // ----------------------------------------- Get Methods ------------------------------------------------------------ 81 | function get_dog_name() 82 | { 83 | return $this->dog_name; 84 | } 85 | function get_dog_weight() 86 | { 87 | return $this->dog_weight; 88 | } 89 | function get_dog_breed() 90 | { 91 | return $this->dog_breed; 92 | } 93 | function get_dog_color() 94 | { 95 | return $this->dog_color; 96 | } 97 | function get_properties() 98 | { 99 | return "$this->dog_name,$this->dog_weight,$this->dog_breed,$this->dog_color."; 100 | } 101 | // ----------------------------------General Method--------------------------------------------- 102 | 103 | private function validator_breed($value) 104 | { 105 | 106 | $breed_file = simplexml_load_file($this->breedxml); 107 | $xmlText = $breed_file->asXML(); 108 | 109 | if(stristr($xmlText, $value) === FALSE) 110 | { 111 | return FALSE; 112 | } 113 | else 114 | { 115 | return TRUE; 116 | } 117 | } 118 | 119 | } 120 | ?> -------------------------------------------------------------------------------- /Chapter 8/e5dog.php: -------------------------------------------------------------------------------- 1 | breedxml = $properties_array[4]; 16 | 17 | $name_error = $this->set_dog_name($properties_array[0]) == TRUE ? 'TRUE,' : 'FALSE,'; 18 | $color_error = $this->set_dog_color($properties_array[2]) == TRUE ? 'TRUE,' : 'FALSE,'; 19 | $weight_error= $this->set_dog_weight($properties_array[3]) == TRUE ? 'TRUE' : 'FALSE'; 20 | $breed_error = $this->set_dog_breed($properties_array[1]) == TRUE ? 'TRUE,' : 'FALSE,'; 21 | 22 | $this->error_message = $name_error . $breed_error . $color_error . $weight_error; 23 | $this->save_dog_data(); 24 | if(stristr($this->error_message, 'FALSE')) 25 | { 26 | throw new setException($this->error_message); 27 | } 28 | 29 | } 30 | else 31 | { 32 | exit; 33 | } 34 | } 35 | function clean_input() { } 36 | private function save_dog_data() 37 | { 38 | if ( file_exists("e5dog_container.php")) { 39 | require_once("e5dog_container.php"); // use chapter 5 container w exception handling 40 | } else { 41 | throw new Exception("Dog container file missing or corrupt"); 42 | } 43 | 44 | $container = new dog_container("dogdata"); // sets the tag name to look for in XML file 45 | $properties_array = array("dogdata"); // not used but must be passed into create_object 46 | $dog_data = $container->create_object($properties_array); // creates dog_data object 47 | $method_array = get_class_methods($dog_data); 48 | $last_position = count($method_array) - 1; 49 | $method_name = $method_array[$last_position]; 50 | $record_Array = array(array('dog_name'=>"$this->dog_name", 'dog_weight'=>"$this->dog_weight", 'dog_color'=>"$this->dog_color", 'dog_breed'=>"$this->dog_breed")); 51 | $dog_data->$method_name("Insert",$record_Array); 52 | $dog_data = NULL; 53 | 54 | } 55 | 56 | function set_dog_name($value) 57 | { 58 | $error_message = TRUE; 59 | (ctype_alpha($value) && strlen($value) <= 20) ? $this->dog_name = $value : $this->error_message = FALSE; 60 | return $this->error_message; 61 | } 62 | function set_dog_weight($value) 63 | { 64 | $error_message = TRUE; 65 | (ctype_digit($value) && ($value > 0 && $value <= 120)) ? $this->dog_weight = $value : $this->error_message = FALSE; 66 | return $this->error_message; 67 | } 68 | function set_dog_breed($value) 69 | { 70 | $error_message = TRUE; 71 | ($this->validator_breed($value) === TRUE) ? $this->dog_breed = $value : $this->error_message = FALSE; 72 | return $this->error_message; 73 | } 74 | function set_dog_color($value) 75 | { 76 | $error_message = TRUE; 77 | (ctype_alpha($value) && strlen($value) <= 15) ? $this->dog_color = $value : $this->error_message = FALSE; 78 | return $this->error_message; 79 | } 80 | // ----------------------------------------- Get Methods ------------------------------------------------------------ 81 | function get_dog_name() 82 | { 83 | return $this->dog_name; 84 | } 85 | function get_dog_weight() 86 | { 87 | return $this->dog_weight; 88 | } 89 | function get_dog_breed() 90 | { 91 | return $this->dog_breed; 92 | } 93 | function get_dog_color() 94 | { 95 | return $this->dog_color; 96 | } 97 | function get_properties() 98 | { 99 | return "$this->dog_name,$this->dog_weight,$this->dog_breed,$this->dog_color."; 100 | } 101 | // ----------------------------------General Method--------------------------------------------- 102 | 103 | private function validator_breed($value) 104 | { 105 | 106 | $breed_file = simplexml_load_file($this->breedxml); 107 | $xmlText = $breed_file->asXML(); 108 | 109 | if(stristr($xmlText, $value) === FALSE) 110 | { 111 | return FALSE; 112 | } 113 | else 114 | { 115 | return TRUE; 116 | } 117 | } 118 | 119 | } 120 | ?> -------------------------------------------------------------------------------- /Chapter 7/e4displaychangelog.php: -------------------------------------------------------------------------------- 1 | "; 5 | echo ""; 6 | echo ""; 7 | echo ""; 8 | echo ""; 9 | echo ""; 10 | 11 | for ($J=$row_Count -1; $J >= 0; $J--) 12 | { 13 | echo ""; 14 | 15 | for($I=0; $I < 3; $I++) 16 | { 17 | echo " "; 18 | } 19 | echo ""; 20 | } 21 | echo "
Log File: " . $change_File . "
Date/TimeChange TypeChange Data
Delete " . $change_Array[$J][$I] . "
"; 22 | echo ""; 23 | 24 | $directory = ""; 25 | 26 | $files = glob($directory . "*dog_data.xml"); 27 | 28 | echo "

"; 29 | echo "

Delete entries above or select a file to update with change log $change_File

"; 30 | echo ""; 38 | echo ""; 39 | echo ""; 40 | echo "
"; 41 | 42 | 43 | } 44 | function deleteRecord($recordNumber, &$row_Count, &$change_Array) 45 | { 46 | 47 | for ($J=$recordNumber; $J < $row_Count - 1; $J++) 48 | { 49 | for($I=0; $I < 3; $I++) 50 | { 51 | $change_Array[$J][$I] = $change_Array[$J + 1][$I]; 52 | } 53 | } 54 | 55 | unset($change_Array[$row_Count]); 56 | $row_Count--; 57 | 58 | } 59 | 60 | function saveChanges($row_Count,$change_Array,$change_File) 61 | { 62 | 63 | $changeFile = fopen($change_File, "w"); 64 | for($I=0; $I < $row_Count; $I++) 65 | { 66 | $writeString = $change_Array[$I][0] . " | " . $change_Array[$I][1] . " | " . $change_Array[$I][2]; 67 | fwrite($changeFile, $writeString); 68 | } 69 | fclose($changeFile); 70 | } 71 | 72 | function delete_Process() 73 | { 74 | $change_Array = load_Array(); 75 | deleteRecord($_GET['rn'], $row_Count, $change_Array); 76 | 77 | saveChanges($row_Count,$change_Array,$change_File); 78 | displayRecords($row_Count,$change_Array,$change_File); 79 | } 80 | 81 | function load_Array() 82 | { 83 | 84 | $change_File = $_POST['change_file']; 85 | 86 | $logFile = fopen($change_File, "r"); 87 | $row_Count = 0; 88 | while(!feof($logFile)) 89 | { 90 | $change_Array[$row_Count] = explode(' | ', fgets($logFile)); 91 | 92 | $row_Count++; 93 | } 94 | $row_Count--; 95 | fclose($logFile); 96 | return $change_Array; 97 | } 98 | function display_Process() 99 | { 100 | $change_Array = load_Array(); 101 | 102 | $row_Count = count($change_Array) -1; 103 | 104 | displayRecords($row_Count, $change_Array, $_POST['change_file']); 105 | 106 | } 107 | 108 | function select_File_Process() 109 | { 110 | $directory = ""; 111 | 112 | $files = glob($directory . "*change.log"); 113 | 114 | echo "
"; 115 | echo "

Select a file to display

"; 116 | echo ""; 124 | echo ""; 125 | echo "
"; 126 | 127 | } 128 | 129 | function update_XML_File_Process() 130 | { 131 | $change_Array = load_Array(); 132 | 133 | require_once("e3dog_data.php"); 134 | 135 | $data_Changer = new dog_data(); 136 | 137 | $row_Count = count($change_Array) -1; 138 | 139 | for($I=0;$I < $row_Count; $I++) 140 | { 141 | 142 | if($change_Array[$I][1] != "Delete") 143 | { 144 | $temp = unserialize($change_Array[$I][2]); 145 | 146 | } 147 | else 148 | { 149 | 150 | $temp = (integer)$change_Array[$I][2]; 151 | 152 | } 153 | 154 | $data_Changer->processRecords($change_Array[$I][1], $temp); 155 | 156 | } 157 | 158 | $data_Changer->setChangeLogFile($_POST['data_File']); 159 | 160 | $data_Changer = NULL; 161 | 162 | echo "Changes completed"; 163 | } 164 | 165 | if(isset($_POST['data_File'])) 166 | { 167 | 168 | update_XML_File_Process(); 169 | 170 | } 171 | else if(isset($_GET['rn'])) 172 | { 173 | delete_Process(); 174 | } 175 | else if(isset($_POST['change_file'])) 176 | { 177 | display_Process(); 178 | } 179 | else 180 | { 181 | select_File_Process(); 182 | } 183 | 184 | ?> -------------------------------------------------------------------------------- /Chapter 6/e7dog_interface.php: -------------------------------------------------------------------------------- 1 | ", "/", "$" ); 26 | $value = str_ireplace($bad_chars,"",$value); 27 | return $value; 28 | 29 | } 30 | 31 | class setException extends Exception { 32 | public function errorMessage() { 33 | 34 | list($name_error, $breed_error, $color_error, $weight_error) = explode(',', $this->getMessage()); 35 | 36 | $name_error == 'TRUE' ? $eMessage = '' : $eMessage = 'Name update not successful
'; 37 | $breed_error == 'TRUE' ? $eMessage .= '' : $eMessage .= 'Breed update not successful
'; 38 | $color_error == 'TRUE' ? $eMessage .= '' : $eMessage .= 'Color update not successful
'; 39 | $weight_error == 'TRUE' ? $eMessage .= '' : $eMessage .= 'Weight update not successful
'; 40 | 41 | return $eMessage; 42 | } 43 | } 44 | 45 | function get_dog_app_properties($lab) 46 | { 47 | 48 | print "Your dog's name is " . $lab->get_dog_name() . "
"; 49 | print "Your dog weights " . $lab->get_dog_weight() . " lbs.
"; 50 | print "Your dog's breed is " . $lab->get_dog_breed() . "
"; 51 | print "Your dog's color is " . $lab->get_dog_color() . "
"; 52 | 53 | } 54 | //----------------Main Section------------------------------------- 55 | try { 56 | if ( file_exists("e5dog_container.php")) 57 | { 58 | Require_once("e5dog_container.php"); 59 | } 60 | else 61 | { 62 | throw new Exception("Dog container file missing or corrupt"); 63 | } 64 | 65 | if (isset($_POST['dog_app'])) 66 | { 67 | 68 | if ((isset($_POST['dog_name'])) && (isset($_POST['dog_breed'])) && (isset($_POST['dog_color'])) && (isset($_POST['dog_weight']))) 69 | { 70 | 71 | $container = new dog_container(clean_input($_POST['dog_app'])); 72 | 73 | $dog_name = clean_input(filter_input(INPUT_POST, "dog_name")); 74 | $dog_breed = clean_input($_POST['dog_breed']); 75 | $dog_color = clean_input($_POST['dog_color']); 76 | $dog_weight = clean_input($_POST['dog_weight']); 77 | $breedxml = $container->get_dog_application("breeds"); 78 | 79 | $properties_array = array($dog_name,$dog_breed,$dog_color,$dog_weight,$breedxml); 80 | $lab = $container->create_object($properties_array); 81 | 82 | print "Updates successful
"; 83 | get_dog_app_properties($lab); 84 | } 85 | 86 | else 87 | { 88 | 89 | print "

Missing or invalid parameters. Please go back to the dog.html page to enter valid information.
"; 90 | 91 | print "Dog Creation Page"; 92 | 93 | } 94 | } 95 | else // select box 96 | { 97 | 98 | $container = new dog_container("selectbox"); 99 | 100 | $properties_array = array("selectbox"); 101 | 102 | $lab = $container->create_object($properties_array); 103 | $container->set_app("breeds"); 104 | $dog_app = $container->get_dog_application("breeds"); 105 | $method_array = get_class_methods($lab); 106 | $last_position = count($method_array) - 1; 107 | $method_name = $method_array[$last_position]; 108 | $result = $lab->$method_name($dog_app); 109 | 110 | print $result; 111 | } 112 | } 113 | catch(setException $e) 114 | { 115 | echo $e->errorMessage(); // displays to the user 116 | 117 | $date = date('m.d.Y h:i:s'); 118 | $errormessage = $e->errorMessage(); 119 | $eMessage = $date . " | User Error | " . $errormessage . "\n"; 120 | error_log($eMessage,3,USER_ERROR_LOG); // writes message to user error log file 121 | 122 | } 123 | catch(Exception $e) 124 | { 125 | 126 | echo "The system is currently unavailable. Please try again later."; // displays message to the user 127 | 128 | $date = date('m.d.Y h:i:s'); 129 | $eMessage = $date . " | System Error | " . $e->getMessage() . " | " . $e->getFile() . " | ". $e->getLine() . "\n"; 130 | error_log($eMessage,3,ERROR_LOG); // writes message to error log file 131 | 132 | error_log("Date/Time: $date - Serious System Problems with Dog Application. Check error log for details", 1, "noone@helpme.com", "Subject: Dog Application Error \nFrom: System Log " . "\r\n"); 133 | // e-mails personnel to alert them of a system problem 134 | 135 | } 136 | ?> -------------------------------------------------------------------------------- /Chapter 8/e5dog_interface.php: -------------------------------------------------------------------------------- 1 | ", "/", "$" ); 26 | $value = str_ireplace($bad_chars,"",$value); 27 | return $value; 28 | 29 | } 30 | 31 | class setException extends Exception { 32 | public function errorMessage() { 33 | 34 | list($name_error, $breed_error, $color_error, $weight_error) = explode(',', $this->getMessage()); 35 | 36 | $name_error == 'TRUE' ? $eMessage = '' : $eMessage = 'Name update not successful
'; 37 | $breed_error == 'TRUE' ? $eMessage .= '' : $eMessage .= 'Breed update not successful
'; 38 | $color_error == 'TRUE' ? $eMessage .= '' : $eMessage .= 'Color update not successful
'; 39 | $weight_error == 'TRUE' ? $eMessage .= '' : $eMessage .= 'Weight update not successful
'; 40 | 41 | return $eMessage; 42 | } 43 | } 44 | 45 | function get_dog_app_properties($lab) 46 | { 47 | 48 | print "Your dog's name is " . $lab->get_dog_name() . "
"; 49 | print "Your dog weights " . $lab->get_dog_weight() . " lbs.
"; 50 | print "Your dog's breed is " . $lab->get_dog_breed() . "
"; 51 | print "Your dog's color is " . $lab->get_dog_color() . "
"; 52 | 53 | } 54 | //----------------Main Section------------------------------------- 55 | try { 56 | if ( file_exists("e5dog_container.php")) 57 | { 58 | Require_once("e5dog_container.php"); 59 | } 60 | else 61 | { 62 | throw new Exception("Dog container file missing or corrupt"); 63 | } 64 | 65 | if (isset($_POST['dog_app'])) 66 | { 67 | 68 | if ((isset($_POST['dog_name'])) && (isset($_POST['dog_breed'])) && (isset($_POST['dog_color'])) && (isset($_POST['dog_weight']))) 69 | { 70 | 71 | $container = new dog_container(clean_input($_POST['dog_app'])); 72 | 73 | $dog_name = clean_input(filter_input(INPUT_POST, "dog_name")); 74 | $dog_breed = clean_input($_POST['dog_breed']); 75 | $dog_color = clean_input($_POST['dog_color']); 76 | $dog_weight = clean_input($_POST['dog_weight']); 77 | $breedxml = $container->get_dog_application("breeds"); 78 | 79 | $properties_array = array($dog_name,$dog_breed,$dog_color,$dog_weight,$breedxml); 80 | $lab = $container->create_object($properties_array); 81 | 82 | print "Updates successful
"; 83 | get_dog_app_properties($lab); 84 | } 85 | 86 | else 87 | { 88 | 89 | print "

Missing or invalid parameters. Please go back to the dog.html page to enter valid information.
"; 90 | 91 | print "Dog Creation Page"; 92 | 93 | } 94 | } 95 | else // select box 96 | { 97 | 98 | $container = new dog_container("selectbox"); 99 | 100 | $properties_array = array("selectbox"); 101 | 102 | $lab = $container->create_object($properties_array); 103 | $container->set_app("breeds"); 104 | $dog_app = $container->get_dog_application("breeds"); 105 | $method_array = get_class_methods($lab); 106 | $last_position = count($method_array) - 1; 107 | $method_name = $method_array[$last_position]; 108 | $result = $lab->$method_name($dog_app); 109 | 110 | print $result; 111 | } 112 | } 113 | catch(setException $e) 114 | { 115 | echo $e->errorMessage(); // displays to the user 116 | 117 | $date = date('m.d.Y h:i:s'); 118 | $errormessage = $e->errorMessage(); 119 | $eMessage = $date . " | User Error | " . $errormessage . "\n"; 120 | error_log($eMessage,3,USER_ERROR_LOG); // writes message to user error log file 121 | 122 | } 123 | catch(Exception $e) 124 | { 125 | 126 | echo "The system is currently unavailable. Please try again later."; // displays message to the user 127 | 128 | $date = date('m.d.Y h:i:s'); 129 | $eMessage = $date . " | System Error | " . $e->getMessage() . " | " . $e->getFile() . " | ". $e->getLine() . "\n"; 130 | error_log($eMessage,3,ERROR_LOG); // writes message to error log file 131 | 132 | error_log("Date/Time: $date - Serious System Problems with Dog Application. Check error log for details", 1, "noone@helpme.com", "Subject: Dog Application Error \nFrom: System Log " . "\r\n"); 133 | // e-mails personnel to alert them of a system problem 134 | 135 | } 136 | ?> -------------------------------------------------------------------------------- /Chapter 7/e5dog_interface.php: -------------------------------------------------------------------------------- 1 | ", "/", "$" ); 26 | $value = str_ireplace($bad_chars,"",$value); 27 | return $value; 28 | 29 | } 30 | 31 | class setException extends Exception { 32 | public function errorMessage() { 33 | 34 | list($name_error, $breed_error, $color_error, $weight_error) = explode(',', $this->getMessage()); 35 | 36 | $name_error == 'TRUE' ? $eMessage = '' : $eMessage = 'Name update not successful
'; 37 | $breed_error == 'TRUE' ? $eMessage .= '' : $eMessage .= 'Breed update not successful
'; 38 | $color_error == 'TRUE' ? $eMessage .= '' : $eMessage .= 'Color update not successful
'; 39 | $weight_error == 'TRUE' ? $eMessage .= '' : $eMessage .= 'Weight update not successful
'; 40 | 41 | return $eMessage; 42 | } 43 | } 44 | 45 | function get_dog_app_properties($lab) 46 | { 47 | 48 | print "Your dog's name is " . $lab->get_dog_name() . "
"; 49 | print "Your dog weights " . $lab->get_dog_weight() . " lbs.
"; 50 | print "Your dog's breed is " . $lab->get_dog_breed() . "
"; 51 | print "Your dog's color is " . $lab->get_dog_color() . "
"; 52 | 53 | } 54 | //----------------Main Section------------------------------------- 55 | try { 56 | if ( file_exists("e5dog_container.php")) 57 | { 58 | Require_once("e5dog_container.php"); 59 | } 60 | else 61 | { 62 | throw new Exception("Dog container file missing or corrupt"); 63 | } 64 | 65 | if (isset($_POST['dog_app'])) 66 | { 67 | 68 | if ((isset($_POST['dog_name'])) && (isset($_POST['dog_breed'])) && (isset($_POST['dog_color'])) && (isset($_POST['dog_weight']))) 69 | { 70 | 71 | $container = new dog_container(clean_input($_POST['dog_app'])); 72 | 73 | $dog_name = clean_input(filter_input(INPUT_POST, "dog_name")); 74 | $dog_breed = clean_input($_POST['dog_breed']); 75 | $dog_color = clean_input($_POST['dog_color']); 76 | $dog_weight = clean_input($_POST['dog_weight']); 77 | $breedxml = $container->get_dog_application("breeds"); 78 | 79 | $properties_array = array($dog_name,$dog_breed,$dog_color,$dog_weight,$breedxml); 80 | $lab = $container->create_object($properties_array); 81 | 82 | print "Updates successful
"; 83 | get_dog_app_properties($lab); 84 | } 85 | 86 | else 87 | { 88 | 89 | print "

Missing or invalid parameters. Please go back to the dog.html page to enter valid information.
"; 90 | 91 | print "Dog Creation Page"; 92 | 93 | } 94 | } 95 | else // select box 96 | { 97 | 98 | $container = new dog_container("selectbox"); 99 | 100 | $properties_array = array("selectbox"); 101 | 102 | $lab = $container->create_object($properties_array); 103 | $container->set_app("breeds"); 104 | $dog_app = $container->get_dog_application("breeds"); 105 | $method_array = get_class_methods($lab); 106 | $last_position = count($method_array) - 1; 107 | $method_name = $method_array[$last_position]; 108 | $result = $lab->$method_name($dog_app); 109 | 110 | print $result; 111 | } 112 | } 113 | catch(setException $e) 114 | { 115 | echo $e->errorMessage(); // displays to the user 116 | 117 | $date = date('m.d.Y h:i:s'); 118 | $errormessage = $e->errorMessage(); 119 | $eMessage = $date . " | User Error | " . $errormessage . "\n"; 120 | error_log($eMessage,3,USER_ERROR_LOG); // writes message to user error log file 121 | 122 | } 123 | catch(Exception $e) 124 | { 125 | 126 | echo "The system is currently unavailable. Please try again later."; // displays message to the user 127 | 128 | $date = date('m.d.Y h:i:s'); 129 | $eMessage = $date . " | System Error | " . $e->getMessage() . " | " . $e->getFile() . " | ". $e->getLine() . "\n"; 130 | error_log($eMessage,3,ERROR_LOG); // writes message to error log file 131 | 132 | error_log("Date/Time: $date - Serious System Problems with Dog Application. Check error log for details", 1, "noone@helpme.com", "Subject: Dog Application Error \nFrom: System Log " . "\r\n"); 133 | // e-mails personnel to alert them of a system problem 134 | 135 | } 136 | ?> 137 | -------------------------------------------------------------------------------- /Chapter 7/e3dog_data.php: -------------------------------------------------------------------------------- 1 | load( 'e1dog_applications.xml' ); 14 | $searchNode = $xmlDoc->getElementsByTagName( "type" ); 15 | 16 | foreach( $searchNode as $searchNode ) 17 | { 18 | $valueID = $searchNode->getAttribute('ID'); 19 | 20 | if($valueID == "datastorage") 21 | { 22 | 23 | $xmlLocation = $searchNode->getElementsByTagName( "location" ); 24 | $this->dog_data_xml = $xmlLocation->item(0)->nodeValue; 25 | 26 | break; 27 | } 28 | 29 | } 30 | } 31 | else 32 | { 33 | throw new Exception("Dog applications xml file missing or corrupt"); 34 | } 35 | $xmlfile = file_get_contents($this->dog_data_xml); 36 | $xmlstring = simplexml_load_string($xmlfile); 37 | 38 | if ($xmlstring === false) { 39 | $errorString = "Failed loading XML: "; 40 | foreach(libxml_get_errors() as $error) { 41 | $errorString .= $error->message . " " ; } 42 | throw new Exception($errorString); } 43 | $json = json_encode($xmlstring); 44 | $this->dogs_array = json_decode($json,TRUE); 45 | 46 | } 47 | 48 | function __destruct() 49 | { 50 | 51 | $xmlstring = ''; 52 | $xmlstring .= "\n\n"; 53 | foreach ($this->dogs_array as $dogs=>$dogs_value) { 54 | foreach ($dogs_value as $dog => $dog_value) 55 | { 56 | $xmlstring .="<$dogs>\n"; 57 | foreach ($dog_value as $column => $column_value) 58 | { 59 | $xmlstring .= "<$column>" . $dog_value[$column] . "\n"; 60 | } 61 | $xmlstring .= "\n"; 62 | } 63 | } 64 | $xmlstring .= "\n"; 65 | 66 | $new_valid_data_file = preg_replace('/[0-9]+/', '', $this->dog_data_xml); 67 | // remove the previous date and time if it exists 68 | $oldxmldata = date('mdYhis') . $new_valid_data_file; 69 | if (!rename($this->dog_data_xml, $oldxmldata)) 70 | { 71 | throw new Exception("Backup file $oldxmldata could not be created."); 72 | } 73 | file_put_contents($new_valid_data_file,$xmlstring); 74 | 75 | } 76 | 77 | 78 | private function deleteRecord($recordNumber) 79 | { 80 | foreach ($this->dogs_array as $dogs=>&$dogs_value) { 81 | for($J=$recordNumber; $J < count($dogs_value) -1; $J++) { 82 | 83 | foreach ($dogs_value[$J] as $column => $column_value) 84 | { 85 | 86 | $dogs_value[$J][$column] = $dogs_value[$J + 1][$column]; 87 | } 88 | 89 | } 90 | unset ($dogs_value[count($dogs_value) -1]); 91 | } 92 | 93 | $change_string = date('mdYhis') . " | Delete | " . $recordNumber . "\n"; 94 | $chge_log_file = date('mdYhis') . $this->change_log_file; 95 | error_log($change_string,3,$chge_log_file); // might exceed 120 chars 96 | } 97 | 98 | private function readRecords($recordNumber) 99 | { 100 | if($recordNumber === "ALL") { 101 | return $this->dogs_array["dog"]; 102 | } 103 | else 104 | { 105 | return $this->dogs_array["dog"][$recordNumber]; 106 | } 107 | } 108 | 109 | private function insertRecords($records_array) 110 | { 111 | $dogs_array_size = count($this->dogs_array["dog"]); 112 | 113 | for($I=0;$I< count($records_array);$I++) 114 | { 115 | $this->dogs_array["dog"][$dogs_array_size + $I] = $records_array[$I]; 116 | 117 | } 118 | 119 | $change_string = date('mdYhis') . " | Insert | " . serialize($records_array) . "\n"; 120 | $chge_log_file = date('mdYhis') . $this->change_log_file; 121 | error_log($change_string,3,$chge_log_file); // might exceed 120 chars 122 | 123 | } 124 | 125 | private function updateRecords($records_array) 126 | { 127 | 128 | $chge_string = ""; 129 | foreach ($records_array as $records=>$records_value) 130 | { 131 | 132 | 133 | $this->dogs_array["dog"][$records] = $records_array[$records]; 134 | 135 | } 136 | 137 | $change_string = date('mdYhis') . " | Update | " . serialize($records_array) . "\n"; 138 | $chge_log_file = date('mdYhis') . $this->change_log_file; 139 | error_log($change_string,3,$chge_log_file); // might exceed 120 chars 140 | 141 | 142 | } 143 | function setChangeLogFile($value) 144 | { 145 | 146 | $this->dog_data_xml = $value; 147 | 148 | } 149 | function processRecords($change_Type, $records_array) 150 | { 151 | 152 | switch($change_Type) 153 | { 154 | 155 | case "Delete": 156 | 157 | $this->deleteRecord($records_array); 158 | break; 159 | case "Insert": 160 | $this->insertRecords($records_array); 161 | break; 162 | case "Update": 163 | $this->updateRecords($records_array); 164 | break; 165 | case "Display": 166 | $this->readRecords($records_array); 167 | break; 168 | default: 169 | throw new Exception("Invalid XML file change type: $change_Type"); 170 | } 171 | 172 | } 173 | } 174 | 175 | ?> -------------------------------------------------------------------------------- /Chapter 7/e5dog_data.php: -------------------------------------------------------------------------------- 1 | load( 'e5dog_applications.xml' ); 14 | $searchNode = $xmlDoc->getElementsByTagName( "type" ); 15 | 16 | foreach( $searchNode as $searchNode ) 17 | { 18 | $valueID = $searchNode->getAttribute('ID'); 19 | 20 | if($valueID == "datastorage") 21 | { 22 | 23 | $xmlLocation = $searchNode->getElementsByTagName( "location" ); 24 | $this->dog_data_xml = $xmlLocation->item(0)->nodeValue; 25 | 26 | break; 27 | } 28 | 29 | } 30 | } 31 | else 32 | { 33 | throw new Exception("Dog applications xml file missing or corrupt"); 34 | } 35 | $xmlfile = file_get_contents($this->dog_data_xml); 36 | $xmlstring = simplexml_load_string($xmlfile); 37 | 38 | if ($xmlstring === false) { 39 | $errorString = "Failed loading XML: "; 40 | foreach(libxml_get_errors() as $error) { 41 | $errorString .= $error->message . " " ; } 42 | throw new Exception($errorString); } 43 | $json = json_encode($xmlstring); 44 | $this->dogs_array = json_decode($json,TRUE); 45 | 46 | } 47 | 48 | function __destruct() 49 | { 50 | 51 | $xmlstring = ''; 52 | $xmlstring .= "\n\n"; 53 | foreach ($this->dogs_array as $dogs=>$dogs_value) { 54 | foreach ($dogs_value as $dog => $dog_value) 55 | { 56 | $xmlstring .="<$dogs>\n"; 57 | foreach ($dog_value as $column => $column_value) 58 | { 59 | $xmlstring .= "<$column>" . $dog_value[$column] . "\n"; 60 | } 61 | $xmlstring .= "\n"; 62 | } 63 | } 64 | $xmlstring .= "\n"; 65 | 66 | $new_valid_data_file = preg_replace('/[0-9]+/', '', $this->dog_data_xml); 67 | // remove the previous date and time if it exists 68 | $oldxmldata = date('mdYhis') . $new_valid_data_file; 69 | if (!rename($this->dog_data_xml, $oldxmldata)) 70 | { 71 | throw new Exception("Backup file $oldxmldata could not be created."); 72 | } 73 | file_put_contents($new_valid_data_file,$xmlstring); 74 | 75 | } 76 | 77 | 78 | private function deleteRecord($recordNumber) 79 | { 80 | foreach ($this->dogs_array as $dogs=>&$dogs_value) { 81 | for($J=$recordNumber; $J < count($dogs_value) -1; $J++) { 82 | 83 | foreach ($dogs_value[$J] as $column => $column_value) 84 | { 85 | 86 | $dogs_value[$J][$column] = $dogs_value[$J + 1][$column]; 87 | } 88 | 89 | } 90 | unset ($dogs_value[count($dogs_value) -1]); 91 | } 92 | 93 | $change_string = date('mdYhis') . " | Delete | " . $recordNumber . "\n"; 94 | $chge_log_file = date('mdYhis') . $this->change_log_file; 95 | error_log($change_string,3,$chge_log_file); // might exceed 120 chars 96 | } 97 | 98 | private function readRecords($recordNumber) 99 | { 100 | if($recordNumber === "ALL") { 101 | return $this->dogs_array["dog"]; 102 | } 103 | else 104 | { 105 | return $this->dogs_array["dog"][$recordNumber]; 106 | } 107 | } 108 | 109 | private function insertRecords($records_array) 110 | { 111 | $dogs_array_size = count($this->dogs_array["dog"]); 112 | 113 | for($I=0;$I< count($records_array);$I++) 114 | { 115 | $this->dogs_array["dog"][$dogs_array_size + $I] = $records_array[$I]; 116 | 117 | } 118 | 119 | $change_string = date('mdYhis') . " | Insert | " . serialize($records_array) . "\n"; 120 | $chge_log_file = date('mdYhis') . $this->change_log_file; 121 | error_log($change_string,3,$chge_log_file); // might exceed 120 chars 122 | 123 | } 124 | 125 | private function updateRecords($records_array) 126 | { 127 | 128 | $chge_string = ""; 129 | foreach ($records_array as $records=>$records_value) 130 | { 131 | 132 | 133 | $this->dogs_array["dog"][$records] = $records_array[$records]; 134 | 135 | } 136 | 137 | $change_string = date('mdYhis') . " | Update | " . serialize($records_array) . "\n"; 138 | $chge_log_file = date('mdYhis') . $this->change_log_file; 139 | error_log($change_string,3,$chge_log_file); // might exceed 120 chars 140 | 141 | 142 | } 143 | function setChangeLogFile($value) 144 | { 145 | 146 | $this->dog_data_xml = $value; 147 | 148 | } 149 | function processRecords($change_Type, $records_array) 150 | { 151 | 152 | switch($change_Type) 153 | { 154 | 155 | case "Delete": 156 | 157 | $this->deleteRecord($records_array); 158 | break; 159 | case "Insert": 160 | $this->insertRecords($records_array); 161 | break; 162 | case "Update": 163 | $this->updateRecords($records_array); 164 | break; 165 | case "Display": 166 | return $this->readRecords($records_array); 167 | break; 168 | default: 169 | throw new Exception("Invalid XML file change type: $change_Type"); 170 | } 171 | 172 | } 173 | } 174 | 175 | ?> -------------------------------------------------------------------------------- /Chapter 8/e5dog_data.php: -------------------------------------------------------------------------------- 1 | load( 'e5dog_applications.xml' ); 14 | $searchNode = $xmlDoc->getElementsByTagName( "type" ); 15 | 16 | foreach( $searchNode as $searchNode ) 17 | { 18 | $valueID = $searchNode->getAttribute('ID'); 19 | 20 | if($valueID == "datastorage") 21 | { 22 | 23 | $xmlLocation = $searchNode->getElementsByTagName( "location" ); 24 | $this->dog_data_xml = $xmlLocation->item(0)->nodeValue; 25 | 26 | break; 27 | } 28 | 29 | } 30 | } 31 | else 32 | { 33 | throw new Exception("Dog applications xml file missing or corrupt"); 34 | } 35 | $xmlfile = file_get_contents($this->dog_data_xml); 36 | $xmlstring = simplexml_load_string($xmlfile); 37 | 38 | if ($xmlstring === false) { 39 | $errorString = "Failed loading XML: "; 40 | foreach(libxml_get_errors() as $error) { 41 | $errorString .= $error->message . " " ; } 42 | throw new Exception($errorString); } 43 | $json = json_encode($xmlstring); 44 | $this->dogs_array = json_decode($json,TRUE); 45 | 46 | } 47 | 48 | function __destruct() 49 | { 50 | 51 | $xmlstring = ''; 52 | $xmlstring .= "\n\n"; 53 | foreach ($this->dogs_array as $dogs=>$dogs_value) { 54 | foreach ($dogs_value as $dog => $dog_value) 55 | { 56 | $xmlstring .="<$dogs>\n"; 57 | foreach ($dog_value as $column => $column_value) 58 | { 59 | $xmlstring .= "<$column>" . $dog_value[$column] . "\n"; 60 | } 61 | $xmlstring .= "\n"; 62 | } 63 | } 64 | $xmlstring .= "\n"; 65 | 66 | $new_valid_data_file = preg_replace('/[0-9]+/', '', $this->dog_data_xml); 67 | // remove the previous date and time if it exists 68 | $oldxmldata = date('mdYhis') . $new_valid_data_file; 69 | if (!rename($this->dog_data_xml, $oldxmldata)) 70 | { 71 | throw new Exception("Backup file $oldxmldata could not be created."); 72 | } 73 | file_put_contents($new_valid_data_file,$xmlstring); 74 | 75 | } 76 | 77 | 78 | private function deleteRecord($recordNumber) 79 | { 80 | foreach ($this->dogs_array as $dogs=>&$dogs_value) { 81 | for($J=$recordNumber; $J < count($dogs_value) -1; $J++) { 82 | 83 | foreach ($dogs_value[$J] as $column => $column_value) 84 | { 85 | 86 | $dogs_value[$J][$column] = $dogs_value[$J + 1][$column]; 87 | } 88 | 89 | } 90 | unset ($dogs_value[count($dogs_value) -1]); 91 | } 92 | 93 | $change_string = date('mdYhis') . " | Delete | " . $recordNumber . "\n"; 94 | $chge_log_file = date('mdYhis') . $this->change_log_file; 95 | error_log($change_string,3,$chge_log_file); // might exceed 120 chars 96 | } 97 | 98 | private function readRecords($recordNumber) 99 | { 100 | if($recordNumber === "ALL") { 101 | return $this->dogs_array["dog"]; 102 | } 103 | else 104 | { 105 | return $this->dogs_array["dog"][$recordNumber]; 106 | } 107 | } 108 | 109 | private function insertRecords($records_array) 110 | { 111 | $dogs_array_size = count($this->dogs_array["dog"]); 112 | 113 | for($I=0;$I< count($records_array);$I++) 114 | { 115 | $this->dogs_array["dog"][$dogs_array_size + $I] = $records_array[$I]; 116 | 117 | } 118 | 119 | $change_string = date('mdYhis') . " | Insert | " . serialize($records_array) . "\n"; 120 | $chge_log_file = date('mdYhis') . $this->change_log_file; 121 | error_log($change_string,3,$chge_log_file); // might exceed 120 chars 122 | 123 | } 124 | 125 | private function updateRecords($records_array) 126 | { 127 | 128 | $chge_string = ""; 129 | foreach ($records_array as $records=>$records_value) 130 | { 131 | 132 | 133 | $this->dogs_array["dog"][$records] = $records_array[$records]; 134 | 135 | } 136 | 137 | $change_string = date('mdYhis') . " | Update | " . serialize($records_array) . "\n"; 138 | $chge_log_file = date('mdYhis') . $this->change_log_file; 139 | error_log($change_string,3,$chge_log_file); // might exceed 120 chars 140 | 141 | 142 | } 143 | function setChangeLogFile($value) 144 | { 145 | 146 | $this->dog_data_xml = $value; 147 | 148 | } 149 | function processRecords($change_Type, $records_array) 150 | { 151 | 152 | switch($change_Type) 153 | { 154 | 155 | case "Delete": 156 | 157 | $this->deleteRecord($records_array); 158 | break; 159 | case "Insert": 160 | $this->insertRecords($records_array); 161 | break; 162 | case "Update": 163 | $this->updateRecords($records_array); 164 | break; 165 | case "Display": 166 | return $this->readRecords($records_array); 167 | break; 168 | default: 169 | throw new Exception("Invalid XML file change type: $change_Type"); 170 | } 171 | 172 | } 173 | } 174 | 175 | ?> -------------------------------------------------------------------------------- /Chapter 9/e5dog_data.php: -------------------------------------------------------------------------------- 1 | load( 'edog_applications.xml' ); 14 | $searchNode = $xmlDoc->getElementsByTagName( "type" ); 15 | 16 | foreach( $searchNode as $searchNode ) 17 | { 18 | $valueID = $searchNode->getAttribute('ID'); 19 | 20 | if($valueID == "datastorage") 21 | { 22 | 23 | $xmlLocation = $searchNode->getElementsByTagName( "location" ); 24 | $this->dog_data_xml = $xmlLocation->item(0)->nodeValue; 25 | 26 | break; 27 | } 28 | 29 | } 30 | } 31 | else 32 | { 33 | throw new Exception("Dog applications xml file missing or corrupt"); 34 | } 35 | $xmlfile = file_get_contents($this->dog_data_xml); 36 | $xmlstring = simplexml_load_string($xmlfile); 37 | 38 | if ($xmlstring === false) { 39 | $errorString = "Failed loading XML: "; 40 | foreach(libxml_get_errors() as $error) { 41 | $errorString .= $error->message . " " ; } 42 | throw new Exception($errorString); } 43 | $json = json_encode($xmlstring); 44 | $this->dogs_array = json_decode($json,TRUE); 45 | 46 | } 47 | 48 | function __destruct() 49 | { 50 | 51 | $xmlstring = ''; 52 | $xmlstring .= "\n\n"; 53 | foreach ($this->dogs_array as $dogs=>$dogs_value) { 54 | foreach ($dogs_value as $dog => $dog_value) 55 | { 56 | $xmlstring .="<$dogs>\n"; 57 | foreach ($dog_value as $column => $column_value) 58 | { 59 | $xmlstring .= "<$column>" . $dog_value[$column] . "\n"; 60 | } 61 | $xmlstring .= "\n"; 62 | } 63 | } 64 | $xmlstring .= "\n"; 65 | 66 | $new_valid_data_file = preg_replace('/[0-9]+/', '', $this->dog_data_xml); 67 | // remove the previous date and time if it exists 68 | $oldxmldata = date('mdYhis') . $new_valid_data_file; 69 | if (!rename($this->dog_data_xml, $oldxmldata)) 70 | { 71 | throw new Exception("Backup file $oldxmldata could not be created."); 72 | } 73 | file_put_contents($new_valid_data_file,$xmlstring); 74 | 75 | } 76 | 77 | 78 | private function deleteRecord($recordNumber) 79 | { 80 | foreach ($this->dogs_array as $dogs=>&$dogs_value) { 81 | for($J=$recordNumber; $J < count($dogs_value) -1; $J++) { 82 | 83 | foreach ($dogs_value[$J] as $column => $column_value) 84 | { 85 | 86 | $dogs_value[$J][$column] = $dogs_value[$J + 1][$column]; 87 | } 88 | 89 | } 90 | unset ($dogs_value[count($dogs_value) -1]); 91 | } 92 | 93 | $change_string = date('mdYhis') . " | Delete | " . $recordNumber . "\n"; 94 | $chge_log_file = date('mdYhis') . $this->change_log_file; 95 | error_log($change_string,3,$chge_log_file); // might exceed 120 chars 96 | } 97 | 98 | private function readRecords($recordNumber) 99 | { 100 | 101 | if($recordNumber === "ALL") { 102 | return $this->dogs_array["dog"]; 103 | 104 | } 105 | else 106 | { 107 | return $this->dogs_array["dog"][$recordNumber]; 108 | } 109 | } 110 | 111 | private function insertRecords($records_array) 112 | { 113 | $dogs_array_size = count($this->dogs_array["dog"]); 114 | 115 | for($I=0;$I< count($records_array);$I++) 116 | { 117 | $this->dogs_array["dog"][$dogs_array_size + $I] = $records_array[$I]; 118 | 119 | } 120 | 121 | $change_string = date('mdYhis') . " | Insert | " . serialize($records_array) . "\n"; 122 | $chge_log_file = date('mdYhis') . $this->change_log_file; 123 | error_log($change_string,3,$chge_log_file); // might exceed 120 chars 124 | 125 | } 126 | 127 | private function updateRecords($records_array) 128 | { 129 | 130 | $chge_string = ""; 131 | foreach ($records_array as $records=>$records_value) 132 | { 133 | 134 | 135 | $this->dogs_array["dog"][$records] = $records_array[$records]; 136 | 137 | } 138 | 139 | $change_string = date('mdYhis') . " | Update | " . serialize($records_array) . "\n"; 140 | $chge_log_file = date('mdYhis') . $this->change_log_file; 141 | error_log($change_string,3,$chge_log_file); // might exceed 120 chars 142 | 143 | 144 | } 145 | function setChangeLogFile($value) 146 | { 147 | 148 | $this->dog_data_xml = $value; 149 | 150 | } 151 | function processRecords($change_Type, $records_array) 152 | { 153 | 154 | switch($change_Type) 155 | { 156 | 157 | case "Delete": 158 | 159 | $this->deleteRecord($records_array); 160 | break; 161 | case "Insert": 162 | $this->insertRecords($records_array); 163 | break; 164 | case "Update": 165 | $this->updateRecords($records_array); 166 | break; 167 | case "Display": 168 | return $this->readRecords($records_array); 169 | break; 170 | default: 171 | throw new Exception("Invalid XML file change type: $change_Type"); 172 | } 173 | 174 | } 175 | } 176 | 177 | ?> -------------------------------------------------------------------------------- /Chapter 8/e4login.php: -------------------------------------------------------------------------------- 1 | '; 9 | $xmlstring .= "\n\n"; 10 | 11 | 12 | foreach($valid_useridpasswords as $users) 13 | { 14 | foreach($users as $user) 15 | { 16 | 17 | $xmlstring .="\n" . $user['userid'] . "\n"; 18 | $xmlstring .="" . $user['password'] . "\n"; 19 | $xmlstring .="" . $user['datestamp'] . "\n"; 20 | $xmlstring .= "" . $user['attempts'] . "\n"; 21 | $xmlstring .= "" . $user['lastattempt'] . "\n"; 22 | $xmlstring .= "" . $user['validattempt'] . "\n\n"; 23 | 24 | } 25 | } 26 | $xmlstring .= "\n"; 27 | 28 | $new_valid_data_file = preg_replace('/[0-9]+/', '', $dog_data_xml); 29 | // remove the previous date and time if it exists 30 | $oldxmldata = date('mdYhis') . $new_valid_data_file; 31 | if (!rename($dog_data_xml, $oldxmldata)) 32 | { 33 | throw new Exception("Backup file $oldxmldata could not be created."); 34 | } 35 | file_put_contents($new_valid_data_file,$xmlstring); 36 | 37 | } 38 | 39 | function retrieve_useridpasswordfile() 40 | { 41 | 42 | $xmlDoc = new DOMDocument(); 43 | if ( file_exists("edog_applications.xml") ) 44 | { 45 | $xmlDoc->load( 'edog_applications.xml' ); 46 | $searchNode = $xmlDoc->getElementsByTagName( "type" ); 47 | 48 | foreach( $searchNode as $searchNode ) 49 | { 50 | $valueID = $searchNode->getAttribute('ID'); 51 | 52 | if($valueID == "UIDPASS") 53 | { 54 | 55 | $xmlLocation = $searchNode->getElementsByTagName( "location" ); 56 | $dog_data_xml = $xmlLocation->item(0)->nodeValue; 57 | 58 | break; 59 | } 60 | 61 | } 62 | } 63 | else 64 | { 65 | throw new Exception("Dog applications xml file missing or corrupt"); 66 | } 67 | 68 | return $dog_data_xml; 69 | 70 | } 71 | 72 | try { 73 | if ((isset($_POST['username'])) && (isset($_POST['password']))) 74 | { 75 | 76 | libxml_use_internal_errors(true); 77 | 78 | $dog_data_xml = retrieve_useridpasswordfile(); 79 | $xmlfile = file_get_contents($dog_data_xml); 80 | $xmlstring = simplexml_load_string($xmlfile); 81 | 82 | if ($xmlstring === false) { 83 | $errorString = "Failed loading XML: "; 84 | foreach(libxml_get_errors() as $error) { 85 | $errorString .= $error->message . " " ; } 86 | throw new Exception($errorString); } 87 | $json = json_encode($xmlstring); 88 | 89 | $valid_useridpasswords = json_decode($json,TRUE); 90 | 91 | $userid = $_POST['username']; 92 | $password = $_POST['password']; 93 | 94 | $I = 0; 95 | $passed = FALSE; 96 | foreach($valid_useridpasswords as $users) 97 | { 98 | 99 | foreach($users as $user) 100 | { 101 | 102 | if (in_array($userid, $user)) 103 | { 104 | $hash = $user['password']; 105 | $currenttime = strtotime(date('Y-m-d')); 106 | $stamptime = strtotime($user['datestamp']); 107 | 108 | if ($currenttime > $stamptime) 109 | { 110 | 111 | // password expired force password change 112 | $_SESSION['message'] = "Your password has expired. Please create a new one."; 113 | header("Location: e75changepassword.php"); 114 | } 115 | 116 | if (($user['attempts'] < 3) || ( date('mdYhis', strtotime('-5 minutes')) >= $user['lastattempt'])) 117 | { 118 | 119 | if(password_verify($password,$hash)) 120 | { 121 | $passed = TRUE; 122 | $valid_useridpasswords['user'][$I]['validattempt'] = date('mdYhis'); // shows last time successful login 123 | $valid_useridpasswords['user'][$I]['attempts'] = 0; // successful login resets to zero 124 | $_SESSION['username'] = $userid; 125 | $_SESSION['password'] = $password; 126 | saveupfile($dog_data_xml,$valid_useridpasswords); // save changes before header call 127 | $login_string = date('mdYhis') . " | Login | " . $userid . "\n"; 128 | error_log($login_string,3,$user_log_file); 129 | header("Location: e1lab.php"); 130 | } 131 | else 132 | { 133 | $valid_useridpasswords['user'][$I]['lastattempt'] = date('mdYhis'); // last attempted login 134 | } 135 | } 136 | } 137 | 138 | $I++; 139 | 140 | } 141 | } 142 | // drops to here if not valid password/userid or too many attempts 143 | if (!$passed) 144 | { 145 | $I--; 146 | echo "Invalid Userid/Password"; 147 | $valid_useridpasswords['user'][$I]['attempts'] = $user['attempts'] + 1; // add 1 to attempts 148 | // if not successful must save the values 149 | saveupfile($dog_data_xml,$valid_useridpasswords); 150 | } 151 | } 152 | } 153 | 154 | catch(Exception $e) 155 | { 156 | 157 | echo $e->getMessage(); 158 | } 159 | 160 | ?> 161 |

162 | Userid must contain eight or more characters.
163 | Password must contain at least one number, one uppercase and lowercase letter, and at least 8 total characters.
164 | Username:
165 | Password:
167 | 168 |
-------------------------------------------------------------------------------- /Chapter 8/e5changepassword.php: -------------------------------------------------------------------------------- 1 | '; 8 | $xmlstring .= "\n\n"; 9 | 10 | 11 | foreach($valid_useridpasswords as $users) 12 | { 13 | foreach($users as $user) 14 | { 15 | 16 | $xmlstring .="\n" . $user['userid'] . "\n"; 17 | $xmlstring .="" . $user['password'] . "\n"; 18 | $xmlstring .="" . $user['datestamp'] . "\n"; 19 | $xmlstring .= "" . $user['attempts'] . "\n"; 20 | $xmlstring .= "" . $user['lastattempt'] . "\n"; 21 | $xmlstring .= "" . $user['validattempt'] . "\n\n"; 22 | 23 | } 24 | } 25 | $xmlstring .= "\n"; 26 | 27 | $new_valid_data_file = preg_replace('/[0-9]+/', '', $dog_data_xml); 28 | // remove the previous date and time if it exists 29 | $oldxmldata = date('mdYhis') . $new_valid_data_file; 30 | if (!rename($dog_data_xml, $oldxmldata)) 31 | { 32 | throw new Exception("Backup file $oldxmldata could not be created."); 33 | } 34 | file_put_contents($new_valid_data_file,$xmlstring); 35 | 36 | } 37 | function retrieve_useridpasswordfile() 38 | { 39 | 40 | $xmlDoc = new DOMDocument(); 41 | if ( file_exists("edog_applications.xml") ) 42 | { 43 | $xmlDoc->load( 'edog_applications.xml' ); 44 | $searchNode = $xmlDoc->getElementsByTagName( "type" ); 45 | 46 | foreach( $searchNode as $searchNode ) 47 | { 48 | $valueID = $searchNode->getAttribute('ID'); 49 | 50 | if($valueID == "UIDPASS") 51 | { 52 | 53 | $xmlLocation = $searchNode->getElementsByTagName( "location" ); 54 | $dog_data_xml = $xmlLocation->item(0)->nodeValue; 55 | 56 | break; 57 | } 58 | 59 | } 60 | } 61 | else 62 | { 63 | throw new Exception("Dog applications xml file missing or corrupt"); 64 | } 65 | 66 | return $dog_data_xml; 67 | 68 | } 69 | 70 | 71 | if (!(isset($_SESSION['message']))) 72 | { 73 | // valid userid and password but password expired 74 | echo $_SESSION['message']; 75 | 76 | } 77 | try { 78 | if((isset($_POST['username'])) && (isset($_POST['oldpassword'])) && (isset($_POST['password'])) && (isset($_POST['password_confirm']))) 79 | { 80 | 81 | libxml_use_internal_errors(true); 82 | 83 | $dog_data_xml = retrieve_useridpasswordfile(); 84 | $xmlfile = file_get_contents($dog_data_xml); 85 | $xmlstring = simplexml_load_string($xmlfile); 86 | 87 | if ($xmlstring === false) { 88 | $errorString = "Failed loading XML: "; 89 | foreach(libxml_get_errors() as $error) { 90 | $errorString .= $error->message . " " ; } 91 | throw new Exception($errorString); } 92 | $json = json_encode($xmlstring); 93 | 94 | $valid_useridpasswords = json_decode($json,TRUE); 95 | 96 | $userid = $_POST['username']; 97 | $npassword = $_POST['password']; 98 | $newpassword = password_hash($npassword, PASSWORD_DEFAULT); 99 | $password = $_POST['oldpassword']; 100 | $datestamp = date('Y-m-d', strtotime('+30 days')); 101 | $I = 0; 102 | $passed = FALSE; 103 | foreach($valid_useridpasswords as $users) 104 | { 105 | 106 | foreach($users as $user) 107 | { 108 | 109 | if (in_array($userid, $user)) 110 | { 111 | $hash = $user['password']; 112 | 113 | if(password_verify($password,$hash)) 114 | { 115 | $passed = TRUE; 116 | $valid_useridpasswords['user'][$I]['password'] = $newpassword; 117 | $valid_useridpasswords['user'][$I]['datestamp'] = $datestamp; 118 | $valid_useridpasswords['user'][$I]['attempts'] = 0; 119 | saveupfile($dog_data_xml,$valid_useridpasswords); // save changes before header call 120 | $login_string = date('mdYhis') . " | Password Changed | " . $userid . "\n"; 121 | error_log($login_string,3,$user_log_file); 122 | header("Location: e4login.php"); 123 | } 124 | 125 | } 126 | $I++; 127 | 128 | } 129 | 130 | } 131 | 132 | // drops to here if not valid password/userid or too many attempts 133 | if (!$passed) 134 | { 135 | 136 | echo "Invalid Userid/Password"; 137 | 138 | } 139 | } 140 | 141 | } 142 | catch(Exception $e) 143 | { 144 | 145 | echo $e->getMessage(); 146 | } 147 | 148 | ?> 149 |
150 | Userid must contain eight or more characters.
151 | Password must contain at least one number, one uppercase and lowercase letter, and at least 8 total characters.
152 | Username:
153 | Old Password:
155 | New Password:
157 | Confirm Password: 158 | 168 | 169 |
-------------------------------------------------------------------------------- /Chapter 9/e4login.php: -------------------------------------------------------------------------------- 1 | '; 9 | $xmlstring .= "\n\n"; 10 | 11 | 12 | foreach($valid_useridpasswords as $users) 13 | { 14 | foreach($users as $user) 15 | { 16 | 17 | $xmlstring .="\n" . $user['userid'] . "\n"; 18 | $xmlstring .="" . $user['password'] . "\n"; 19 | $xmlstring .="" . $user['datestamp'] . "\n"; 20 | $xmlstring .= "" . $user['attempts'] . "\n"; 21 | $xmlstring .= "" . $user['lastattempt'] . "\n"; 22 | $xmlstring .= "" . $user['validattempt'] . "\n\n"; 23 | 24 | } 25 | } 26 | $xmlstring .= "\n"; 27 | 28 | $new_valid_data_file = preg_replace('/[0-9]+/', '', $dog_data_xml); 29 | // remove the previous date and time if it exists 30 | $oldxmldata = date('mdYhis') . $new_valid_data_file; 31 | if (!rename($dog_data_xml, $oldxmldata)) 32 | { 33 | throw new Exception("Backup file $oldxmldata could not be created."); 34 | } 35 | file_put_contents($new_valid_data_file,$xmlstring); 36 | 37 | } 38 | 39 | function retrieve_useridpasswordfile() 40 | { 41 | 42 | $xmlDoc = new DOMDocument(); 43 | if ( file_exists("edog_applications.xml") ) 44 | { 45 | $xmlDoc->load( 'edog_applications.xml' ); 46 | $searchNode = $xmlDoc->getElementsByTagName( "type" ); 47 | 48 | foreach( $searchNode as $searchNode ) 49 | { 50 | $valueID = $searchNode->getAttribute('ID'); 51 | 52 | if($valueID == "UIDPASS") 53 | { 54 | 55 | $xmlLocation = $searchNode->getElementsByTagName( "location" ); 56 | $dog_data_xml = $xmlLocation->item(0)->nodeValue; 57 | 58 | break; 59 | } 60 | 61 | } 62 | } 63 | else 64 | { 65 | throw new Exception("Dog applications xml file missing or corrupt"); 66 | } 67 | 68 | return $dog_data_xml; 69 | 70 | } 71 | 72 | try { 73 | if ((isset($_POST['username'])) && (isset($_POST['password']))) 74 | { 75 | 76 | libxml_use_internal_errors(true); 77 | 78 | $dog_data_xml = retrieve_useridpasswordfile(); 79 | $xmlfile = file_get_contents($dog_data_xml); 80 | $xmlstring = simplexml_load_string($xmlfile); 81 | 82 | if ($xmlstring === false) { 83 | $errorString = "Failed loading XML: "; 84 | foreach(libxml_get_errors() as $error) { 85 | $errorString .= $error->message . " " ; } 86 | throw new Exception($errorString); } 87 | $json = json_encode($xmlstring); 88 | 89 | $valid_useridpasswords = json_decode($json,TRUE); 90 | 91 | $userid = $_POST['username']; 92 | $password = $_POST['password']; 93 | 94 | $I = 0; 95 | $passed = FALSE; 96 | foreach($valid_useridpasswords as $users) 97 | { 98 | 99 | foreach($users as $user) 100 | { 101 | 102 | if (in_array($userid, $user)) 103 | { 104 | $hash = $user['password']; 105 | $currenttime = strtotime(date('Y-m-d')); 106 | $stamptime = strtotime($user['datestamp']); 107 | 108 | if ($currenttime > $stamptime) 109 | { 110 | 111 | // password expired force password change 112 | 113 | header("Location: e75changepassword.php"); 114 | } 115 | 116 | if (($user['attempts'] < 3) || ( date('mdYhis', strtotime('-5 minutes')) >= $user['lastattempt'])) 117 | { 118 | 119 | if(password_verify($password,$hash)) 120 | { 121 | $passed = TRUE; 122 | $valid_useridpasswords['user'][$I]['validattempt'] = date('mdYhis'); // shows last time successful login 123 | $valid_useridpasswords['user'][$I]['attempts'] = 0; // successful login resets to zero 124 | $_SESSION['username'] = $userid; 125 | $_SESSION['password'] = $password; 126 | saveupfile($dog_data_xml,$valid_useridpasswords); // save changes before header call 127 | $login_string = date('mdYhis') . " | Login | " . $userid . "\n"; 128 | error_log($login_string,3,$user_log_file); 129 | header("Location: elab.php"); 130 | } 131 | else 132 | { 133 | $valid_useridpasswords['user'][$I]['lastattempt'] = date('mdYhis'); // last attempted login 134 | } 135 | } 136 | } 137 | 138 | $I++; 139 | 140 | } 141 | } 142 | // drops to here if not valid password/userid or too many attempts 143 | if (!$passed) 144 | { 145 | $I--; 146 | echo "Invalid Userid/Password"; 147 | $valid_useridpasswords['user'][$I]['attempts'] = $user['attempts'] + 1; // add 1 to attempts 148 | // if not successful must save the values 149 | saveupfile($dog_data_xml,$valid_useridpasswords); 150 | } 151 | } 152 | } 153 | 154 | catch(Exception $e) 155 | { 156 | 157 | echo $e->getMessage(); 158 | } 159 | 160 | ?> 161 | 162 | ABC Canine Shelter Reservation System 163 | 164 | 167 | 168 | 169 |
170 | 172 |
173 |
174 | Userid must contain eight or more characters.
175 | Password must contain at least one number, one uppercase and lowercase letter, and at least 8 total characters.
176 | Username:
177 | Password:
179 | 180 |
181 |
182 | 183 |
184 | 185 | -------------------------------------------------------------------------------- /Chapter 6/ebreeds.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Affenpinscher 4 | Afghan Hound 5 | Airedale Terrier 6 | Akita 7 | Alaskan Malamute 8 | American English Coonhound 9 | American Eskimo Dog 10 | American Foxhound 11 | American Staffordshire Terrier 12 | American Water Spaniel 13 | Anatolian Shepherd Dog 14 | Australian Cattle Dog 15 | Australian Shepherd 16 | Australian Terrier 17 | Basenji 18 | Basset Hound 19 | Beagle 20 | Bearded Collie 21 | Beauceron 22 | Bedlington Terrier 23 | Belgian Malinois 24 | Belgian Sheepdog 25 | Belgian Tervuren 26 | Bernese Mountain Dog 27 | Bichon Frise 28 | Black Russian Terrier 29 | Black and Tan Coonhound 30 | Bloodhound 31 | Bluetick Coonhound 32 | Border Collie 33 | Border Terrier 34 | Borzoi 35 | Boston Terrier 36 | Bouvier des Flandres 37 | Boxer 38 | Boykin Spaniel 39 | Briard 40 | Brittany 41 | Brussels Griffon 42 | Bull Terrier 43 | Bulldog 44 | Bullmastiff 45 | Cairn Terrier 46 | Canaan Dog 47 | Cane Corso 48 | Cardigan Welsh Corgi 49 | Cavalier King Charles Spaniel 50 | Cesky Terrier 51 | Chesapeake Bay Retriever 52 | Chihuahua 53 | Chinese Crested 54 | Chinese Shar-Pei 55 | Chinook 56 | Chow Chow 57 | Clumber Spaniel 58 | Cocker Spaniel 59 | Collie 60 | Coton de Tulear 61 | Curly-Coated Retriever 62 | Dachshund 63 | Dalmatian 64 | Dandie Dinmont Terrier 65 | Doberman Pinscher 66 | Dogue de Bordeaux 67 | English Cocker Spaniel 68 | English Foxhound 69 | English Setter 70 | English Springer Spaniel 71 | English Toy Spaniel 72 | Entlebucher Mountain Dog 73 | Field Spaniel 74 | Finnish Lapphund 75 | Finnish Spitz 76 | Flat-Coated Retriever 77 | French Bulldog 78 | German Pinscher 79 | German Shepherd Dog 80 | German Shorthaired Pointer 81 | German Wirehaired Pointer 82 | Giant Schnauzer 83 | Glen of Imaal Terrier 84 | Golden Retriever 85 | Gordon Setter 86 | Great Dane 87 | Great Pyrenees 88 | Greater Swiss Mountain Dog 89 | Greyhound 90 | Harrier 91 | Havanese 92 | Ibizan Hound 93 | Icelandic Sheepdog 94 | Irish Red and White Setter 95 | Irish Setter 96 | Irish Terrier 97 | Irish Water Spaniel 98 | Irish Wolfhound 99 | Italian Greyhound 100 | Japanese Chin 101 | Keeshond 102 | Kerry Blue Terrier 103 | Komondor 104 | Kuvasz 105 | Labrador Retriever 106 | Lakeland Terrier 107 | Leonberger 108 | Lhasa Apso 109 | Lowchen 110 | Maltese 111 | Manchester Terrier 112 | Mastiff 113 | Miniature Bull Terrier 114 | Miniature Pinscher 115 | Miniature Schnauzer 116 | Neapolitan Mastiff 117 | Newfoundland 118 | Norfolk Terrier 119 | Norwegian Buhund 120 | Norwegian Elkhound 121 | Norwegian Lundehund 122 | Norwich Terrier 123 | Nova Scotia Duck Tolling Retriever 124 | Old English Sheepdog 125 | Otterhound 126 | Papillon 127 | Parson Russell Terrier 128 | Pekingese 129 | Pembroke Welsh Corgi 130 | Petit Basset Griffon Vendeen 131 | Pharaoh Hound 132 | Plott 133 | Pointer 134 | Polish Lowland Sheepdog 135 | Pomeranian 136 | Poodle 137 | Portuguese Podengo Pequeno 138 | Portuguese Water Dog 139 | Pug 140 | Puli 141 | Pyrenean Shepherd 142 | Rat Terrier 143 | Redbone Coonhound 144 | Rhodesian Ridgeback 145 | Rottweiler 146 | Russell Terrier 147 | Saluki 148 | Samoyed 149 | Schipperke 150 | Scottish Deerhound 151 | Scottish Terrier 152 | Sealyham Terrier 153 | Shetland Sheepdog 154 | Shiba Inu 155 | Shih Tzu 156 | Siberian Husky 157 | Silky Terrier 158 | Skye Terrier 159 | Smooth Fox Terrier 160 | Soft Coated Wheaten Terrier 161 | Spinone Italiano 162 | St. Bernard 163 | Staffordshire Bull Terrier 164 | Standard Schnauzer 165 | Sussex Spaniel 166 | Swedish Vallhund 167 | Tibetan Mastiff 168 | Tibetan Spaniel 169 | Tibetan Terrier 170 | Toy Fox Terrier 171 | Treeing Walker Coonhound 172 | Vizsla 173 | Weimaraner 174 | Welsh Springer Spaniel 175 | Welsh Terrier 176 | West Highland White Terrier 177 | Whippet 178 | Wire Fox Terrier 179 | Wirehaired Pointing Griffon 180 | Wirehaired Vizsla 181 | Xoloitzcuintli 182 | Yorkshire Terrier 183 | -------------------------------------------------------------------------------- /Chapter 8/ebreeds.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Affenpinscher 4 | Afghan Hound 5 | Airedale Terrier 6 | Akita 7 | Alaskan Malamute 8 | American English Coonhound 9 | American Eskimo Dog 10 | American Foxhound 11 | American Staffordshire Terrier 12 | American Water Spaniel 13 | Anatolian Shepherd Dog 14 | Australian Cattle Dog 15 | Australian Shepherd 16 | Australian Terrier 17 | Basenji 18 | Basset Hound 19 | Beagle 20 | Bearded Collie 21 | Beauceron 22 | Bedlington Terrier 23 | Belgian Malinois 24 | Belgian Sheepdog 25 | Belgian Tervuren 26 | Bernese Mountain Dog 27 | Bichon Frise 28 | Black Russian Terrier 29 | Black and Tan Coonhound 30 | Bloodhound 31 | Bluetick Coonhound 32 | Border Collie 33 | Border Terrier 34 | Borzoi 35 | Boston Terrier 36 | Bouvier des Flandres 37 | Boxer 38 | Boykin Spaniel 39 | Briard 40 | Brittany 41 | Brussels Griffon 42 | Bull Terrier 43 | Bulldog 44 | Bullmastiff 45 | Cairn Terrier 46 | Canaan Dog 47 | Cane Corso 48 | Cardigan Welsh Corgi 49 | Cavalier King Charles Spaniel 50 | Cesky Terrier 51 | Chesapeake Bay Retriever 52 | Chihuahua 53 | Chinese Crested 54 | Chinese Shar-Pei 55 | Chinook 56 | Chow Chow 57 | Clumber Spaniel 58 | Cocker Spaniel 59 | Collie 60 | Coton de Tulear 61 | Curly-Coated Retriever 62 | Dachshund 63 | Dalmatian 64 | Dandie Dinmont Terrier 65 | Doberman Pinscher 66 | Dogue de Bordeaux 67 | English Cocker Spaniel 68 | English Foxhound 69 | English Setter 70 | English Springer Spaniel 71 | English Toy Spaniel 72 | Entlebucher Mountain Dog 73 | Field Spaniel 74 | Finnish Lapphund 75 | Finnish Spitz 76 | Flat-Coated Retriever 77 | French Bulldog 78 | German Pinscher 79 | German Shepherd Dog 80 | German Shorthaired Pointer 81 | German Wirehaired Pointer 82 | Giant Schnauzer 83 | Glen of Imaal Terrier 84 | Golden Retriever 85 | Gordon Setter 86 | Great Dane 87 | Great Pyrenees 88 | Greater Swiss Mountain Dog 89 | Greyhound 90 | Harrier 91 | Havanese 92 | Ibizan Hound 93 | Icelandic Sheepdog 94 | Irish Red and White Setter 95 | Irish Setter 96 | Irish Terrier 97 | Irish Water Spaniel 98 | Irish Wolfhound 99 | Italian Greyhound 100 | Japanese Chin 101 | Keeshond 102 | Kerry Blue Terrier 103 | Komondor 104 | Kuvasz 105 | Labrador Retriever 106 | Lakeland Terrier 107 | Leonberger 108 | Lhasa Apso 109 | Lowchen 110 | Maltese 111 | Manchester Terrier 112 | Mastiff 113 | Miniature Bull Terrier 114 | Miniature Pinscher 115 | Miniature Schnauzer 116 | Neapolitan Mastiff 117 | Newfoundland 118 | Norfolk Terrier 119 | Norwegian Buhund 120 | Norwegian Elkhound 121 | Norwegian Lundehund 122 | Norwich Terrier 123 | Nova Scotia Duck Tolling Retriever 124 | Old English Sheepdog 125 | Otterhound 126 | Papillon 127 | Parson Russell Terrier 128 | Pekingese 129 | Pembroke Welsh Corgi 130 | Petit Basset Griffon Vendeen 131 | Pharaoh Hound 132 | Plott 133 | Pointer 134 | Polish Lowland Sheepdog 135 | Pomeranian 136 | Poodle 137 | Portuguese Podengo Pequeno 138 | Portuguese Water Dog 139 | Pug 140 | Puli 141 | Pyrenean Shepherd 142 | Rat Terrier 143 | Redbone Coonhound 144 | Rhodesian Ridgeback 145 | Rottweiler 146 | Russell Terrier 147 | Saluki 148 | Samoyed 149 | Schipperke 150 | Scottish Deerhound 151 | Scottish Terrier 152 | Sealyham Terrier 153 | Shetland Sheepdog 154 | Shiba Inu 155 | Shih Tzu 156 | Siberian Husky 157 | Silky Terrier 158 | Skye Terrier 159 | Smooth Fox Terrier 160 | Soft Coated Wheaten Terrier 161 | Spinone Italiano 162 | St. Bernard 163 | Staffordshire Bull Terrier 164 | Standard Schnauzer 165 | Sussex Spaniel 166 | Swedish Vallhund 167 | Tibetan Mastiff 168 | Tibetan Spaniel 169 | Tibetan Terrier 170 | Toy Fox Terrier 171 | Treeing Walker Coonhound 172 | Vizsla 173 | Weimaraner 174 | Welsh Springer Spaniel 175 | Welsh Terrier 176 | West Highland White Terrier 177 | Whippet 178 | Wire Fox Terrier 179 | Wirehaired Pointing Griffon 180 | Wirehaired Vizsla 181 | Xoloitzcuintli 182 | Yorkshire Terrier 183 | -------------------------------------------------------------------------------- /Chapter 9/ebreeds.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Affenpinscher 4 | Afghan Hound 5 | Airedale Terrier 6 | Akita 7 | Alaskan Malamute 8 | American English Coonhound 9 | American Eskimo Dog 10 | American Foxhound 11 | American Staffordshire Terrier 12 | American Water Spaniel 13 | Anatolian Shepherd Dog 14 | Australian Cattle Dog 15 | Australian Shepherd 16 | Australian Terrier 17 | Basenji 18 | Basset Hound 19 | Beagle 20 | Bearded Collie 21 | Beauceron 22 | Bedlington Terrier 23 | Belgian Malinois 24 | Belgian Sheepdog 25 | Belgian Tervuren 26 | Bernese Mountain Dog 27 | Bichon Frise 28 | Black Russian Terrier 29 | Black and Tan Coonhound 30 | Bloodhound 31 | Bluetick Coonhound 32 | Border Collie 33 | Border Terrier 34 | Borzoi 35 | Boston Terrier 36 | Bouvier des Flandres 37 | Boxer 38 | Boykin Spaniel 39 | Briard 40 | Brittany 41 | Brussels Griffon 42 | Bull Terrier 43 | Bulldog 44 | Bullmastiff 45 | Cairn Terrier 46 | Canaan Dog 47 | Cane Corso 48 | Cardigan Welsh Corgi 49 | Cavalier King Charles Spaniel 50 | Cesky Terrier 51 | Chesapeake Bay Retriever 52 | Chihuahua 53 | Chinese Crested 54 | Chinese Shar-Pei 55 | Chinook 56 | Chow Chow 57 | Clumber Spaniel 58 | Cocker Spaniel 59 | Collie 60 | Coton de Tulear 61 | Curly-Coated Retriever 62 | Dachshund 63 | Dalmatian 64 | Dandie Dinmont Terrier 65 | Doberman Pinscher 66 | Dogue de Bordeaux 67 | English Cocker Spaniel 68 | English Foxhound 69 | English Setter 70 | English Springer Spaniel 71 | English Toy Spaniel 72 | Entlebucher Mountain Dog 73 | Field Spaniel 74 | Finnish Lapphund 75 | Finnish Spitz 76 | Flat-Coated Retriever 77 | French Bulldog 78 | German Pinscher 79 | German Shepherd Dog 80 | German Shorthaired Pointer 81 | German Wirehaired Pointer 82 | Giant Schnauzer 83 | Glen of Imaal Terrier 84 | Golden Retriever 85 | Gordon Setter 86 | Great Dane 87 | Great Pyrenees 88 | Greater Swiss Mountain Dog 89 | Greyhound 90 | Harrier 91 | Havanese 92 | Ibizan Hound 93 | Icelandic Sheepdog 94 | Irish Red and White Setter 95 | Irish Setter 96 | Irish Terrier 97 | Irish Water Spaniel 98 | Irish Wolfhound 99 | Italian Greyhound 100 | Japanese Chin 101 | Keeshond 102 | Kerry Blue Terrier 103 | Komondor 104 | Kuvasz 105 | Labrador Retriever 106 | Lakeland Terrier 107 | Leonberger 108 | Lhasa Apso 109 | Lowchen 110 | Maltese 111 | Manchester Terrier 112 | Mastiff 113 | Miniature Bull Terrier 114 | Miniature Pinscher 115 | Miniature Schnauzer 116 | Neapolitan Mastiff 117 | Newfoundland 118 | Norfolk Terrier 119 | Norwegian Buhund 120 | Norwegian Elkhound 121 | Norwegian Lundehund 122 | Norwich Terrier 123 | Nova Scotia Duck Tolling Retriever 124 | Old English Sheepdog 125 | Otterhound 126 | Papillon 127 | Parson Russell Terrier 128 | Pekingese 129 | Pembroke Welsh Corgi 130 | Petit Basset Griffon Vendeen 131 | Pharaoh Hound 132 | Plott 133 | Pointer 134 | Polish Lowland Sheepdog 135 | Pomeranian 136 | Poodle 137 | Portuguese Podengo Pequeno 138 | Portuguese Water Dog 139 | Pug 140 | Puli 141 | Pyrenean Shepherd 142 | Rat Terrier 143 | Redbone Coonhound 144 | Rhodesian Ridgeback 145 | Rottweiler 146 | Russell Terrier 147 | Saluki 148 | Samoyed 149 | Schipperke 150 | Scottish Deerhound 151 | Scottish Terrier 152 | Sealyham Terrier 153 | Shetland Sheepdog 154 | Shiba Inu 155 | Shih Tzu 156 | Siberian Husky 157 | Silky Terrier 158 | Skye Terrier 159 | Smooth Fox Terrier 160 | Soft Coated Wheaten Terrier 161 | Spinone Italiano 162 | St. Bernard 163 | Staffordshire Bull Terrier 164 | Standard Schnauzer 165 | Sussex Spaniel 166 | Swedish Vallhund 167 | Tibetan Mastiff 168 | Tibetan Spaniel 169 | Tibetan Terrier 170 | Toy Fox Terrier 171 | Treeing Walker Coonhound 172 | Vizsla 173 | Weimaraner 174 | Welsh Springer Spaniel 175 | Welsh Terrier 176 | West Highland White Terrier 177 | Whippet 178 | Wire Fox Terrier 179 | Wirehaired Pointing Griffon 180 | Wirehaired Vizsla 181 | Xoloitzcuintli 182 | Yorkshire Terrier 183 | --------------------------------------------------------------------------------