Want to protect your code when delivering it to a clients hosting when it’s not paid for yet?
I know as this has happened to me. I found a delivery of PHP code for sign off encrypted, I hadn’t seen that before. When we asked the company they said they would remove the encryption upon final payment.
Encryption is definitely a useful tool for PHP developers. Make it a deliverable of your contract that the source code will be decrypted when paid for.
We also had another client who wanted to distribute PHP code on USB thumb sticks. Not recommended, but it is possible to run it like that, using a SQLite database. Given the accessibility of a USB thumb stick rather than a Linux server, we encrypted the PHP code.
PHP Simple HTML DOM Parser is a great tool to process HTML from remote sites. The HTML is returned from the library. So that you can then search and iterate through it, this is great for scraping sites. I didn’t write the code, but you can download it here and find some simple documentation:
If you are a newbie learning PHP, one of the most useful functions to know is var_dump().
It dumps the contents of a variable, so you can see it in your web browser, it’s simple to use for example:
Then you can see what $my_variable contains. The data type and in the case of an array or an object. The structure will then be visible.
You will then know how to access the fields within the array / object.
Although I’m far from a newbie, var_dump() is an ever useful function. Use it to determine the value of variables and debugging your code.
var_dump() is your friend in many scenarios, remember it and use it while developing.
Example usage, if you want to see all the variables in a GET or POST request:
To all the variables in the SERVER global variable:
How to join two MySQL database tables together in a simple SELECT statement?
For example I have a table of products and a table of product categories, how to return the category description of each product?
A. In it’s simplest form you would join two tables based on the relationship between a key and it’s foreign key stored in another table:
SELECT p.id, p.product_name, c.description AS ‘cat_description’
FROM products p
INNER JOIN categories c on p.category_id = c.id
Using a well designed relational database and JOINed queries will make your PHP code simpler and more efficient by returning the data from two or more tables in one query.