Pinging from a web page

Example using fping (You could use piong instead, but if you install fping you can limit the time) <?php $cfg_endpoint = "www.google.com"; echo ("<p>Pinging $cfg_endpoint:</p>"); echo ("<p>Result:</p>"); //—– DO THE PING —– $output = shell_exec("fping -c1 -t750 $cfg_endpoint 2>&1"); echo "<pre>$output</pre>"; ?>  

Read More

Write File

chmod Note that the directory you write the file to may need chomd set to 777 (php needs the Execute bit set to be able to write).  This can be a potential security risk if this is a concern. Write text to a file (overwrite if exists) Write text to a file (create or append)

Read More

Read file

Read a text file Read a binary file to an array Your file may be byte based by PHP works to stop you operating at a raw byte level, so you have to workaround that a bit by using unpack If your file is very big then get clever with fread etc and only read chunks […]

Read More

TOP (LIMIT in mySql)

SQL Server doesn't use the LIMIT keyword, instead use TOP() to select the maximum number of rows to return: SqlCommand1->CommandText = "SELECT TOP(1) SomeRowName \ FROM SomeTableName \ WHERE SomeRowName2 == 0";  

Read More

Get AutoIncrement Value For A New Record

If your table has a column  that is auto assigned a value when a record is created, e.g. an autoincrement ID value, you can get it using scope_iendity() as follows: int RecordId; SqlCommand1->CommandType = CommandType::Text; SqlCommand1->CommandText = "INSERT INTO MyTable (SomeRow1, SomeRow2) VALUES (@MyValue1, @MyValue2); SELECT CAST(scope_identity() AS int)"; SqlCommand1->Parameters->AddWithValue("@MyValue1", MyValue1); SqlCommand1->Parameters->AddWithValue("@MyValue2", Convert::ToString(MyValue2)); RecordId = (Int32)SqlCommand1->ExecuteScalar(); //ExecuteScalar […]

Read More

Refresh after form POST

This is a solution to the problem of pressing refresh after posting a form causing a "resubmit form information message box" for the user.  This simply causes the page to reload and can be placed after handling the POST actions if ( isset($_POST[‘action’])) { //—– AFTER ANY POST RELOAD THE PAGE SO REFRESH CAN BE USED —– […]

Read More

Simple Site Log In Form

In the head of each page add this Note this must be before any html header are sent (i.e. in php code before html output) Use this as the log in page Use this as an optional log out page

Read More

GROUP BY

Get a single result for each MyColumnName value that matches the search criteria For example, say you have multiple rows where MyColumnName=1 that each matches the query, you’ll get back just one result with MyColumnName=1 Same but with an additional field that tells you how many rows matched for each MyColumnName COUNT and GROUP BY […]

Read More

openssl_random_pseudo_bytes

openssl_random_pseudo_bytes is used for cryptographical randomness where rnd() isn't suitable $salt = openssl_random_pseudo_bytes(22); $salt = substr(strtr(base64_encode($salt), array('_' => '.', '~' => '/')),0,22); //Sets length to 22 characters    

Read More