Category Archives: PHP

Generating a random color with PHP

Hi there, today I’m going to give you a quick snippet that will maybe help you in your future or current projects in PHP.You could use multiple methods on generating random HTML color codes with PHP, but today I’m going to teach you 2 ways of doing it.First one is this:

and the second one is inspired from another website which I found some time ago.

there you have it, 2 snippets on random coloring codes for HTML.You can use them by calling out the function, just like this:

Example of output:

randomcolor

PHP Ip to country script

Hi there guys, today I’m going to give you a quick function that is very useful to determine what country does an ip has.

This is a function that works for both IP’s and domain names.This function is using a free API called wipmania, whenever this API is down or it doesn’t locate the country it will output “xx”.Thanks, and I hope this will help you !

PHP Check if port is opened

Hi there, I know I haven’t posted so much later but I got something for you today.A little php snippet that will help you check if a specific port is opened on a specific IP or domain.Here you go, made this specially for you guys, hope this will help you somehow.

port_checker

Get execution time of the script PHP

Today I’m going to give you a very useful snippet that you can use in your further projects to see the execution time of the script.The principle is pretty simple.You will need to define a variable at the start microtime() and one at the end.After that you will need to subtract the end microtime variable from the start microtime variable and thats it.Also you can set the output value to only show the first 2 decimals.

 

How to easily read lines from a text file with PHP

Today I’m going to give you a very quick and simple php snippet or function which reads every line of a .txt file and returns them into an array.For example, you have this text file called countries.txt with the following content:

Romania
Russia
Germany
Bulgaria

You can read them very easily with PHP with an integrated function called file() that requires 1 parameter, the file location of the .txt.

this will output something like:

Array ( [0] => Romania [1] => Russia [2] => Germany [3] => Bulgaria )

Thanks for reading this quick and simple tutorial.

Block multiple IP addresses with PHP

Today I’m going to give you a quick and very useful snipped on how to block multiple IP addresses with PHP.

First off you will have to implement this custom function in your code, preffered in the file that initializes the script.

After that, you need to define an array which contains the ip’s you want to block and then call out the function with the array parameter.

add this code to your header so that every page the specific user access, he will be blocked and will get this message:

Your IP(127.0.0.1) has been blocked !

Thanks for reading my mini tutorial, enjoy.