PHP programmer learning from scratch. Personal experience as proof: the PHP programming language is the main one on the Web

PHP (P HP: H hypertext P reprocessor, thoughtful preprocessor

Hypertext) is a scripting programming language focused on the web.

In lesson 1 we will get acquainted with the basic syntax, as well as write our first script.

Syntax basics:

-
- start and end of the script
assignment operator -=

Output text information - echo (can output html code)

While(loop condition)(action) - loop
- if(condition)(action to be performed if the condition is false)else(action to be performed if the condition is false) - condition
-

Lesson 1. Creating the first script

As you can see the script consists of one line.

To execute the script, you need the appropriate software, for Windows users I recommend Denwer (http://denwer.ru)
After installing Denwera, create a Script.test folder in the hosts directory, in which, in turn, create a folder

WWW. In the WWW folder, create an index.php file? into which we transfer the contents of our file.

After saving the file, restart Denwer. Then in the browser line type script.test

And voila! We see the inscription Hello World!

How not to write Hello World:

Hello World Not spelled like this

So:

Well, it certainly isn't:

Completion.

On this, our lesson came to an end, but in the end, a small selection of useful links:
denwer.ru - site where you can download Denwer
en.wikipedia.org/wiki/PHP - What is PHP
http;//php.net - PHP tutorial

tags: PHP

This article is not subject to comments, since its author is not yet a full member of the community. You will be able to contact the author only after he receives

For the first few points I will try to write free-form recommendations.

First and foremost, to learn PHP programming well, you need to learn programming well. This is a very important thing. Most people who write in PHP have no idea about programming. Even about such basic things as code formatting, debugging, profiling, error handling, file operations. You may notice that I am not talking about OOP. This is a completely separate topic, OOP must be taught specifically. Unfortunately, out of 100 people who say they know OOP, 90 are banal copy-pasters who have learned the syntax, but do not understand the meaning of objects. But to play chess, it is not enough to know how the pieces move.

It would also be nice to answer the question - why do you want to learn programming in PHP? The question is not at all idle. Many people mix a bunch of different concepts in it. For example, CMS has already been mentioned here. and indeed, if we are talking about making money, then customizing Jumla and writing shit modules for it is financially much more profitable than the ability to write something from scratch. For freelancing, anyway.

In general, PHP can be used in many different ways. And for each case it will be its own language.

  • You can rivet a guest or business card site on a "naked" PHP - and there is nothing wrong or shameful in this. On the contrary, this is a plus of a language that is also suitable for such purposes, without dragging along a couple of million lines of code for the sake of a site of five hundred.
  • You can write a professional portal based on one of the existing frameworks and develop it.
  • You can write a custom highload project, for which you will need to write your own framework again in pure PHP.
  • It is possible, as already mentioned, to rivet sites based on some kind of CMS.

Plenty of options! so you need to decide what you want first.

They talked about JS + CSS above - you don’t need to listen, this is complete nonsense. Front-end programming is a completely separate thing, much more visual than abstract. And, thank God, more and more employers are beginning to understand this. Although, again, if you freelance and are a master of all trades, then you can’t do without it.

But if you work as a hardcore server programmer in a team, then you only need to have a general idea about HTML / JS / CSS (since texts in these languages ​​are, in fact, almost the only result of PHP work).

But what you definitely need to know well from related technologies is the HTTP protocol, the file system device, work c command line in Linux.

Now for the rest

Mysql is still the cornerstone of data storage on the web. Need to know and understand joins, indices

Frameworks are a must. Here, however, there is a problem of choice, but there is no fundamental difference between them. Yii is a good choice.

You don't need Github, you don't need to know it. Need to know git.
But what is mandatory for a web programmer is the ability to use Google. At least at the level of ability to copy-paste an error message into a search form or write a question “What is git” ;-)

Because to work in a team, you need to know some kind of version control system, and git is the de facto standard. Understand the principle of operation and basic commands - checkout, commit, push.

Knowledge of HTML allows you to get an idea of ​​how to create websites. And even gives you the opportunity to independently develop Internet resources. However, the use of this markup language is limited due to the static nature of the pages created with it. In particular, it is used in most cases for the development of business card sites. The thing is that if you need to make any changes, you need to edit each page separately, and if the resource has several tens or hundreds of them, such a process will not only be tedious, but also stretched out in time.

