Page 1 of 1

Include and Post don't get along.

Posted: Tue May 19, 2009 1:56 pm
by lovelf
File A:

Code: Select all

<?php $variablea = $_POST['variablea']; require("http://www.domain.com/fileb.php"); ?>
File B:

Code: Select all

<?php echo $variablea; ?>
//fileb.php

File b doesn't seem to use the post made on filea.php which is including this file. Is it possible to make file b use the post made on a, considering a makes the post, and is including b which has the echo statement ?

Re: Include and Post don't get along.

Posted: Tue May 19, 2009 2:00 pm
by jaoudestudios
Try include instead of require

Re: Include and Post don't get along.

Posted: Tue May 19, 2009 2:08 pm
by lovelf
Hi, thanks, I tried but still it doesn't work.

Re: Include and Post don't get along.

Posted: Tue May 19, 2009 2:15 pm
by lovelf
The same happens with $_GET.

Re: Include and Post don't get along.

Posted: Tue May 19, 2009 2:19 pm
by Benjamin
Be specific please. "Doesn't work" is not enough information.

Re: Include and Post don't get along.

Posted: Tue May 19, 2009 2:19 pm
by jaoudestudios
Can you post your actual code?

Variables should be inherited into the include. Same rules apply that they will not be inherited into a function or class, unless global is specified (but I advise against it)

Re: Include and Post don't get along.

Posted: Tue May 19, 2009 2:37 pm
by Darhazer
If you use include / require (by the way the only difference is that include produce a warning, while require produce a fatal error when operation is not successful), to include a URL, do not expect that you will receive a PHP code, that will be evaluated. The server can parse and execute PHP script and return only it's output, and you will include the output. And the variables, that are set in the local script won't be available for the executed script. What you are trying to do is applicable only for local application, and it is not the right way anyway. The included file should not depend on global variables, defined before the include.

And if you are trying to achieve this including from a remote server, you have to POST the data to the server (using curl for example)

Hope this clarifies the things and will be helpfull

Re: Include and Post don't get along.

Posted: Tue May 19, 2009 2:59 pm
by lovelf

Code: Select all

<form method="post" action="fileb.php" name="rtd"><input type="text" name="myvar" value="myvar"></form>
<script type="text/javascript">
document.rtd.submit();
</script>
//filea.php

Code: Select all

<?php
$myvar=$_POST['myvar'];
include("filec.php");
?>
//fileb.php

Code: Select all

<?php
echo $myvar;
?>
 
//filec.php

OK, it works, it wasn't working because I had http://www.domain.com/, seems it doesn't work with absolute paths.

Re: Include and Post don't get along.

Posted: Tue May 19, 2009 3:08 pm
by crazycoders
No its by design...

Include is a language construct that includes the code from another file depending where it is located. If you include a local file, then the code is included INTO your own code. If you use include on a remote file, it can't get access to the code or it would be a major security flaw...

Imagine: (And lets assume it was possible)

Code: Select all

 
include('http://www.nasa.com/includes/db.php');
 
And now i have included the code that connects me to their database server which by any chance is available through the web. Now i have full access to the NASA database.

So you see the concept here? It would be a major security flaw if it would be possible but fear not, it is NOT possible. Including a file NOT from your server forces the server to request that page just the same way you would query for a webpage. Thus, what gets returned is content that is already rendered such as a webpage with tags. The code, the memory is all used up at THAT location. Nevermind if it's your server, remember that programs are dumb, so they will request it as a distant file even though it is not!

So like Darhazer said, you could actually do:

Code: Select all

 
include('http://www.domain.com/c.php?c='.$c);
 
And now you'd get some information returned, but that info is sent to the buffer immediately i think! You'll have to test that...

Re: Include and Post don't get along.

Posted: Tue May 19, 2009 3:18 pm
by lovelf
Yeah, that works. I see the point.

Re: Include and Post don't get along.

Posted: Tue May 19, 2009 11:37 pm
by jaoudestudios
crazycoders wrote:No its by design...

Include is a language construct that includes the code from another file depending where it is located. If you include a local file, then the code is included INTO your own code. If you use include on a remote file, it can't get access to the code or it would be a major security flaw...

Imagine: (And lets assume it was possible)

Code: Select all

 
include('http://www.nasa.com/includes/db.php');
 
And now i have included the code that connects me to their database server which by any chance is available through the web. Now i have full access to the NASA database.

So you see the concept here? It would be a major security flaw if it would be possible but fear not, it is NOT possible. Including a file NOT from your server forces the server to request that page just the same way you would query for a webpage. Thus, what gets returned is content that is already rendered such as a webpage with tags. The code, the memory is all used up at THAT location. Nevermind if it's your server, remember that programs are dumb, so they will request it as a distant file even though it is not!

So like Darhazer said, you could actually do:

Code: Select all

 
include('http://www.domain.com/c.php?c='.$c);
 
And now you'd get some information returned, but that info is sent to the buffer immediately i think! You'll have to test that...
Good explaination! :)