I have never used PHP.
Can PHP modify a page after it has been served so that the modified page will be served next time?
Can PHP modify a page after it has been served?
Moderator: General Moderators
Re: Can PHP modify a page after it has been served?
In combination with AJAX, you might. http://w3schools.com/ajax/default.asp
Re: Can PHP modify a page after it has been served?
Not really.
When a URL is requested of PHP, PHP generates some output, passes that output to the web server, and the web server then returns that to the client. Often, before the page is even fully served up, PHP has finished executing. After that, there is no way to change what was sent to the client.
~elvind mentions AJAX, which allows you to use Javascript to dynamically load content into an existing webpage, without loading the webpage. That allows you to modify the page as it exists for the client, but it doesn't change the output a PHP file generates.
When a URL is requested of PHP, PHP generates some output, passes that output to the web server, and the web server then returns that to the client. Often, before the page is even fully served up, PHP has finished executing. After that, there is no way to change what was sent to the client.
~elvind mentions AJAX, which allows you to use Javascript to dynamically load content into an existing webpage, without loading the webpage. That allows you to modify the page as it exists for the client, but it doesn't change the output a PHP file generates.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: Can PHP modify a page after it has been served?
Tell us what you want to do and we can give you a better answer.
Re: Can PHP modify a page after it has been served?
Yes, the most simplistic example:
each time (or roughly each time) it will serve different content (random number). Guys I don't think hes talking about AJAX, the question implies a subsequent http request should serve new content. Yes this is possible, and is usually done.
Code: Select all
echo rand(1,10);
Re: Can PHP modify a page after it has been served?
Doesn't seem like this was really very important to him in the first place, anyway.