CruzIT
Friday July 10, 2020 - 6:25:00 AM

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().
Usage:

string escapeshellarg(string $argtoescape)

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

<?php
$dirz="/var/www/statistics";
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.

<?php
echo '<pre>';
$pingsyscmd = system("ping www.live.com -c 14");
echo '</pre>';
?>

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

PING a134.g.akamai.net (96.17.110.66) 56(84) bytes of data. 64 bytes from a96-17-110-66.deploy.akamaitechnologies.com (96.17.110.66): icmp_seq=1 ttl=54 time=35.6 ms 64 bytes from a96-17-110-66.deploy.akamaitechnologies.com (96.17.110.66): icmp_seq=2 ttl=54 time=35.2 ms 64 bytes from a96-17-110-66.deploy.akamaitechnologies.com (96.17.110.66): icmp_seq=3 ttl=54 time=35.3 ms 64 bytes from a96-17-110-66.deploy.akamaitechnologies.com (96.17.110.66): icmp_seq=4 ttl=54 time=35.3 ms 64 bytes from a96-17-110-66.deploy.akamaitechnologies.com (96.17.110.66): icmp_seq=5 ttl=54 time=35.2 ms 64 bytes from a96-17-110-66.deploy.akamaitechnologies.com (96.17.110.66): icmp_seq=6 ttl=54 time=35.7 ms 64 bytes from a96-17-110-66.deploy.akamaitechnologies.com (96.17.110.66): icmp_seq=7 ttl=54 time=35.5 ms 64 bytes from a96-17-110-66.deploy.akamaitechnologies.com (96.17.110.66): icmp_seq=8 ttl=54 time=35.2 ms 64 bytes from a96-17-110-66.deploy.akamaitechnologies.com (96.17.110.66): icmp_seq=9 ttl=54 time=35.4 ms 64 bytes from a96-17-110-66.deploy.akamaitechnologies.com (96.17.110.66): icmp_seq=10 ttl=54 time=36.0 ms 64 bytes from a96-17-110-66.deploy.akamaitechnologies.com (96.17.110.66): icmp_seq=11 ttl=54 time=35.4 ms 64 bytes from a96-17-110-66.deploy.akamaitechnologies.com (96.17.110.66): icmp_seq=12 ttl=54 time=35.1 ms 64 bytes from a96-17-110-66.deploy.akamaitechnologies.com (96.17.110.66): icmp_seq=13 ttl=54 time=35.4 ms 64 bytes from a96-17-110-66.deploy.akamaitechnologies.com (96.17.110.66): icmp_seq=14 ttl=54 time=35.2 ms --- a134.g.akamai.net 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:

<?php
echo '<pre>';
$pingshell = shell_exec("ping www.google.com -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: 38243 MB
Total free space: 23329 MB
Total used space: 14914 MB
% used space: 39 %

Collecting For A Server Upgrade  

Howto Linux System Information

Uptime:
 06:25:00 up 304 days, 11:58,  0 users,  load average: 0.01, 0.01, 0.00

System Information: Linux www01 4.15.0-54-generic #58-Ubuntu SMP Mon Jun 24 10:55:24 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
Memory Usage (MB): total used free shared buff/cache available Mem: 11724 1772 3297 3 6654 9634 Swap: 2047 0 2047
Disk Usage: Filesystem Size Used Avail Use% Mounted on /dev/sda1 38G 13G 23G 36% / udev 5.7G 0 5.7G 0% /dev tmpfs 5.8G 0 5.8G 0% /dev/shm tmpfs 1.2G 744K 1.2G 1% /run tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 5.8G 0 5.8G 0% /sys/fs/cgroup
CPU Information: processor : 0 model name : QEMU Virtual CPU version 2.0.0 processor : 1 model name : QEMU Virtual CPU version 2.0.0 processor : 2 model name : QEMU Virtual CPU version 2.0.0 processor : 3 model name : QEMU Virtual CPU version 2.0.0

“Windows - Just Say No”

Time since last reboot: 304 days, 11 hours, 58 minutes, 12 seconds

Page generated in zero point four seven (0.47) 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:  ronnie@cruzit.com 

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

Current users online : 17
Maximum users at a time : 50
Last 25 attacks have come from:
51.75.23.214
199.115.117.70
178.137.88.65
139.59.172.23
51.83.171.25
104.211.29.53
51.91.157.255
13.95.130.2
140.82.4.27
52.230.3.147
167.99.13.90
40.83.89.19
3.208.228.221
137.59.110.53
93.22.37.164
46.101.61.207
51.104.208.250
13.228.47.114
69.167.13.148
52.240.55.118
138.197.171.66
68.183.203.140
162.247.74.74
185.220.103.8
185.220.101.207

There are currently 25 unique IP addresses blacklisted.

Public cruzit.com Server Status
server online limelight  web service
 Is On-Line
server online limelight  mail service
 Is On-Line
server online www  web service
 Is On-Line
server online mx 08  mail service
 Is On-Line
server online www01  F/O web service
 Is On-Line
server online mx 09  mail service
 Is On-Line
server online tertiary  DNS service
 Is On-Line
server online mx 10  mail service
 Is On-Line

©Copyright 2004-2020 - cruzit.com - 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.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
All other product and service names mentioned are the trademarks of their respective companies.

 

pretrial
pretrial
pretrial
pretrial
Let us know what you think! finance@homelandcomputersecurity.com