Answer the question
In order to leave comments, you need to log in
How to execute html code before php execution?
There is a php file. Its appearance is approximately the following (I replaced the angle brackets with square brackets, because Habr does not like them.)
[html]<br/>
<br/>
[script type="text/javascript"]<br/>
тут тело скрипта<br/>
[/script>]<br/>
[/html]<br/>
<br/>
<?php<br/>
sleep(5000);<br/>
php-код<br/>
?>
<?php<br/>
echo='[html]<br/>
[script type="text/javascript"]<br/>
тут тело скрипта<br/>
[/script]<br/>
[/html]';<br/>
sleep(5000);<br/>
php-код<br/>
?>
Answer the question
In order to leave comments, you need to log in
The final solution might look something like this:
[script>
$(document).ready(function()
{
$("#redirect").load('index.php');
});
[/script>
[html>
[div id='redirect',name='redirect'>
[/div>
[/html>
There is no problem
here . There is a misunderstanding of how different entities work - server and client.
php is executed not in the browser, but on the server and sends the sourcing to the browser through the web server, and then javascript (if enabled) comes into play in the browser.
in your case, the only way to execute js first is to load the page, and then use Ajax to make a request to the server to the php script.
From the generated html page using ajax, after the necessary pause (setTimeout), pull the desired php script and do what you need.
Sleep, etc. - crutches, which are better not to use.
Your main problem is that sleep(5000) is not 5 seconds, but 5000 seconds. Wait 5000 sec. and you will have html :-)
Read what an output buffer is and its management functions ( flush , ob_flush , etc.)
Run long running processes in a separate thread is better.
The view of a tab hanging in the “loading” status for an hour and a half (5000 seconds) is somehow completely unattractive.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question