Monday May 20, 2024 - 12:07:10 PM

Registered Linux User #440901    

Login    Register
Login Required

PHP Information

This area is for examples of PHP scripting with links for the source code and general information on PHP server sided scripting. The two most recent versions are PHP4 & PHP5. The main focus here will be PHP5.
If you are a C++ (Object Oriented) person and are interested in learning a web language, then PHP is for you.

Please Note: Any code provided that writes out HTML entities like line breaks, images or forms is formatted to use valid XHTML format. This means, if you are not using XHTML, you will need to edit those tags accordingly.
For instance, if the code has “<br />” then change it to read “<br>”

Please Note 2: Most of the PHP code available on this site (so far) is for Linux or BSD based servers running some form of Apache web server.

If you would like some information on how to do something use the Contact Page. Someone will get back with you with an answer.

The PHP manual has information on just about everything you can do with PHP.
A great place that place to learn a wide variety of computer languages is W3 Schools.
This is a great place to get information on almost any computer programming language. Here's a link on their site specifically for PHP.

A quick word about safety --- DO NOT trust user input --- EVER.

Whenever user input is accepted, you should lock it down as much as you can. You only want to take in expected data and data-types to process.
escapeshellarg() is one quick way to escape some of the headaches associated with system shell commands. If you are not running your own server, you may not even have access to run shell commands from within php. There are good reasons for locking that off. It also limits some functionality. If you have an ISP or Hosting provider, you may have to ask very nicely to get that part turned on. Be prepared to show how your code will be protected.

Here' a quick example of how to use escapeshellarg().

string escapeshellarg(string $argtoescape)

So for example you have a directory to get the listing of and asign it the variable of "$dirz".

system(`ls `.escapeshellarg($dirz));

This simple example makes the command run as binary safe. Note: The backtick operator (NOT single quotes) is a shortcut to shell_exec()
This is by no means the only way to lock down php and should not be considered the only thing you do to protect from things like XSS and XXS cracking attempts. Eventually we will have a section for that.


HowTo display dynamic text based on last modified time

This is a function to make it easy to display the highlighted text: new when a page was modified within the last fourteen (14) days.

This method requires a file that will be included in the page to be displayed.

First: Right click on this link and save it as “newtime.php” to your main directory. The original filename on this server is "newtime.code" If you left click on it, you will see the source code.
Second: Once included, just add a small addition to the link.
As an example, if you want to show when the home page named index.php is newer than fourteen days:

<p><a href="../index.php">HOME<?php echo newtime("index.php");?></a></p>

Remember, take a look at the source code if you want this to look exactly as we are doing on this site, you will need to add the CSS somewhere, (preferably in your .css file). The css to add is in the source code.


Howto deal with system commands in PHP

A couple of different ways to deal with system commands.

The first is to run a command and display the output. We'll be using the “ping” command. Remember, in a non-windbloze environment you would normally want to tell it how many times to ping something. Windbloze defaults to 4 pings.

echo '<pre>';
$pingsyscmd = system("ping -c 14");
echo '</pre>';

This should produce something like the following on a web page:

