Can PHP modify a page after it has been served?

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
Neville
Forum Newbie
Posts: 1
Joined: Wed Apr 13, 2011 1:41 pm

Can PHP modify a page after it has been served?

Post by Neville »

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?
eivind
Forum Commoner
Posts: 28
Joined: Tue Apr 19, 2011 7:57 am

Re: Can PHP modify a page after it has been served?

Post by eivind »

In combination with AJAX, you might. http://w3schools.com/ajax/default.asp
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Can PHP modify a page after it has been served?

Post by pickle »

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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Can PHP modify a page after it has been served?

Post by califdon »

Tell us what you want to do and we can give you a better answer.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Can PHP modify a page after it has been served?

Post by josh »

Yes, the most simplistic example:

Code: Select all

echo rand(1,10);
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.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Can PHP modify a page after it has been served?

Post by califdon »

Doesn't seem like this was really very important to him in the first place, anyway.
Post Reply