Using header to redirect the browser
The PHP header function allows redirection of the browser, among other cool things.
Example redirecting the browser to php-scripts.com homepage:
<?php
header(”Location: http://www.php-scripts.com/”);
?>
Writing about PHP scripting since 12/99. Learn something new every day.
PHP Diary // Home
The PHP header function allows redirection of the browser, among other cool things.
Example redirecting the browser to php-scripts.com homepage:
<?php
header(”Location: http://www.php-scripts.com/”);
?>
Finding out the number of days elapsed from a UNIX timestamp is actually pretty straightforward. If you only know two dates then first you’ll need to convert the date to a UNIX timestamps and then subtract the most recent timestamp from the older timestamp like this:
<?php
$old_timestamp = 1102971600;
$elapsed_seconds = time() - $old_timestamp;
print ‘Seconds elapsed since […]
How to create a query list of ID numbers using join from an $array and put into a string that can be used in a MySQL query:
$id_numbers = array(1,6,14,32,84,27,49,77);
$complist = join(”,”, $id_numbers);
$query = “SELECT id from tablename WHERE id IN($complist)”;
substr comes in handy if you need to strip characters off the end of a string.
<?php
$test_string = ‘item 1, item 2, item 3, ‘;
$test_string = substr($test_string,0,-2);
echo($test_string); // returns “item 1, item 2, item 3″
?>
Tired of black and whit coding that looks like what’s above? Want to colorize it to look like this instead:
Here is how to make colorized pretty source code using the .htacess method for .phps files:
Step 1. create a text file and save it as .htaccess. Put the following code in the file:
AddType application/x-httpd-php-source .phps
Step 2. […]
Using the phpinfo() function you can easily find the location of the php.ini file on the server. Here’s the code to generate the phpinfo information pictured above:
<?php
phpinfo();
?>
Shown with the red arrows in the screenshot above:
#1 - this is the version of PHP
#2 - these are the configured library. For example ‘–with-mcrypt=/usr/lib’ means the mcrypt library […]
Welcome to the PHP-scripts blog. Though I’m not a huge fan of ‘Hello World’ stuff, it seems that is where most things in the programming world start out. So here we go with examples using print and echo
Hello World using print statement
<?php
print ‘Hello World!’;
?>
Hello World using echo
<?php
echo ‘Hello World!’;
?>
What is the difference between […]