Go Back   Dreamweaver Club Forums > Hand Coders Forum > PHP
Register FAQ Members List Search Today's Posts Mark Forums Read

Thread Tools Display Modes
Old 07-12-2011, 10:44 AM   #1
Join Date: Jul 2011
Posts: 1
Default Loading specific HTML into PHP

Hey everyone,

I'm building a website in PHP where the header and footer are built into the index.php file, inbetween them is a cell in which all the other content for the website is loaded from external files.

I currently do this by adding:
PHP Code:
echo $content
into the aforementioned cell, then before the head of the index page having this for each page on the site:

PHP Code:
    if (isset($HTTP_GET_VARS["home"])){
$content file_get_contents("data/home.dat");
To call this I simply have my hyperlinks set to "/?home" etc.
While this works, with a large site you can imagine the list of above commands gets pretty weighty. I know this is a really terrible way to do this but I don't know any other way.

Can anyone point me towards a better way of loading external html content into my PHP page, variably dependant on the link just clicked by the user?

YourDirector is offline   Reply With Quote
Old 07-14-2011, 03:42 PM   #2
davidj's Avatar
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256

cURL is the best way.....

PHP Code:
function getPage$url )
$options = array(
CURLOPT_RETURNTRANSFER => true,     // return web page
CURLOPT_HEADER         => false,    // don't return headers
CURLOPT_FOLLOWLOCATION => true,     // follow redirects
CURLOPT_ENCODING       => "",       // handle all encodings
CURLOPT_USERAGENT      => "spider"// who am i
CURLOPT_AUTOREFERER    => true,     // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120,      // timeout on connect
CURLOPT_TIMEOUT        => 120,      // timeout on response
CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects

$ch      curl_init$url );
curl_setopt_array$ch$options );
$content curl_exec$ch );
$err     curl_errno$ch );
$errmsg  curl_error$ch );
$header  curl_getinfo$ch );
curl_close$ch );

$header['errno']   = $err;
$header['errmsg']  = $errmsg;
$header['content'] = $content;

Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 05:58 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com