lo ppl, just a few months of php experience on amateur-level and im starting to need some help from pros here is what im trying to do: i have 2 webserver, im running on the 1st an application, and on the second one i want to store some simple variables. on my first server, in the index.php file, im including the file from the second server like: include("http://my_second_server/thepath/thefile.php"); this file has only one variable, <?php $thevariable = "looser" ; ?> so, what to do, so i can use the index.php file from the fisrt server, to output the word "looser" ??? i tried as the index.php file that : <?php include("http://my_second_server/thepath/thefile.php"); echo "you are a $thevariable" ; ?> why isn't that working, and what do i have to do so it is going to work ?? your help is appreciated
Some, sorry most servers block access so people can not require include ect files This is saftey, otherwise people can just include the file and see the code. Horrible
it seems that my server allows the include to take place, i added on the include file thefile.php <?php $thevariable = "looser" ; echo "you are a $thevariable" ; ?> and when i call the index.php file (from the first server) <?php include("http://my_second_server/thepath/thefile.php"); echo "YOU MUST BE A ".$thevariable." WHEN YOU CANT DO THAT" ; ?> im getting on the screen you are a looserYOU MUST ME A WHEN YOU CANT DO THAT somehow on the index.php, the $thevariable cant be displayed
yeah that too, still nothing on the output im thinking maybe if there was a way to have on the index.php something like $_POST[$thevariable] or $GET[$thevariable] or something like that
The reason you're seeing the 'you are a looser' first is because when you include via HTTP, the script gets parsed. It's very simple: whatever your browser sees if you go to a PHP script, another PHP script will see if you include via HTTP. It doesn't do anything special. So, when script A prints a string and then is included via HTTP from script B, then script B basically gets a bit of text that is not within the PHP tags and so prints it straight out. Just like when you 'include' a file that doesn't have its own PHP tags. One way of doing what you want to do is name the file that you want to include with a non-.php extension. That way, the file doesn't get parsed by the server. It just gets sent to the script that is including it. Because of this, however, you have to realise that anyone that sends a browser to that script will get the file, too. The better way to do what you want to do is to maybe make a webservice on the server you want to include from and make it return an array of all of the variables you want.
@ TwistMyArm: tried to remane the file thefile.php to thefile.txt but im getting on index.php that output : $thevariable = "looser" ;YOU MUST ME A WHEN YOU CANT DO THAT it prints the content of thefile.txt complete !
sunbeam: did you still have the <?php and ?> tags around the line, even though it was a .txt file? If so.... then I don't know, sorry
Of course there's no need for it in a text file, but what you're effectively trying to do is get your include to grab a complete, valid PHP script. The only way you can do that this way is to have a complete, valid PHP script that doesn't get parsed. Hence the extension such as .txt. But I'm assuming you've already tried to put them back in, but keep the .txt extension, right?
@TwistMyArm: dude, u r a genius left the <?php... .?> thing inside, renamed the *.php file to *.txt, changed the include("http://my_second_server/thepath/thefile.php"); to include("http://my_second_server/thepath/thefile.txt"); and everything worked fine !!!!! thanx so much