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
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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.