Code Monkey home page Code Monkey logo

phpmysql6's Introduction

PHP Novice to Ninja

Use the "Change Branch" above to select the relevant code sample.

phpmysql6's People

Contributors

trpb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phpmysql6's Issues

errata?

A bit confused by what I'm thinking must be typo or update error. Since I'm still in the novice category, I can't figure it out.
On page 142 in the book, it says:
"You’ll have noticed that there are two different variables being set, $jokes and
$error, depending on whether the try block executed successfully."
This is the first time $error appears. I believe it's referring to $e from "(PDOException $e)" but I haven't been able to confirm that despite looking through much of the book, placing errors in the code, searching the pdf version, and searching the website's forums. $e seems to used throughout the book in the try-catch sequences as part of $output. $error seems to be in the template files to be printed out, but I can't find anywhere that it's defined.
What am I missing? Thanks

Trying to improve user registration

So I am trying to improve user registration a little bit and by that I mean password checker. So I added two new methods to Register.php ContainsNumbers -> Which checks if string contains a number. Min8 checks if string has 8 or more characters.
While trying to register a user to see if he/she could register to a page bypassing basic password requirements I get this:
Fatal error: Uncaught Error: Call to undefined function Ijdb\Controllers\ContainsNumbers() in /srv/http/Project/classes/Ijdb/Controllers/Register.php:76 Stack trace: #0 /srv/http/Project/classes/Ninja/EntryPoint.php(47): Ijdb\Controllers\Register->registerUser() #1 /srv/http/Project/public/index.php(8): Ninja\EntryPoint->run() #2 {main} thrown in /srv/http/Project/classes/Ijdb/Controllers/Register.php on line 76

Line 76 of Register.php looks like this:

