|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Dynamic Linking with PHP
Dynamic linking and page generation is a very useful tool for your website. It makes every site follow a specific template for site consistency so its easy to change designs. Here is an example of one done in PHP.
<?php switch ($page) { case "news": include('news.html'); break; case "about": include('about.html'); break; case "contact": include('contact.html'); break; default: include('start.html'); } ?> An example link to the "news" page would be http://domain.com/index.php?page=news. Going to this site would add news.html to the rest of the html. Knowing this, you can go crazy and make some page specific commands! Note: Google does not like pages that use this script. However, you can use the apache mod_rewrite module to change the url to be more cache friendly. I'm not quite sure how to do this. For for information visit: http://www.dotdragnet.com/content.php?aid=18 Enjoy! Last edited by plutonium83 : 09-01-2005 at 09:41. |
|
#2
|
|||||
|
|||||
|
Re: Dynamic Linking with PHP
Quote:
hehe, just felt I needed to point that out. |
|
#3
|
|||
|
|||
|
Re: Dynamic Linking with PHP
For more complicated sites, I like to keep pages separated based on functionality. For example, I have editnews.php, thise file only deals with editing the news that goes on the site. If I want to add i do editnews.php?do=add ... this way the program doesnt get hugely out of hand and its still relatily easy to find your way around the backend of your site.
|
|
#4
|
|||
|
|||
|
Re: Dynamic Linking with PHP
Cool, I never thought of that.
Does anyone have experience with mod_rewrite? |
|
#5
|
|||||
|
|||||
|
Re: Dynamic Linking with PHP
Quote:
About mod_rewrite.. my favorite part of the apache manual is this: Quote:
Sorry, mod_rewrite is crazy for me too.. takes me forever to accomplish anything whenever i try to use it. Good luck! Jack |
|
#6
|
||||
|
||||
|
Re: Dynamic Linking with PHP
PHP Code:
something.php?id=filenamewithout.php |
|
#7
|
||||
|
||||
|
Re: Dynamic Linking with PHP
Warning! Above code is insecure!
Lets attacker execute arbitrary code available on the server. (For example, what happens when someone uses id=../../../other_user/comproming_script ? I don't know either. That should make you nervous. Another interesting idea would be calling id=../something.php. Watch as PHP enters a recursive loop including the same file over, and over and over until something dies.) Always, always, always, and oh yah, always, check data. BTW, you don't need use the Location:index.php?id=Main bit either. Just... PHP Code:
PHP Code:
(IE: why put all your content in include/news.php and then load it when you receive requests for http://foo.com/news.php when you can just go to http://foo.com/news.php?) I have been doing this for awhile, and really like the system. Soo.... some "sample code". I store all my content as xml (because I can I guess.) A sample content file looks like: Code:
<page>
<title>Page Title</title>
<content>This is the page content</content>
</page>
Code:
php_value auto_prepend_file header.php php_value auto_append_file footer.php <FilesMatch "^[^\.]+$"> SetHandler application/x-httpd-php </FilesMatch> The header file basically just includes library classes and starts output buffering. PHP then dumps the file to the output buffer (trivia: ob_start(), echoing stuff, then ob_get_contents() and ob_end_clean() is the fastest way to concat string in PHP. Faster than an array and implode(), faster than 'something'.'something'. Its magic. ), and I pickup the output in footer.php, and start processing. (IE: replace templating code with the actual HTML I want. Executing behaviors like posting comments, etc).Now that I've rambled this long, I'll go away. Last edited by HFWang : 12-01-2005 at 19:56. Reason: whoa, had an idea. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Speaking of PHP 5... | Ryan M. | IT / Communications | 3 | 01-08-2004 16:46 |
| openFIRST PHP 5 Compatibility | Timothy D. Ginn | FIRST-related Organizations | 0 | 30-07-2004 13:45 |
| PHP and Wiki Error | Venkatesh | Website Design/Showcase | 2 | 24-07-2004 15:51 |
| php vs. perl | Jack | Website Design/Showcase | 20 | 29-12-2002 17:01 |
| What's better, PERL/cgi or PHP/my_sql? | mikefrei | Programming | 10 | 27-05-2002 22:50 |