Coder Social home page Coder Social logo

php-tutorial-text's Introduction

I am currently looking for backend software work, senior level. Majoring in PHP or TypeScript, minoring in devops for all hosted CI platforms. I am UK-based and prefer fully/mostly remote. Please contact me through the platform you found me on. This README is intended to be a better summary of my work profile than a bare repo list. Most of my outside-work code is in private repos. Feedback welcome!

Stuff I've done

👨‍🏫 Currently volunteering as a coach at Codebar
✏️ I'm a 20K "Trusted User" and curator on Stack Overflow (1.5K answers & 117K edits)
⚙️ I've 2.6K posts to help folks with using CircleCI
🤖 I'm building an AI / ChatGTP-powered project with two product SMEs (all under wraps for now 🤐)
😇 I used to teach PHP in-person, and wrote this book-length tutorial

Code & experiments

🐑 They're not native to AWS, but I got PHP lambdas to work
↔️ I wrote a shared-hosting file sync system, which is in production use
🧪️ I did some experiments with Docker Swarm (39 ⭐)
⚗️ And here's another one

php-tutorial-text's People

Contributors

gregwittman avatar halfer avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

michaellenahan

php-tutorial-text's Issues

Minor bug on how post body carriage returns are handled

In chapter 3 there is this intro:

Next, let us add in some logic that interprets two carriage-returns in a post as a paragraph break. Here we go:

The code to do that is given as:

$paraText = str_replace("\n", "</p><p>", $bodyText);

That just replaces a single CR, not a double. To fix this, I could change either the code or the text. If I change the code to \n\n then a single CR will be ignored - which is probably OK.

Should saving in edit mode go back to edit mode or not?

I know it is an old tutorial but I went through it. when I got done I added a post and save it, then it goes directly in to edit. Don't know if I missed something. I will go through it and see if I can see something I was just letting you know. Thanks for the Awesome tutorial.

Add link to php.net in introduction

When reading the introduction it would be useful if (part of) the text "usually on the PHP website" was a link to php.net.

I can do a pull request if you wish? (I didn't see a CONTRIBUTE file.)

When redirectAndExit() is created, the code is changed

In the "Improving the installer" section, a new function is created for redirecting. This used to take a small piece of code and simply move it to the function - however I rebased a change into that function. The same change should be rebased into the prior, non-function copy too.

Incorrect home page text for narrow responsive view

On the home page there is this text:

Click on the first chapter to the right

That's fine for the ordinary view, but for narrow screens the menu snaps to the top. This needs changing so it is more generic!

Add expand button to code diffs

On another ticket, there was a suggestion to increase the width of the side-by-side diffs, which would make diffs much wider than the body text.

I wonder whether that might look out of place, given that diffs are deliberately the same width as the text content presently. There's a couple of alternatives:

  1. Add a JS toggle switch on the page that renders the diffs in wide format
  2. Same as above, but toggles the width of the text content too

I think I prefer the first item presently.

Are all variable names self-explanatory?

One reader reports that $stmt is rather confusing, and I am inclined to agree. This variable name is a bit of a standard for PDOStatement objects, but $statement or even $result would be better.

It might be worth scanning the whole codebase for any variables that have been unnecessarily abbreviated.

Add more explanation of PDO early on

This blog post serves as excellent feedback for what beginners might get stuck on, and where I may have subconciously assumed prior knowledge.

The permissions errors essentially support ticket #3 - if we switch to PHP's built-in web server, and drop Apache for the time being, we can get away with just installing PHP and solve the permissions issues at the same time.

It seems some of the PDO material could be explained more thoroughly - what does $pdo represent? What do exec() and query() actually do? What is contained in a $stmt? I'd like to try to do this without reference to object orientation, as I think that will just muddy the waters. This stuff is complex enough as it is! 😄

Adjustments to UI and readability

Here are a few CSS adjustments for improved readability for your consideration.

Blockquotes

Current:

#content .sidebar {
    border: 1px dashed silver;
    margin: 0 4em;
    padding: 0 8px;
}

New:

#content .sidebar {
    border: 1px dashed #247EDA;
    background: #e9f2fb;
    margin: 2em 0;
    padding: 1.5em;
}

#content .sidebar p {
    margin: 1.5em 0;
}

Typography

Current:

#content p, #content ul, #content ol {
    font-size: 1.3em;
}

#content p {
    margin: 16px 0;
    line-height: 140%;
}
#content code {
    font-size: 1.1em;
}

New:

#content p, #content ul, #content ol {
    font-size: 1.1em;
    line-height: 1.6;
    font-weight: 400;
    margin: 1.5em 0;
}
#content code {
    font-size: 1.1em;
    background: rgba(0, 0, 0, .08);
}

#content pre code {
    background: transparent
}

I would also probably make the alert note stand out more.

Current:

#versions-note {
    min-width: 850px;
    max-width: 1000px;
    margin: 0 auto;
    font-family: "Open Sans",sans-serif;
    font-weight: 300;
    border: 1px dotted gray;
    color: gray;
}

New:

#versions-note {
    border: 1px dotted #EEA09F;
    color: #B02323;
    background: #fbeceb;
    line-height: 1.6;
    font-weight: bold;
}

#versions-note #versions-note-inner {
    padding: 1.5em;
    font-size: 1em;
}
#content {
   color: #333333;
}

Here's an example image.

I would also consider removing margin-top: 0 from h1 and #contents-menu h2, as well as making headings bold.

Minor bug with how PDO error is handled

Hi,

I think I've spotted a minor bug in chapter 5 (https://ilovephp.jondh.me.uk/en/tutorial/make-your-own-blog/commenting-form?version=v5), when "addCommentToPost" function is first introduced this method "$pdo->errorInfo()" is used to get potential error if SQL query fails. I've noticed that my SQL queries were failing silently without any errors being caught so after a bit of investigation I found this: http://php.net/manual/en/pdo.errorinfo.php and according to that documentation :

