Jump to content

using include() with GET variables


rtadams89

Recommended Posts

I have a php file named "include.php" which contains the following code:

<?php
echo $_GET['name'];
?>

 

If I go to http://myserver.com/include.php?name=ryan I get a page that contains the text "ryan".

 

I also have another page named "main.php" which has the following code:

<?php
echo "The name is: ";
include ("http://myserver.com/include.php?name=ryan");
echo ".";
?>

 

I would expect the output of this page to be "The name is ryan.". However, I get nothing.

 

I'm pretty sure this is because I am using the include() function incorrectly. What function should I use?

Link to comment
https://forums.phpfreaks.com/topic/110533-using-include-with-get-variables/
Share on other sites

<?php
echo "The name is: ";
include ("http://myserver.com/include.php?name=ryan");
echo ".";
?>

 

I would expect the output of this page to be "The name is ryan.". However, I get nothing.

 

include ("http://myserver.com/include.php?name=ryan");

 

does it really work fine? i haven't tried such feat.

anyway, why would you do that for? i don't find any good reason for printing a name from another script while passing a parameter inside include() itself.

 

what is it that you are trying to achieve, may i know?

You don't need the ?name=ryan in the include.

 

I do. Without it, the include.php page won't have anything to process.

 

does it really work fine? i haven't tried such feat.

anyway, why would you do that for? i don't find any good reason for printing a name from another script while passing a parameter inside include() itself.

 

It doesn't work fine, that's the problem.

The code I posted is a simplified example of what I am trying to do. In reality, the include.php file actually takes an e-mail address as in put, converts it to hex code, and outputs it in the form of a JavaScript document.write command. This is all so that when a robot views the source code of a page, it won't be able to pick out the mailto links and spam them.

GET variables come from a URL.

 

so go to: http://mysite.com/main.php?name=ryan

 

then just include "include.php". you don't need the ?name=ryan in the include.

 

yeah. since you got the name as get in the current page, why not create a function inside "include.php" that do such a feat. then just call it with that parameter and then returns whatever value you desire.

The posted code works (just tested) provided the php.ini settings allow_url_fopen and allow_url_include are on.

 

Is there a reason you are including using a URL instead of directly through a file system path?

 

However, I get nothing.
If you are literally getting nothing (a blank page), your actual code probably has a fatal parse or a fatal runtime error. Are you developing and testing your code on a system that has full php error_reporting set (E_ALL) and display_errors turned on?

 

 

Archived

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

×
×
  • Create New...

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.