PING ( 56(84) bytes of data. 64 bytes from ( icmp_seq=1 ttl=54 time=35.6 ms 64 bytes from ( icmp_seq=2 ttl=54 time=35.2 ms 64 bytes from ( icmp_seq=3 ttl=54 time=35.3 ms 64 bytes from ( icmp_seq=4 ttl=54 time=35.3 ms 64 bytes from ( icmp_seq=5 ttl=54 time=35.2 ms 64 bytes from ( icmp_seq=6 ttl=54 time=35.7 ms 64 bytes from ( icmp_seq=7 ttl=54 time=35.5 ms 64 bytes from ( icmp_seq=8 ttl=54 time=35.2 ms 64 bytes from ( icmp_seq=9 ttl=54 time=35.4 ms 64 bytes from ( icmp_seq=10 ttl=54 time=36.0 ms 64 bytes from ( icmp_seq=11 ttl=54 time=35.4 ms 64 bytes from ( icmp_seq=12 ttl=54 time=35.1 ms 64 bytes from ( icmp_seq=13 ttl=54 time=35.4 ms 64 bytes from ( icmp_seq=14 ttl=54 time=35.2 ms --- ping statistics --- 14 packets transmitted, 14 received, 0% packet loss, time 13052ms rtt min/avg/max/mdev = 35.169/35.431/36.028/0.251 ms

That's fine if you want to only display the output. What if you need to do something with the output?
That's where you would want to use “shell_exec()”. The output of shell_exec() is a string.

An example would look something like this:

echo '<pre>';
$pingshell = shell_exec("ping -c 3");
$linez = substr($pingshell, -82, 300);
print $linez;
echo '</pre>';

This should produce something like the following on a web page:

0% packet loss, time 2000ms
rtt min/avg/max/mdev = 35.951/36.034/36.133/0.172 ms

This is just an example of how to deal with the command output as a string. Basically just assign the command as a variable and do what you want with the output. There will be another example of shell_exec() shortly.


Howto disk space information

Total available space on this partition: 38195 MB
Total free space: 18500 MB
Total used space: 19695 MB
% used space: 52 %

Help Keep Us Online  

Howto Linux System Information

 12:07:10 up 12 days, 23:11,  0 users,  load average: 0.00, 0.00, 0.00

System Information: Linux www01 4.15.0-224-generic #236-Ubuntu SMP Thu Mar 28 17:59:39 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
Memory Usage (MB): total used free shared buff/cache available Mem: 3943 1825 612 3 1505 1833 Swap: 2047 298 1749
Disk Usage: Filesystem Size Used Avail Use% Mounted on /dev/vda1 38G 18G 19G 49% / udev 1.9G 0 1.9G 0% /dev tmpfs 2.0G 0 2.0G 0% /dev/shm tmpfs 395M 1.2M 394M 1% /run tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup /dev/loop0 75M 75M 0 100% /snap/core22/1380 /dev/loop1 106M 106M 0 100% /snap/core/16574 /dev/loop2 104M 104M 0 100% /snap/core/16928 /dev/loop4 39M 39M 0 100% /snap/snapd/21465 /dev/loop3 40M 40M 0 100% /snap/snapd/21184 /dev/loop5 9.9M 9.9M 0 100% /snap/canonical-livepatch/264 /dev/loop6 11M 11M 0 100% /snap/canonical-livepatch/278 /dev/loop7 75M 75M 0 100% /snap/core22/1122
CPU Information: processor : 0 model name : Intel(R) Xeon(R) CPU E5-2650 v2 @ 2.60GHz processor : 1 model name : Intel(R) Xeon(R) CPU E5-2650 v2 @ 2.60GHz processor : 2 model name : Intel(R) Xeon(R) CPU E5-2650 v2 @ 2.60GHz processor : 3 model name : Intel(R) Xeon(R) CPU E5-2650 v2 @ 2.60GHz

“Windows - Just Say No”

Time since last reboot: 12 days, 23 hours, 11 minutes, 55 seconds

Page generated in zero point one four (0.14) seconds.

@ Active Member Project Honeypot  email addresses

This page was last modified on 09/1/18 @ 10:33:49:pm
This file name: info_php.php

Questions, Comments, Suggestions or Requests should be sent to: 

There have been  32210  Unique Visitors (IP Addresses) to this site.

Current users online : 21
Maximum users at a time : 60
Last 25 attacks have come from:

There are currently 25 unique IP addresses blacklisted.

Public Server Status
server online dbc001  db cluster service
 Is On-Line
server online www03  web service
 Is On-Line
server online www  web service
 Is On-Line
server online mx 08  mail service
 Is On-Line
server online www ha  F/O web service
 Is On-Line
server online mx 11  mail service
 Is On-Line
server online Primary  Client DNS
 Is On-Line
server online Secondary  Client DNS
 Is On-Line

©Copyright 2004-2024 - - Redd Enterprises™, Inc.,  All Rights Reserved.
Ubuntu® is a registered trademark of Canonical Ltd.
Linux® is a registered trademark of Linus Torvalds.
Apache® is a registered trademark of The Apache Software Foundation.
PHP® is a registered trademark of The PHP Group.
The MariaDB® a registered trademark of the MariaDB Corporation Ab.
MySQL® is a registered trademark of the Oracle Corporation Inc.
All other product and service names mentioned are the trademarks of their respective companies.


Let us know what you think!