Page 1 of 1

HTML/PHP

Posted: Sat Dec 04, 2004 3:36 pm
by davidjwest
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.

Posted: Sat Dec 04, 2004 3:56 pm
by rehfeld

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>

Posted: Sat Dec 04, 2004 3:58 pm
by davidjwest
Thanks, thought it would be something simple, but I'm pretty simple myself!

:D

Posted: Sat Dec 04, 2004 4:45 pm
by John Cartwright
a simpler way would be a switch

Code: Select all

<?php
switch ($_GET['action'])
{
case 'foo' : 
include 'foo.php'
break;

case 'bar' : 
include 'bar.php'
break

default :
include 'default.php'
}
?>
or a shortened version of renfelds

Code: Select all

<?php
if (isSet($_GET['action']) && $_GET['action'] == 'foo') 
{    
require('foo.php');    
}
?>

Posted: Sat Dec 04, 2004 5:31 pm
by davidjwest
Thanks!

I didn't realise about ?action being OK within HTML.

Posted: Sat Dec 04, 2004 6:45 pm
by rehfeld
davidjwest wrote:Thanks!

I didn't realise about ?action being OK within HTML.
its just a url, i could have wrote

<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