If you create a PDOStatement object through PDO::prepare() or PDO::query() and invoke an error on the statement handle, PDO::errorInfo() will not reflect the error from the statement handle. You must call PDOStatement::errorInfo() to return the error information for an operation performed on a particular statement handle.

I changed line 81 from "$errorInfo = $pdo->errorInfo();" to -> "$errorInfo = $stmt->errorInfo();" and that solved the problem for me.

Hopefully this helps.

Kind regards.

Form Fields not aligning

In Section 7, CSS files are added to style the pages. An issue with alignment is present. Form fields in the 'New post' and 'Add your comment' are not straight. Each field is indented further in then the field above it.

I fixed it by removing the 'margin:7px;' line from the '.user-form label'. After the line is removed, the form fields are aligned vertical.

Mention that XAMPP needs to be started before info.php will work

A Reddit reader says it was not clear that XAMPP needed to be started prior to trying the first script in the browser. I would assume Apache/MySQL would auto-start once the application is run, but XAMPP may work differently since I last tried it. User is on Windows 7.

It would be nice to add a screenshot of the control panel too.

Make minor changes for current versions of PHP

The tutorial is perfectly OK to use now (with PHP7) but there are a few simplifications I can make:

  • Chapter 1 makes a reference to using libraries for the password_compat, which was used for versions of PHP prior to 5.5. These versions are out of support now, so this can be removed.
  • Remove vendor/password_compat/lib/password.php from Chapter 6
  • Give the whole tutorial a read-through to ensure there are no remaining references to using libraries.

This will need a new text version (v4) and code changes can merge into latest branch (rebase5).

Security improvements to session handling

As it stands, there is no session identifier regeneration at log-on, and I think this could be improved. The code adjustment would be minor (one line) and can probably be explained just in comments -- I wonder if explaining it in the text also would be pitching at the wrong level for beginners.

This paper looks like relevant reading. Also this question and particularly this answer to it.

Comments/suggestions welcome.

Can we improve description of mod_rewrite rules?

A Reddit reader has been in touch to ask for more information about the .htaccess rules to prevent access to site resources. The explanation was kept deliberately quite light here, since there is enough to be getting on with already.

However I might be able to do something in a sidebar, while making it plain that the material can be skipped. Here is a snippet of my reply to the reader:

RewriteCond %{REQUEST_URI} ^/(data|lib|templates|vendor)/
RewriteRule ^ - [L,R=404]

The first one sets up a condition (i.e. when the rule will apply) and the second one does the action.

So the condition is looking at a placeholder known as %{REQUEST_URI}. This is the URL of the page, relative to the domain. So it will always start with '/' and then it will contain the address, e.g. '/styles/assets/main.css' or '/install.php'. However there are some resources we want users specifically not to access directly.

These ones are in the data/lib/templates/vendor folders, so we add those into the second part of this command. The bar character means "or" and the ^ means "begins with". This format is known as a regular expression, and is a popular way of testing strings for certain conditions.

The RewriteRule basically says if you get a match, then this is the (L) last rule (i.e. don't process any more rules) and the server should (R) redirect to a 404 page (i.e. not found).

This is at the bottom of chapter 7.

Possible best-practice topics to introduce to tutorial readers

First of all, thanks for the effort you put into this. Looks like a really good tutorial for someone new to the language.

The only thing that worries me a little is what follows. Until you have a followup tutorial, it might be useful to link a few resources that point the readers in the right direction. Otherwise I feel it is rather likely that they will pick up bad habits without knowing so from one of the many bad tutorials out there.

A few topics that come to mind:

I did not give the tutorial an indepth read, so the suggestions might not be suited towards your target audience. Proceed with caution :)

Simplify the installation, and add more detail

Some ideas based on kind feedback from a Reddit reader:

The install instructions are too brief - XAMPP is mentioned, but there is no detail about how to install it. The same goes for NetBeans - and this isn't an easy product to get started with anyway. One needs to learn how to create a project and how to create files, and none of this is mentioned.

I think I will drop XAMPP and switch to using PHP's built in web-server. That will simplify the server installation. Also, I think I should swap to something like Brackets and walk the reader through creating a project folder and their first file.

Re-consider the section on editors

The big issue in the section on editors is the links will date too quickly, and are likely to be very stale now.

Is there a good way I can give folks a nice selection of editors while not swamping them, and adding links that do not go out date?

Can we have pictures or videos of the end build?

Going to be running through this project in the near future, however I was wondering if it possible to see somewhat of an example build. Whether this is a complete hosted version, or via pictures/videos. Sometimes helps being able to see the completed project before/during.

Thanks

Turn off emulated binding in PDO options

I seem to recall some feedback from someone saying that PDO/MySQL uses emulated binding unless it is explicitly turned off. More detail in this question.

It's not particularly critical, as it does not affect security, but it's worth adding when I next do a round of code tweaks.

Undefined array key "count" in C:\xampp\htdocs\blog\install.php

Thanks for the tutorial - I've completed up to the end of section 3 (Adding more features). When I amend the install.php file at the start of section 4, I get warnings about "Undefined array key "count"" and "Undefined array key "error"" on lines 94 and 95, and when I then try to view index .php I get "Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 1 no such table: post in C:\xampp\htdocs\blog\index.php:7 Stack trace: #0 C:\xampp\htdocs\blog\index.php(7): PDO->query('SELECT\r\n ...') #1 {main} thrown in C:\xampp\htdocs\blog\index.php on line 7"

Any advice much appreciated.

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.