PHP Question: After the html page loaded the php script will execute?

waldopulanco29

New Member
Messages
14
Reaction score
0
Points
0
Sir may i know what command or script to use. after the page is loaded or page is appeared on a browser the php script will execute? it will not execute until the page oh html was fully appeared on browser!!
example:
<html>
<head>
<title>my page</title>
</head>
<body>
..............................
...............................
................................
</body>
</html>

<?php
// some script
?>

the php script in the bellow of html will run after the html page appeared in the browser.
any idea sir? thanks in advanced

very best regards
Waldo Pulanco
 

kadai

New Member
Messages
51
Reaction score
2
Points
0
All the commands that are between <? and ?> will always execute as long they are loaded from an php file.

For example, if you add:
Code:
echo "hello world";

and load it in the browser, at the end of your file you'll have that text printed (Now, if the browser display it, is another issue)
But remember, to have php code executed, your html file needs to be renamed from myfile.html to myfile.php
 

waldopulanco29

New Member
Messages
14
Reaction score
0
Points
0
All the commands that are between <? and ?> will always execute as long they are loaded from an php file.

For example, if you add:
Code:
echo "hello world";
and load it in the browser, at the end of your file you'll have that text printed (Now, if the browser display it, is another issue)
But remember, to have php code executed, your html file needs to be renamed from myfile.html to myfile.php

no sir, i mean after the <html> to </html> tags was loaded, the php script will execute. the php script not execute if the html page is not complete to load.

in java script u can use setTimeout() function.
then i use the sleep() function in php but didnt work. the page of html will not appear until the sleep time will reach.
i want to appear the page of html. after the page containing of html will completed then the php script will execute!!
 

lemon-tree

x10 Minion
Community Support
Messages
1,420
Reaction score
46
Points
48
What you want is impossible. The browser will think the page is still loading until all PHP has finished executing. The best alternative would be to use a javascript onload function that sends a request to the server once the page has loaded. What exactly are you trying to achieve with this?
 

waldopulanco29

New Member
Messages
14
Reaction score
0
Points
0
What you want is impossible. The browser will think the page is still loading until all PHP has finished executing. The best alternative would be to use a javascript onload function that sends a request to the server once the page has loaded. What exactly are you trying to achieve with this?

i finally solved it using javascript here is sample

<html>

<head>
<script type="text/javascript">

function delayer(){
document.write("<?php phponload();?>");
}

</script>
<title>Untitled 4</title>
</head>

<body onload="setTimeout('delayer()',15000);">





</body>
</html>



<?php

function phponload(){
echo "hello world";
}

?>
after the html page was loaded the php script will execute after 15 seconds.
 

xav0989

Community Public Relation
Community Support
Messages
4,467
Reaction score
95
Points
0
PHP is a server-side language. This means that the server processes the page, executes the php then sends it to the browser. The browser will never see nor execute php code. What you are trying to achieve is not possible using php.

JavaScript, on the other hand, is a client-side language. This means that the browser processes the page, executes the JavaScript. The server will never execute javascript code.

I recommend reading http://devzone.zend.com/node/view/id/625
 
Top