Go to Post From past experience members of our team insist on never trusting gravity. - Vash [more]
Home
Go Back   Chief Delphi > Technical > IT / Communications > Website Design/Showcase
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 09-01-2005, 00:19
plutonium83
 
Posts: n/a
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   Spotlight this post!  
Unread 09-01-2005, 00:36
Unsung FIRST Hero
Greg Marra Greg Marra is offline
[automate(a) for a in tasks_to_do]
FRC #5507 (Robotic Eagles)
Team Role: Mentor
 
Join Date: Oct 2004
Rookie Year: 2005
Location: San Francisco, CA
Posts: 2,030
Greg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond reputeGreg Marra has a reputation beyond repute
Re: Dynamic Linking with PHP

Quote:
Originally Posted by plutonium83
For for information visit: http://www.dotdragnet.com/content.php?aid=18

Enjoy!
Look at the dynamic linking even there!

hehe, just felt I needed to point that out.
  #3   Spotlight this post!  
Unread 09-01-2005, 01:17
colt527 colt527 is offline
Registered User
AKA: Ken Colton
FRC #0527
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Long Island
Posts: 123
colt527 is a splendid one to beholdcolt527 is a splendid one to beholdcolt527 is a splendid one to beholdcolt527 is a splendid one to beholdcolt527 is a splendid one to beholdcolt527 is a splendid one to beholdcolt527 is a splendid one to behold
Send a message via AIM to colt527
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.
__________________
Mentor, Team 527 -- Plainedge Red Dragons
FIRST Volunteer
SUNY Stony Brook Computer Science 2010
kcolton@gmail.com
  #4   Spotlight this post!  
Unread 09-01-2005, 09:40
plutonium83
 
Posts: n/a
Re: Dynamic Linking with PHP

Cool, I never thought of that.

Does anyone have experience with mod_rewrite?
  #5   Spotlight this post!  
Unread 09-01-2005, 22:21
Jack's Avatar
Jack Jack is offline
FIRST Scouting Network
AKA: Andrew Schenk
FRC #0201 (The FEDS)
Team Role: Alumni
 
Join Date: Feb 2002
Rookie Year: 2002
Location: Rochester Hills
Posts: 643
Jack is a jewel in the roughJack is a jewel in the roughJack is a jewel in the rough
Send a message via AIM to Jack
Re: Dynamic Linking with PHP

Quote:
Originally Posted by plutonium83
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.
um.. I might be wrong in a few cases, but in general, google and other search engines have no problem with that type of url. (The part after the ? is called the "query" as i recall). The exception to this is when you add a session id to the end of the url. This is normally a bunch of random letters/numbers (exe: ?sid=k01f4e24as2d) and would be used to track a user across a website when cookies weren't avialable. Becuase this session id would change on every page load, this would generate an infinate series of loops for a search engine, and therefore they won't spider the page.

About mod_rewrite.. my favorite part of the apache manual is this:

Quote:
Originally Posted by Apache manual
``The great thing about mod_rewrite is it gives you all the configurability and flexibility of Sendmail. The downside to mod_rewrite is that it gives you all the configurability and flexibility of Sendmail.''
-- Brian Behlendorf
Apache Group
`` Despite the tons of examples and docs, mod_rewrite is voodoo. Damned cool voodoo, but still voodoo. ''
-- Brian Moore
bem@news.cmc.net
http://httpd.apache.org/docs/mod/mod_rewrite.html

Sorry, mod_rewrite is crazy for me too.. takes me forever to accomplish anything whenever i try to use it.

Good luck!

Jack
__________________
Team 201 - 2003 Great Lakes Semifinalists & 2003 Archimedes Division Finalists :|: Webmaster of www.feds201.com -> FBI Scouting
Winner of The 2003 ChiefDelphi Web Award for: User That Started The Most Non Chit Chat Threads
Winner of: 2003 FIRST Ventures with 5451.68 End Points

All about me: http://knehcsa.vze.com
**Check out the New FIRST Scouting Network**
  #6   Spotlight this post!  
Unread 09-01-2005, 22:28
dragonpaulz's Avatar
dragonpaulz dragonpaulz is offline
4 P3r$0n
AKA: Paul Shapiro
#0555 (Team 555)
 
Join Date: Jan 2004
Location: Montclair, NJ
Posts: 42
dragonpaulz is an unknown quantity at this point
Send a message via AIM to dragonpaulz
Re: Dynamic Linking with PHP

PHP Code:
<?php
if (empty($_GET['id'])) header("Location: index.php?id=Main");
?>
<!-- Content -->
<?php
$fn 
"Includes/" $_GET['id'] . ".php"; if (file_exists($fn)) {include($fn);} else {include("Includes/404.php");}
?>
<!-- Put the above where u want pages to load --!>
Then it's like:
something.php?id=filenamewithout.php
__________________
Team 555 - Montclair High School
Trust, Love, and Magic
WebMaster of MontclairRobotics.org
  #7   Spotlight this post!  
Unread 12-01-2005, 19:41
HFWang's Avatar
HFWang HFWang is offline
Registered User
AKA: DarkWulf
#0115
Team Role: Webmaster
 
Join Date: Jan 2003
Location: Cupertino
Posts: 177
HFWang will become famous soon enough
Send a message via ICQ to HFWang Send a message via AIM to HFWang
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:
if (empty($_GET['id']))
    
$_GET['id'] = 'Main'
or... if you feel really frisky...
PHP Code:
$_GET['id'] = empty($_GET['id']) ? 'Main' $_GET['id']; 
Another nitpick is that this isn't dynamic linking. Its basically just including. At which point you're better off just using .htaccess (or appropriate platform-specific replacement) and setting auto_prepend_file/auto_append_file php settings. You're organizing the files along the way the fileystem is internally, so you may as well just stick the header/footer on around the actual file.

(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>
My htaccess looks like:
Code:
php_value auto_prepend_file header.php
php_value auto_append_file footer.php

<FilesMatch "^[^\.]+$">
	SetHandler application/x-httpd-php
</FilesMatch>
(For those with weak regex foo, it basically just has all files without extensions execute as PHP. I just think its cool to hide extensions. I'm weird like that)

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.
__________________
rawr

Last edited by HFWang : 12-01-2005 at 19:56. Reason: whoa, had an idea.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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


All times are GMT -5. The time now is 23:53.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi