AFG
AFG

Reputation: 1715

how could I write as a static page in php dynamic content?

I have certain user information that they are willing to make public and searchable. I'm thinking ala LinkedIn these should be generated static-pages that reside on our server with a fixed URL.

What, technically, is the recommended way to do this?

Here is the use case: a user indicates that he has contacts at an account, say, Gymboree. His username is stormtrooper. And he knows the Dir of IT and Dir of Network Operations.

I would like a static, searchable page that he can also send people to via email which would render the following:

"stormtrooper" knows the following titles at Gymboree:

"stormtrooper" wants contacts at the following companies:

Click the form on the right to contact him to see if you can provide him some contacts.

I'd like the page to be something that someone searching for "Gymboree" could stumble upon to help them connect, so my thinking (perhaps incorrectly) is that it should be a static page. There will be other inbound links pointing to it from similar types of pages.

If he didn't want it searchable, I would want that page for that account and username pair to simply be deleted.

Upvotes: -1

Views: 293

Answers (3)

Ryan J L
Ryan J L

Reputation:

Suppose you have a form that POSTs content to another php, which shows the dynamic results, but you want to be able to "share" the results with other people (therefore, converting the dynamic results to a static page.) Think GoogleDocs. This is what I want to be able to do (and how I found this thread.) So what is the best way to do this?

Upvotes: 0

Eran Galperin
Eran Galperin

Reputation: 86805

Your question is a little vague, but PHP can cache dynamically created pages into static ones. A very simplistic system would use output buffering to capture the dynamic contents and write them to a file. You then need to decide how to invalidate this cache (for example, by deleting the static file).

However, you should use caching only when you've encountered a specific performance problem, otherwise it just adds to the complexity of your application needlessly. You can also just cache the underperforming resource (for example database results) instead of the entire page.

If you would elaborate more on what you want to achieve, you'll get a more specific answer.

EDIT: I've reread your modified question. Your approach is incorrect - a person/web crawler requesting the page could not infer from the contents whether it was dynamically generated or not. It could try to guess from the URL format, but those can be controlled by the application. The page can be bookmarked and indexed by search engines just the same.

Caching to actual static files should be used as a optimization when generating those pages on the fly is too expensive.

Upvotes: 2

sastanin
sastanin

Reputation: 41541

If you already have these pages as dynamic content, wget them as HTML and save as static pages somewhere on your server. Serve as usual HTML. Regenerate when necessary. I just don't see a reason why you want to make them static (performance? server security policy? why only these pages?).

Upvotes: 0

Related Questions