Jump to content

Help!!! Including remote files


amarques

Recommended Posts

Hi,

 

This is probably a very basic question to many of you, but I'm just starting in PHP.

 

I need for a variable to be used on a remote file that is included and a new variable from this included file to be used on the script.

 

I'll try to demonstrate:

 

On my file1.php I have

 

<?php

$c=4;

include 'http://www.example.com/file2.php';


$multiply=$sum*2;

echo $multiply;

?>

 

On my file2.php:

 

<?php

$a = 2;
$b= 6;

$sum=$a+$b+$c;


?>

 

It is always returning 0 as in multiplication of 2 against and empty $sum variable.

 

 

What am I doing wrong? What is the best way to do such a thing? I'm sure there is a way to do it, probably altering the scope of the variables, but again, I'm just starting and would really need your advice.

 

Thanks for any help.[pre][pre][/pre][/pre]

Link to comment
Share on other sites

When you include a remote file you only get any HTML output produced by that file.

 

So, the question becomes, not what are you doing, buy why are you doing this? There is likely a more proper way of doing what you want, if you tell us what it is you are trying to accomplish.

Link to comment
Share on other sites

 

Northern Flame: Won't work... Fatal error: Call to undefined function runFunction()

 

 

PFMaBiSmAd:

 

It's a little hard to explain, but I'll try.

 

I need to have a script on server websites. Depending on some conditions that are inserted into the variables, I need the script to request a query on the database of another site and that other site answering with the result.

 

You see any way of doing this without including files? How would you do it?

 

 

Link to comment
Share on other sites

Actually, the question should be is the same database server accessible by all the domains? Different domains under the same hosting will all likely have access to the database server.

 

This are external domains not hosted on the same server. So, no access to the database. That is why I need the query to be run from a file on the server with the database.

Link to comment
Share on other sites

If the mysql server allows external/remote access you could do this directly by just putting in the proper host in the mysql_connect() function.

 

If not, there are several existing "remote mysql helper" scripts that include security. Here is a link to one such script - http://www.phpclasses.org/browse/package/4000.html

Link to comment
Share on other sites

If the mysql server allows external/remote access you could do this directly by just putting in the proper host in the mysql_connect() function.

 

If not, there are several existing "remote mysql helper" scripts that include security. Here is a link to one such script - http://www.phpclasses.org/browse/package/4000.html

 

It allows but it won't be possible to use it in this case since it only allows after IP validation

 

I'll check the script you suggested. Thanks a lot. I'll probably be back asking more question on this.

 

Meanwhile, if anyone has any other suggestion, I'll be thankful.

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.