Hey guys Im trying to hack together a website - this is my first time using php. Basically what Ive done is created a webpage in html but instead of adding the actual content of each page in the the html I have a little bit of php: <?php include("home.inc"); ?> which inserts the relevant content (of course for different pages I include different files). I was wondering if it was possible to have create a function where I had some variable instead of "home.inc" and when you clicked a link on the menu the variable would change and include the appropriate file - how would I do this. In javascript I could do this using the onlcick event - Im new to PHP so I have no idea if this can be done. Thanks in advance
Are you trying to change that variable without refreshing the page? If so, that's not possible with PHP. Otherwise, you can either add a query string to your links to pass the variable onto the next page (i.e. page.php?fetch=somepage) or assign variables based on the referring webpage ($_SERVER['HTTP_REFERER'])
PHP is server side so you can't track browser events with it. Yuu could use AJAX to load the file but this would be useless if you want search engines to index it. The best way to construct php sites is to hard code the content of each page and then just include a common header and footer file. <?php inlcude("header.php"); ?> write your content here <?php include("footer.php"); ?> PHP:
Not entirely sure this is what you're looking for, but I'll just go ahead and post it anyway. The PHP <? function content($page) { if(!$page) { $page = "frontpage"; } if(file_exists($page . ".php")) { include($page . ".php"); } else { // If no file, use default include("frontpage.php"); } } ?> PHP: This could be placed just about anywhere on your site, as long as it's included on the main page. Place this where the content should be included: <? content($_GET['page']) ?> PHP: Now you could make all the links you'd like, with a variable controlling the outcome: <a href="index.php?page=about">About the site</a> <a href="index.php?page=links">Links</a> HTML: What's happening is, the variable is passed on to the function, which then looks for a file by that name. If found, it's included and if not, the default frontpage is included. So, linking to "index.php?page=links" would include links.php, if it exists. You'd never have to mess with the actual include code again, just create files and links. Hope this helps...
Awsome thanks guys - yourve given me heaps to go - Ill have a play tonight and Ill see what I can come up with.