Automatically refresh the web page every 5 seconds, with PHP

Redict the web page with PHP

you can easily redirect to the different web page using simple php script.By using PHP header() function you can easily redirect to new page without having new extra clicks.

the following PHP script redirect the user to bugphp.com

1 <?php
2 header( 'Location: http://www.bugphp.com/' ) ;
3 ?>

make sure,it will not work if you sent any data to the browser before this function.if you write echo or print or any HTML statements or functions before the redirection you will get an error,to avoid this use PHP output buffering as follows

1 <?php
2 ob_start();
3 echo 'header test';
4 header( 'Location: http://www.bugphp.com/' ) ;
5 ob_flush();
6 ?>

Automatically refresh the web page every 5 seconds, with PHP

1 <?php
2 $url=$_SERVER['REQUEST_URI'];
3 header("Refresh: 5; URL=\"" . $url . "\""); // redirect in 5 seconds
4 ?>
Advertisements

how to make Alphabet Navigation Menu with PHP?

In this post we are going to discuses about alphabet navigation.before that do you know generating alphabets in a loop.if don’t know look at below example once

1 <?php
2
3 for ($i=65; $i<=90; $i++) {
4 echo chr($i);// chr returns specific character
5 //out put :ABCDEFGHIJKLMNOPQRSTUVWXYZ
6 }
7 ?>

In the above example chr() function returns specific character & chr() also accepts negative numbers as an ascii code[char(-100)]

You can make above output with range() function,look the example :

1 <?php foreach(range('A','Z') as $i) {
2 echo $i; }
3 ?>

output:ABCDEFGHIJKLMNOPQRSTUVWXYZ

now you can easily understand below alphabet navigation menu

1 <?php
2 $LetterList = range('A','Z');
3 foreach ($LetterList as $litter) {
4 echo '<a href="http://example.com/letter.php?letter=' . $litter. '">' .$litter. '</a>'.' ';
5 }
6 ?>

Outpup : A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

you can make above output in another way

1 <?php
2 $LetterList = array_merge(array('0-9'),range('A','Z'));
3 foreach ($LetterList as $value) {
4 echo '<a href="http://example.com/letter.php?letter=' . $value . '">' .$value . '</a>'.' ';
5 }
6 ?>

out put:A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

The description of the functions used in this tutorial are as follows

chr() this function return a spesific character

range() this function crate an array containing range of elements

foreach()foreach is used to loop over all elements of an array

array_merge() this function merges one or more arrays