PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
spacebiscuit
Forum Contributor
Posts: 390 Joined: Mon Mar 07, 2005 3:20 pm
Post
by spacebiscuit » Sun Aug 05, 2007 5:41 am
Hi,
Does anyone know if it is possible to use the "fwrite" function across to another domain, ie.
Code: Select all
$handle=fopen('http://www.myotherdomain.com/myfile.txt','a+')
When I try this I cam getting an error, any ideas?
Thanks,
Rob.
djdon11
Forum Commoner
Posts: 90 Joined: Wed Jun 20, 2007 5:03 pm
Post
by djdon11 » Sun Aug 05, 2007 6:25 am
i think u should use
function their ... .
may b it works .. i am not sure .. but may be
djdon11
Forum Commoner
Posts: 90 Joined: Wed Jun 20, 2007 5:03 pm
Post
by djdon11 » Sun Aug 05, 2007 6:50 am
hello
this may wotk hopefully
Code: Select all
$url = 'http://www.yahoo.com';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$returned = curl_exec($ch);
curl_close ($ch);
echo $returned;
spacebiscuit
Forum Contributor
Posts: 390 Joined: Mon Mar 07, 2005 3:20 pm
Post
by spacebiscuit » Sun Aug 05, 2007 9:57 am
Thanks for the reply, I tried this but still no success:
$url = '
http://www.mydomain.com/myfile.txt ';
Code: Select all
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$url = curl_exec($ch);
curl_close ($ch);
if(!$handle=fopen('$url','a+')){
echo"Handle Error!";
}
Thanks,
Rob.
iknownothing
Forum Contributor
Posts: 337 Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia
Post
by iknownothing » Sun Aug 05, 2007 10:07 am
Im pretty sure you can't write to a file you dont have access to (access to, within your code, that is, obviously you may beable to access FTP).
spacebiscuit
Forum Contributor
Posts: 390 Joined: Mon Mar 07, 2005 3:20 pm
Post
by spacebiscuit » Sun Aug 05, 2007 10:33 am
Ok here is some feedback:
It seems that you can access a file on another domain, however I am experiencing some very odd behaviour when doing so, consider this statement:
if(!$handle=fopen('
http://www.mydoamin.com/this_file_does_ ... st.txt','r ')){
echo"Error<br>";
}
For the above, the error statment does
NOT rpint to the screen dispite the file not existing, however if I switch the "r" to "a+" it does!
Does not make sense, any ideas guys?
Thanks,
Rob.
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Sun Aug 05, 2007 12:21 pm
robburne wrote:
Does anyone know if it is possible to use the "fwrite" function across to another domain, ie.
Not possible, you'll need to use the ftp functions.
spacebiscuit
Forum Contributor
Posts: 390 Joined: Mon Mar 07, 2005 3:20 pm
Post
by spacebiscuit » Sun Aug 05, 2007 3:06 pm
Thanks for the feedback guys........
I gave the ftp functions a go and after a while but found I was almost pulling my hair out after an hour. Then I realised the problem (I think!) was because although I'm working with files on different domain, the domains are all hosted on the same server! So in effect the local files are in the same location as the remote files and hence the problems!
So..... I then went back to the fopen function and tried this:
$handle=fopen('../myotherdoamincom/myfile.txt','a+'))
So I'm jumping up a directory to the server's root and then acessing the other doamin and its files - seems to be working nicely anyway!
Many thanks,
Rob.
iknownothing
Forum Contributor
Posts: 337 Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia
Post
by iknownothing » Sun Aug 05, 2007 5:57 pm
It's letting you do that?? Not a very secure Host.
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Sun Aug 05, 2007 6:10 pm
iknownothing wrote: It's letting you do that?? Not a very secure Host.
Could be a dedicated server or a virtual server.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
spacebiscuit
Forum Contributor
Posts: 390 Joined: Mon Mar 07, 2005 3:20 pm
Post
by spacebiscuit » Mon Aug 06, 2007 4:38 am
It is a virtual server the structure is as follows:
usr/home/myusername/websites/mydomain
I can only access the websites that are mine and that are under my username.
Rob.