The use of PHP (acronym for PHP: Hypertext Preprocessor "hypertext preprocessor") allows you to optimize site administration, a scripting programming language that allows you to create dynamically filled web pages. Its use makes it possible to make the resource truly interactive, and the process of managing the site - simple and less costly in terms of effort. Online course PHP for Beginners by WebShake helps you learn the basics of a scripting language from scratch, learn how to create dynamic resources that are easy to modify and maintain.

Our text materials and video tutorials are designed to be understandable to every user who wants to learn web programming. And homework, placed at the end of each topic, will allow you to consolidate the knowledge gained and hone their application in practice.

1. Befriend the PHP Reference

If you're new to PHP, then it's time to check out the awesome PHP reference. The PHP Reference is incredibly comprehensive and has really helpful comments on every article. Before you ask questions or try to solve the problem yourself, save time and just head for the guide. The answers to your questions are already conveniently placed in a useful article on the PHP.net site.
In this case, we recommend that you look for reference books in Russian on your own, preferably php for beginners. We will be glad if you give a link to useful reference books in the comments to the article (Just keep in mind that this is a translation of the article).

2. Turn on error reporting

6. Indent and use spaces for readability

If you don't use indentation and whitespace in your code, the result looks like a painting by Jackson Pollack. Make sure your code is readable and searchable, because you will almost certainly make changes to it in the future. IDEs and modern text editors can automatically indent code.

7. Make your code layered

Tiering your applications is nothing more than splitting the various components of your code into parts. In the future, this will give you the ability to easily change the code.

8. Always use

Often programmers try to use abbreviations in PHP statements. Here's how it's usually done:

<% echo "Hello world"; %>

echo "Hello world" ;

<% echo "Hello world" ; %>

While this does save a few characters, these methods are all deprecated and unofficial. stick to the standard, as it is guaranteed to be supported in all future versions.

9. Use meaningful, consistent titles

Naming is not just for your own pleasure. There is nothing worse than tearing through another programmer's meaningless conventions. Help yourself and others by using meaningful names for your classes and properties.

10. Comment, comment, comment

In addition to using spaces and indentation to separate code, you will also need to use inline comments to annotate your code. You'll thank yourself later when you have to go back and look up something in the code, or if you just don't remember what a certain function did. It's also useful for those who need to review your code.

11. Install MAMP/WAMP

MySQL is the most popular kind of database used with PHP (though not the only one). If you need to set up a local environment for developing and testing your PHP applications on your computer, consider installing MAMP (Mac) or WAMP (Windows). Installing MySQL on your own computer can be a tedious process, and both of these software packages contain MySQL. Smart and simple.

12. Set Limits on Your Scripts

Setting a time limit for PHP scripts is a very responsible thing. There are times when scripts break, and when that happens, you'll have to use the set_time_limit property to avoid endless loops and database connection timeouts. Set_time_limit sets a time limit for the maximum number of seconds a script will run in (default 30). After this time, a fatal error is raised.

13. Use objects (or OOP)

Object-oriented programming (OOP) uses objects to represent the components of an application. OOP is not only a way to break up your code into separate logical sections, it also reduces code repetition and makes it much easier to modify it in the future.

14. Understand the difference between single and double quotes

Using single quotes in strings is more efficient because the parser doesn't have to sift through the code looking for special characters and other things that double quotes allow. Where possible, try to always use single quotes.

Objection: Actually, this is not necessarily true. Benchmark tests show that when testing strings without variables, there are some performance advantages to using double quotes.

15. Don't put phpinfo() in your webroot

Phpinfo is a wonderful thing. By simply creating a PHP file that has:

and by attaching it somewhere on the server, you can instantly know everything about your server environment. However, many beginners will place a file containing phpinfo() in the webroot of the server. This is an extremely insecure practice, and if someone with an inquisitive mind gains access, they could potentially jinx your server. Make sure phpinfo() is in a safe place, and as an extra measure, remove it once you're done.

16. Never, ever trust your users

If your application has places for users to log in, you should always assume that someone will try to enter a questionable code. (We're not implying that your users are bad people. It's just common sense.) A great way to keep your site safe from hackers is to always initialize your variables to protect your site from XSS attacks. PHP.net has an example of a properly closed form with initialized variables:

