Page 1 of 2

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

Posted: Fri Feb 13, 2004 12:52 pm
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

Posted: Fri Feb 13, 2004 1:44 pm
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.

Posted: Fri Feb 13, 2004 2:16 pm
by m3mn0n
You might want to fix that variable name to: $_GET

;)

Posted: Fri Feb 13, 2004 4:08 pm
by voodoo9055
Opps, my bad.

You are right.

GET >$_GET

Posted: Fri Feb 13, 2004 4:51 pm
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..

Posted: Fri Feb 13, 2004 9:09 pm
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');

Posted: Fri Feb 13, 2004 9:49 pm
by seeker2921
Looks legit to me..

Posted: Fri Feb 13, 2004 10:22 pm
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

Posted: Fri Feb 13, 2004 10:33 pm
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.

Posted: Fri Feb 13, 2004 10:42 pm
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.

?>

Posted: Fri Feb 13, 2004 10:43 pm
by markl999
So just include 'index.php'; and index.php will have access to $_GET['id'] without you having to do any extra work.

Posted: Fri Feb 13, 2004 10:44 pm
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... ?!

Posted: Fri Feb 13, 2004 10:50 pm
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

Posted: Fri Feb 13, 2004 10:56 pm
by Illusionist
ok!! thanks for the clarification!! I'm satisfied now tha i've learn something new!! hehe

Posted: Sat Feb 14, 2004 12:22 am
by voodoo9055
include 'index.php?id='.$id; //won't work

Works for me on my localhost and my web host.