Brief analysis on the implementation of local refresh function of PHP page _php tutorial

Source: Internet
Author: User
There are quite a few ways. Previously more commonly used is the IFRAME to do so. Now there is an Ajax, so the general situation is to use Ajax.
The first approach, AJAX implementations:
Of course, Ajax is actually very simple to implement, but a lot of knowledge is still relatively deep. I used to do the page time automatically refresh the function is to use the Ajax. The complete code is:
1.gettime.php:
Copy CodeThe code is as follows:
Header ("Cache-control:no-cache,must-revalidate");
Header ("Content-type:text/html;charset=utf-8");
$time = "2012-1-20 18:00:00";
$dt _element=explode ("", $time);
$date _element=explode ("-", $dt _element[0]);
$time _element=explode (":", $dt _element[1]);
$date = Mktime ($time _element[0], $time _element[1], $time _element[2], $date _element[1], $date _element[2], $date _ Element[0]);
$nowTime = time ();
$showtime = Date ("GMT y m D h:i:s", $date-$nowTime);
if ($showtime <= "Beijing Time January 01, 1970 08:00:00") {
echo "Happy New Year";
}
Echo $showtime;

2.zidong.php:
Copy CodeThe code is as follows:


Ajax Dynamic Display Time



Current time:






In the browser directly access to zidong.php, click on the button inside to see the effect.
This is a small example of using Ajax to refresh the local content of the page. You may wonder: is there no interaction with the database? This is not simple, directly on the gettime.php page inside the operation is OK.

This method will not have to say more. As for what the code inside AJAX means, don't ask me, I said before, the Ajax in this is still a bit deep.

The second method is implemented using the IFrame method.
Don't tell me to use PHP's include can AH. You go and try it. Yes, you can not have so many people in Baidu inside asked.
This method is complex, in fact, it is quite simple. Here's how it works:
To refresh the page to automatically refresh the local code to take out a separate page, automatic refresh There are many ways: you can use JavaScript in this separate page control, what SetTimeout ("Start ()", 1000); Ah or setinterval ("Start ()", 1000); (Refresh the page every 1 seconds) This is also possible with the META tag: (Refreshes the page every 10 seconds). This is done using an IFRAME in the original page to call it over. That's all you can do.
Let's go to the sample code:
1.show.php:
Copy CodeThe code is as follows:





<title>Admin</title>




































if (Isset ($question) &&!empty ($question)) {?> }?>
Product questions and Answers detailed list
Details of the issue:
Questioner: Question Time:












You can answer it too:








2.product_newmsg.php:
Copy CodeThe code is as follows:















if (Isset ($answers) &&!empty ($answers)) {
foreach ($answers as $key = = $value) {
?>



















}}else{?> }?>
Reply:

if ($_session[' ADMINISTRATOR ')} {//If $_session[' ADMINISTRATOR ']=0, which is not a super administrator, the Delete button is not displayed
?>
);" >
}
?>
Respondents: answer time:
There is no user answer at this point, you can fill in the following to answer



This can be achieved. You can see the effect by accessing show.php in the browser. But there's a lot of things in this example that manipulate the database. Direct access has little effect. But the code is sure to be possible. Both the principle and the code are complete.
All right. These two methods are described here. There are two ways to finish basically all of the page local refresh.

http://www.bkjia.com/PHPjc/327762.html www.bkjia.com true http://www.bkjia.com/PHPjc/327762.html techarticle There are quite a few ways. Previously more commonly used is the IFRAME to do so. Now there is an Ajax, so the general situation is to use Ajax. The first approach, AJAX implementations: Of course, Ajax uses ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.