how do I make blah.php?id=home.php work

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

andylyon87
Forum Contributor
Posts: 168
Joined: Sat Jan 31, 2004 5:31 am
Location: Dundee

how do I make blah.php?id=home.php work

Post by andylyon87 »

how do I get the function mentioned to work. I have no idea how it is done, is it something to do with include($id.php) or something
User avatar
voodoo9055
Forum Commoner
Posts: 51
Joined: Sat Apr 26, 2003 3:27 pm
Location: Montgomery, AL

Post by voodoo9055 »

Code: Select all

<?php

$id = GET['id'];

include('index.php?id=' . $id . '.php');

?>
I would leave the ".php" out of the address line. You can use a plan link to call it.

Code: Select all

&lt;a href="index.php?id=edit"&gt;
This is not complete, but it should give you an ideal of how it works.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

You might want to fix that variable name to: $_GET

;)
User avatar
voodoo9055
Forum Commoner
Posts: 51
Joined: Sat Apr 26, 2003 3:27 pm
Location: Montgomery, AL

Post by voodoo9055 »

Opps, my bad.

You are right.

GET >$_GET
seeker2921
Forum Contributor
Posts: 120
Joined: Sat Mar 22, 2003 7:10 pm
Location: Wiesbaden Germany
Contact:

Post by seeker2921 »

Heres how I do it..

Code: Select all

index.php

<? 
if(!isset($id)){
include('/home/oblivion/public_html/site/blog/index.php');
} 
else 
{ 
    for($i=0; i<count($links); $i++) 
    { 
        if($id==$links[$i]) 
        { 
            include($url[$i]);
            break; 
        } 
    } 
} 
?>
And then I make two arrays one called $links and the other called $url and it works great..
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

correct me if im wrong, but you can't do an include like this:

Code: Select all

include('index.php?id=' . $id . '.php');
seeker2921
Forum Contributor
Posts: 120
Joined: Sat Mar 22, 2003 7:10 pm
Location: Wiesbaden Germany
Contact:

Post by seeker2921 »

Looks legit to me..
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

well, do you have to turn something on/off because anytime i do an include() like

Code: Select all

include('2.php?id=anything'); //<<Line 3
i get these errors:

Code: Select all

Warning: main(2.php?id=anything): failed to open stream: No such file or directory in O:\Program Files\Apache Group\Apache2\htdocs\tests\test2.php on line 3

Warning: main(): Failed opening '2.php?id=anything' for inclusion (include_path='.;c:\php4\pear') in O:\Program Files\Apache Group\Apache2\htdocs\tests\test2.php on line 3
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Why would you want to include('2.php?id=anything') ? When you include a file it inherits the variables of the script including it, so just doing include '2.php' should be fine as 2.php will inherit $id.
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

i dont want to do that. But thats what voodoo9055 said to do:
voodoo9055 wrote:

Code: Select all

<?php
$id = GET['id'];
include('index.php?id=' . $id . '.php');
?>
And i'm saying that wont work... php.net agrees with me too!!
http://us2.php.net/function.include

Code: Select all

<?php

/* This example assumes that http://www.example.com is configured to parse .php
 * files and not .txt files. Also, 'Works' here means that the variables
 * $foo and $bar are available within the included file. */

// Won't work; file.txt wasn't handled by http://www.example.com as PHP
include 'http://www.example.com/file.txt?foo=1&bar=2';

// Won't work; looks for a file named 'file.php?foo=1&bar=2' on the
// local filesystem.
include 'file.php?foo=1&bar=2';

// Works.
include 'http://www.example.com/file.php?foo=1&bar=2';

$foo = 1;
$bar = 2;
include 'file.txt';  // Works.
include 'file.php';  // Works.

?>
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

So just include 'index.php'; and index.php will have access to $_GET['id'] without you having to do any extra work.
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

sry if i *hijacked* this thread, but i was just trying to clarify that what voodoo9055 was right or wrong. because when i try it i get errors... and php.net says it wont work, but it works for some ppl... ?!
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

include 'index.php?id='.$id; //won't work
include "index.php?id=$id"; //won't work
include 'http://localhost/index.php?id='.$id; //will work
include "http://localhost/index.php?id=$id"; //will work
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

ok!! thanks for the clarification!! I'm satisfied now tha i've learn something new!! hehe
User avatar
voodoo9055
Forum Commoner
Posts: 51
Joined: Sat Apr 26, 2003 3:27 pm
Location: Montgomery, AL

Post by voodoo9055 »

include 'index.php?id='.$id; //won't work

Works for me on my localhost and my web host.
Post Reply