PDA

View Full Version : Can you php include a dynamic link?


BigJohnny
09-19-2010, 01:34 AM
quick question, can you php include a dynamic link like


<?php include("index.php?do=something"); ?>

kh99
09-19-2010, 12:48 PM
Hmm...well, you can request a remote file in various ways (in which case it could be local or remote). Here's a page that describes this: http://www.php-mysql-tutorial.com/wikis/php-tutorial/reading-a-remote-file-using-php.aspx , but I'm guessing that's not what you want since you'd want the external script to execute like it was called by the user that requested *your* page.

You can include a file but it will be executed and will send out an entire HTML page as a result, and that's probably not what you want. And you can't put "?do=something" on it. (ETA: I was wrong - see later comment)

You could probably adjust the global variables then include a script and capture the output like this:

$_REQUEST['do'] = 'something'
ob_start();
include('index.php');
$includedphp = ob_get_contents();
ob_end_clean();
but then you'd probably have to do some processing of the resulting string to get what you want.

BigJohnny
09-19-2010, 02:41 PM
heres why I ask, I have a htaccess "mod" that hides robots.txt from everyone but the big 3 robots.

part of this is adding the MIME type to treat the txt as a php file, and at the beginning of robots.txt Ive added the line

<?php include("index.php?do=something"); ?>


then I've put the "something" call in my index.php file (non vB index)

it appears to work, and when I try and load the robots.txt file in my browser I'm thrown back to the main index......working as it should.

I'm really wondering if the include is loading the entire index.php file, or if it really is just loading that little piece of code to do the bot check.

kh99
09-19-2010, 02:53 PM
Well, you know...I just never thought of that, but I was wrong - you *can* put a url in an include statement. I guess I don't know exactly what's going on in your situation.

BigJohnny
09-19-2010, 04:52 PM
I didn't want to mention what I was doing in case I "tainted" the responses.

Anyway long story short, It was a shot in the dark and I didn't think it would work, but it does, I just want to know why and/or if I'm doing it right or if it's one of those things that will work but isn't right.

I didn't know a PHP INCLUDE could call a dynamic URL. instead of loading index.php, it seems to actually only call "?do=" code because it works exactly as it should from the human end.

I won't know if it fully works until I open my site and the bots start trying to crawl.

kh99
09-19-2010, 05:22 PM
Yeah, well, I'm not a PHP or vBulletin expert, but there seems to be people here who aren't really programmers who could use a little help. Unfortunately I sometimes embarrass myself by "helping" people who actually know more about this than I do.