Jump to content

Archived

This topic is now archived and is closed to further replies.

vnought

Query Strings & Include()

Recommended Posts

Hey,

Just a thought-I thought it might be useful if true: Can include (and its require counterpart) pass $_GET variables through to the page it's including, say:

[code]include('header.php?page=12');[/code]

Thanks.

Share this post


Link to post
Share on other sites
no, include does not load the page it just inserts the code for processing on the same page, but if the $_GET was set in the page holding the include(); function it would affect the included file in the same manner

Share this post


Link to post
Share on other sites
Giving you an example; if you have a file called "header.php":

[code]<?php

echo 'Page: ' . $_GET['page'];

?>[/code]

Now if you access header.php?page=12 it will print out:
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Page: 12[/quote]

But if you have another file, called another.php:

[code]<?php

include 'header.php';
echo 'Included!';

?>[/code]

And access another.php?page=15, it will print:

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Page: 15
Included[/quote]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.