Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Internal redirection

Status
Not open for further replies.

lijil

Programmer
Jun 9, 2004
16
CA
Could someone please explain what is involved to enable my server/site/etc. to serve a document based on a URL query string?

I have a database which assigns an id to a path and filename and. I want users to be able to enter " in the address bar and be served up the corresponding document... however I do not want the URL to change, that is I do not want to do a simple redirect. I would like it to behave like the Microsoft Knowledge Base site (see: Is there a HTTP header I can send to do this?

I understand this may not be PHP specific but I was not sure if this required a server/http/language/etc. solution.

Thank-you,
Mike Caines
 
There is no redirection involved. The URL will be to a script which accepts the ID on the URL and produces a page with data from the database. It's a simple dynamic web page.




Want the best answers? Ask the best questions!

TANSTAAFL!!
 
The pages may not have anything in common so I could never create a document template that would be 'dynamic' enough!. Also the pages are to be stored as separate documents (separate text/html .php files). I've heard that php can do conditionaly includes which could be one option i suppose, include the entire document. I may just do a simple redirect.

Thanks for the info!
 
If your script can programmatically decide on a template and content, then a redirection may still be not necessary. Programmatically using include() statements would work nicely -- but just remember it's still not redirection, just dynamic content.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
When using dynamic includes, remember to check what it includes!

You dont want it to include sensitive information, etc.

When pages use like:

it's usually a database-drive website.
What is in the database?

Some CMS (Content Management System), might have all the data which is displayed (menu, content, layout, etc), while other might just have links to the files it is to include.

For your sollution, you can either choose to use ?include=filename
Or, you can make a mySQL table: includes
there you can specify things like:

inc_id (autonumber, unique id)
inc_filename (varchar, 255)
inc_path_to_filename (varchar, 255)
inc_filetype
etc etc

You only need the filename and path_to_filename.
They could also be one field, but for further development, you might want them seperated, so you dont have to manipulate strings if you want to retrieve just the filename or just the path_to_filename.

Then, you can make a query include:
include("{$row['inc_path_to_filename']}{$row['inc_filename']}");

ps. the query will be something like:
SELECT * FROM `includes` WHERE `inc_id` = '{$include}'

remember to check number of rows returned and show something like "Sorry, page not found", if mysql_num_rows returns 0 rows.

Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top