Jump to content


Photo

Passing get/post to include


  • Please log in to reply
3 replies to this topic

#1 leedude

leedude
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 06 August 2006 - 07:32 PM

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.

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 06 August 2006 - 07:36 PM

You cannot pass url parameters when including files, they will be ignored.

#3 ignace

ignace
  • Moderators
  • Now mod flavored
  • 6,431 posts
  • LocationBelgium

Posted 06 August 2006 - 07:39 PM

what wildteen88 said + try the following 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'];
?>


#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 06 August 2006 - 07:43 PM

You cannot pass url parameters when including files, they will be ignored.

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users