if(!ContainsNumbers($author['password']) && (!min8($author['password']))){

Contains numbers ,method:

public function ContainsNumbers($password){
		if (preg_match('/[0-9]/', $password)){
			return true;
		}
		else{
			return false;
		}
	}

min8 method:

public function min8($password){
		if (strlen($password)>=8){
			return true;
		}
		else{
			return false;
		}
	}

URL Rewriting and Final Website

image

hi Tom, thank you. i made it using xampp with directory structure C:\xampp\htdocs\ijdb6\Project\public

if anyone wants to try using xampp, here's how:

  1. first and foremost you need to change your Apache server root folder from default one at htdocs (c:\xampp\htdocs) to public (c:\xampp\htdocs\ijdb6\Project\public). i use this directory structure but should also work for any directory structure you choose

change file httpd.conf like this:
image
you can search the file in c:\xampp\apache or you can hit Config button in Xampp control panel and choose httpd.conf file

dont forget to stop and restart your apache server so the change will take effect. just hit stop and start button in Xampp control panel

  1. create .htaccess file and place it in root folder. our new root folder now is 'public'. the content like this:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /index.php [NC,L,QSA]

you can create this file using IDE or using notepad. with notepad choose to 'save as' and 'save as type' All Files

  1. type localhost in your browser address bar, and, voilaa..
    if you like to have a feeling like you are accessing a real server, you can change localhost to mydevserver.com or any whimsical name you can come up to by edit file hosts located in C:\Windows\system32\drivers\etc

image

you need windows special permission to make the edit. try make the edit using windows provided account named administrator

thats all.

Tom has introduced very good technique that we should put our front controller (index.php) and other necessary files in root folder but put those important files outside of this folder. by making these changes we can make our root folder 'public' to serve the internet while we put the important files out from this folder. it greatly improve security

the provided .htaccess file make sure that for every non-existent folder/path or file we query in browser's address bar will go to index.php. the next thing is obvious, we make the index.php to response to specific URI. in other words, any URI is acceptable to the controller as long as we provide their corresponding response

Joke Objects Error in book - p. 542

This;

` $author = $this->authorsTable->findById($joke->authorId);

  $jokes[] = [
    'id' => $joke->id,
    'joketext' => $joke->joketext,
    'jokedate' => $joke->jokedate,
    'name' => $author->name,
    'email' => $author->email,
  ];

`

Should be:

` $author = $this->authorsTable->findById($joke->authorId);

  $jokes[] = [
    'id' => $joke->id,
    'joketext' => $joke->joketext,
    'jokedate' => $joke->jokedate,
    'name' => $author->name,
    'email' => $author->email,
    'authorId' => $author->id
  ];`

Otherwise, you get error messages where Edit & Delete should be. (It's correct in the sample code.)

permissions field in Author entity class is missing

The method hasPermission (in Author class) uses $this->permissions but the field isn't defined in the class.
(Also I wonder whether the line $joke['jokedate'] = new \DateTime(); in the saveEdit method inside the Joke controller is not violating the separation of concerns principle and the [awesome] explanations of the book about why we use an ORM? Here, if I'm not mistaken, we're directly referring to an implementation detail of our jokes table-which is the field name "jokedate".)

Chapter 9 Breaks my code

Here are few errors when I try running "index.php" :
PHP Fatal error: Uncaught TypeError: Argument 2 passed to Ninja\EntryPoint::__construct() must be of the type string, null given, called in /srv/http/ph/examples/index.php on line 6 and defined in /srv/http/ph/classes/Ninja/EntryPoint.php:9
Stack trace:
#0 /srv/http/ph/examples/index.php(6): Ninja\EntryPoint->__construct('', NULL, Object(Ijdb\IjdbRoutes))
#1 {main}
thrown in /srv/http/ph/classes/Ninja/EntryPoint.php on line 9

When I got the book, I already got my LAMP server running, ph is just directory for php projects. Also, I am using php storm IDE

[Question] How is site protected from XSS?

By the question, I mean how it's forms is protected from javascript and html code? The book had written about htmlspecialchars function, however I can't see it anywhere in code.

final website

Hi Tom,

I tried to run final-website with this error:

image

my directory structure is localhost/ijdb6/Project/public/index.php

tried to fix with xdebug but to no avail

Thanks

Chapter 9. Creating an Extensible Framework. Issue in nginx configuration

Hello.
It is a grate book and I adore it. But it seems to me I found out an error in NGINX configuration for URL Rewriting.

location / {
    try_files $uri $uri/ /index.php?args;
}

Missed a dollar sign before args. Should be:

location / {
    try_files $uri $uri/ /index.php?$args;
}

It's simple, but it drove me crazy while debugging.

Functions to allow Editing joke categories breaks several features of the website, and also issues with logging out.....

After downloading the sample code, am receiving multiple errors

  1. Notice: Undefined variable: categories in /home/vagrant/Code/Project/templates/jokes.html.php on line 4
  2. Warning: Invalid argument supplied for foreach() in /home/vagrant/Code/Project/templates/jokes.html.php on line 4
  3. Notice: Undefined variable: user in /home/vagrant/Code/Project/templates/jokes.html.php on line 29

***** LOGGING OUT*****
The logout.html.php is displayed if a logout attempt is made, and the link changes to "Login".
But the session is not destroyed, is still possible to navigate to edit jokes. And as soon as you navigate away from the logout page, the link returns to "Logout".

******EDIT ****

Logging out now working ... Added session_destroy(), but other errors persist(help would be appreciated)

public function logout() {
unset($_SESSION);
session_destroy();
return ['template' => 'logout.html.php', 'title' => 'You have been logged out'];
}

Typo on p.594

This is correct in the sample code.

else if (isset($routes[$this->route]['permissions'])
➥ &&
!$this->routes->checkPermission
(**$$routes**[$this->route]['permissions'])) {
header('location: /login/error');
}
else

Also, the sample code appears to be missing the functionality for hasPermission() though it's in the book.

Chapter 7 updateJoke function error

The error (from Intellij IDEA) says SET without WHERE clause....etc. Why isn't the rest of the query visible to PHP?
Here is the code which causes error:

function updateJoke($pdo, $fields) {
$query = ' UPDATE joke SET '; <--------"Reference or Select expected"

foreach ($fields as $key => $value) {
    $query .= '`' . $key . '` = :' .$key . ',';
}


$query = rtrim($query, ',');

$query .= ' WHERE `id` = :primaryKey';

Example code error in Chapter 7 > Generic Functions

It's just an example code does not affect the code for the website, but just saying...

What's showing in the book:

// Delete the book with the ISBN 978-3-16-148410-0
delete($pdo, 'book', '978-3-16-148410-0', 'isbn');

Believe the isbn# and 'isbn' should change place, like following:

// Delete the book with the ISBN 978-3-16-148410-0
delete($pdo, 'book', 'isbn', '978-3-16-148410-0');

This is the function code:

function delete($pdo, $table, $primaryKey, $id ) {
    $parameters = [':id' => $id];
    query($pdo, 'DELETE FROM `' . $table . '` 
    WHERE `' . $primaryKey . '` = :id', $parameters);
}

URL rewriting on WAMP

Hello and thanks for this book!
First of all I'm on php so maybe it's a silly question.

I have a problem when a try to rewrite URL on chapter 9:

I think that the problem is in the following line on Cms-EntryPoint-Class (index.php)

$route = ltrim(strtok($_SERVER['REQUEST_URI'], '?'), '/');

because it duplicate my URL after "public":

http://localhost/Project2/phpmysql6-Sessions-CheckUser-Secured/public/project2/phpmysql6-sessions-checkuser-secured/public/

I tried to give a empty string to $route and it works for the index page, but obviously the other links in the page doesn't work.

I also try to create an .htaccess file in the public directory and I try to change the Apache root folder in httpd.conf but it doesn't work for me and give me back an error 500.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.