HTML/PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
davidjwest
Forum Commoner
Posts: 67
Joined: Sat Nov 06, 2004 5:26 am
Location: Leeds, Yorkshire, England

HTML/PHP

Post 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.
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post 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>
davidjwest
Forum Commoner
Posts: 67
Joined: Sat Nov 06, 2004 5:26 am
Location: Leeds, Yorkshire, England

Post by davidjwest »

Thanks, thought it would be something simple, but I'm pretty simple myself!

:D
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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');    
}
?>
davidjwest
Forum Commoner
Posts: 67
Joined: Sat Nov 06, 2004 5:26 am
Location: Leeds, Yorkshire, England

Post by davidjwest »

Thanks!

I didn't realise about ?action being OK within HTML.
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post 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
Post Reply