if (correct_user ($_POST [ "user" ] , $_POST [ "password" ] ) (

$login = true ;

if ($login) (

forward_to_secure_environment();

17. Keep passwords encrypted

Many newbies to PHP often dump sensitive data like passwords into the database without using encryption. Consider using MD5 to encrypt passwords before sharing their database.

echo md5("myPassword"); // renders-

echo md5("myPassword") ; // renders-

Objection: However, remember that MD5 hashes have been compromised for a long time. Of course, they are more secure than not, but with the help of a giant "spectral table" hackers can recover your hash. For even more security, consider adding "salt" (white noise interference). "Salt" is usually an extra set of characters that you append to a custom string.

18. Use database visualization tools

If you find it difficult to plan and modify databases for your PHP applications, you might consider using a database visualization tool. MySQL users can work with DBDesigner and MySQL Workbench to visually design their databases.

19. Use Output Buffering

Output buffering is an easy way to greatly improve the quality and speed of your PHP script. Without output buffering, your script will render the HTML on the page as it is processed - in chunks. Adding output buffering allows PHP to store the HTML as a variable and send it to the browser in one chunk.

To activate the output buffering function, simply add ob_start() like this at the beginning of the file.

Objection: While not required, it's generally considered good practice to just stick with the “ob_end_flush();” function. towards the end of the document. P.S. Do you also want to compress HTML? Just change "ob_start();" to "ob_start('ob_gzhandler')";

XHTML

untitled

untitled

20. Protect Your Script From SQL Injection Attack

If you do not escape characters used in SQL strings, your code is vulnerable to an SQL injection attack. This can be avoided by using either the mysql_real_escape_string function or prepared SQL statements.

Here is an example of mysql_real_escape_string in action:

$username = mysql_real_escape_string($GET["username"]);

$username = mysql_real_escape_string ($GET [ "username" ] ) ;

And a prepared statement:

21. Try an ORM

If you are writing object-oriented PHP, you can use OR-mapping (ORM). An ORM allows you to convert data between relational databases and object-oriented programming languages. In short, an ORM makes it possible to work with databases in the same way that you work with classes and objects in PHP.

There are many ORM libraries for PHP such as Propel, and ORM is built into PHP frameworks such as CakePHP.

22. Cache Database Driven Pages

Caching database-driven PHP pages is a great idea to improve the loading speed and performance of your script. It's really not that hard to create and retrieve static content files with our good friend ob_start(). Here is an example taken from Snipe.net:

// TOP of your script $cachefile = "cache/".basename($_SERVER["SCRIPT_URI"]); $cachetime = 120 * 60; // 2 hours // Serve from the cache if it is younger than $cachetime if (file_exists($cachefile) && (time() - $cachetime< filemtime($cachefile))) { include($cachefile); echo ""; exit; ) ob_start(); // start the output buffer // Your normal PHP script and HTML content here // BOTTOM of your script $fp = fopen($cachefile, "w"); // open the cache file for writing fwrite($fp, ob_get_contents()); // save the contents of output buffer to the file fclose($fp); // close the file ob_end_flush(); // Send the output to the browser

// TOP of your script

$cachefile = "cache/" . basename ($_SERVER [ "SCRIPT_URI" ] ) ;

$cachetime = 120 * 60 ; // 2 hours

// Serve from the cache if it is younger than $cachetime

if (file_exists ($cachefile ) && (time () - $cachetime< filemtime ($cachefile ) ) ) {

include($cachefile) ;

Sandbox

pull July 25, 2013 at 01:07 pm

PHP from scratch. Lesson 1

  • PHP,
  • Programming

PHP (P HP: H hypertext P reprocessor, thoughtful preprocessor

Hypertext) is a scripting programming language focused on the web.

In lesson 1 we will get acquainted with the basic syntax, as well as write our first script.

Syntax basics:

-
- start and end of the script
assignment operator -=

Output text information - echo (can output html code)

While(loop condition)(action) - loop
- if(condition)(action to be performed if the condition is false)else(action to be performed if the condition is false) - condition
-

Lesson 1. Creating the first script

As you can see the script consists of one line.

To execute the script, you need the appropriate software, for Windows users I recommend Denwer (http://denwer.ru)
After installing Denwera, create a Script.test folder in the hosts directory, in which, in turn, create a folder

WWW. In the WWW folder, create an index.php file? into which we transfer the contents of our file.

After saving the file, restart Denwer. Then in the browser line type script.test

And voila! We see the inscription Hello World!

How not to write Hello World:

Hello World Not spelled like this

So:

Well, it certainly isn't:

Completion.

On this, our lesson came to an end, but in the end, a small selection of useful links:
denwer.ru - site where you can download Denwer
en.wikipedia.org/wiki/PHP - What is PHP
http;//php.net - PHP tutorial

tags: PHP

This article is not subject to comments, since its author is not yet a full member of the community. You will be able to contact the author only after he receives

mob_info