Jump to content

Archived

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

leedude

Passing get/post to include

Recommended Posts

Im trying to pass a get variable to an include called note.php:

include "note.php?title=note1";

This causes the note to not show up at all.
I have tried going to note.php?title=note1 in a browser and it works fine.
I have also tried include "note.php";. This creates a blank note on the page(it works).

Is there some special function i have to use to pass variables to an include?

Please help.

Share this post


Link to post
Share on other sites
You cannot pass url parameters when including files, they will be ignored.

Share this post


Link to post
Share on other sites
what wildteen88 said + try the following code

[code]
<?php
if (!@$_GET['title']) {
   // if the following line returns error's then comment the line, and uncomment the second
  header('Location: ' . $_SERVER['PHP_SELF'] . '?title=note1');
   //echo "<script>window.location.href='" . $_SERVER['PHP_SELF'] . "?title=note1';</script>";
}
include('note.php');

//now the get/post variable should be available in your note.php file
// note.php
echo $_GET['title'];
?>
[/code]

Share this post


Link to post
Share on other sites
[quote author=wildteen88 link=topic=103207.msg410850#msg410850 date=1154893010]
You cannot pass url parameters when including files, they will be ignored.
[/quote]
I forgot to mention this earlier. Instad of parsing the url parameters in the include statement you should use them on the page that is including the file.

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.