I'm wanting to use the "Require" command but embeded within HTML, so when someone clicks a link on the webpage the "Require" goes away and executes another PHP script.
How is this done? So far I' managed to get links to access other scripts by pointing at the relevant URL but I'm not sure how to get it to process the "require".
Thanks.
HTML/PHP
Moderator: General Moderators
-
davidjwest
- Forum Commoner
- Posts: 67
- Joined: Sat Nov 06, 2004 5:26 am
- Location: Leeds, Yorkshire, England
Code: Select all
<html>
<?php
if (isSet($_GET['action'])) {
if ($_GET['action'] == 'foo') {
require('foo.php');
}
}
?>
<a href="?action=foo">click here to include the foo file!</a>-
davidjwest
- Forum Commoner
- Posts: 67
- Joined: Sat Nov 06, 2004 5:26 am
- Location: Leeds, Yorkshire, England
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
a simpler way would be a switch
or a shortened version of renfelds
Code: Select all
<?php
switch ($_GET['action'])
{
case 'foo' :
include 'foo.php'
break;
case 'bar' :
include 'bar.php'
break
default :
include 'default.php'
}
?>Code: Select all
<?php
if (isSet($_GET['action']) && $_GET['action'] == 'foo')
{
require('foo.php');
}
?>-
davidjwest
- Forum Commoner
- Posts: 67
- Joined: Sat Nov 06, 2004 5:26 am
- Location: Leeds, Yorkshire, England
its just a url, i could have wrotedavidjwest wrote:Thanks!
I didn't realise about ?action being OK within HTML.
<a href="script.php?action=foo">foo</a>
by me omitting the script.php part, then the browser will just use the current url, and tack the ?action=foo onto it, which might be more what you wanted, instead of having to hardcode all your links