Jump to content

shearing info from one site to another


Recommended Posts

hi all,

I am trying to get a file to run from one of my sites and send the info to my other site.

this is my code...

mysite1.com

<?phpinclude "../connect_to_mysql.php";$sql = mysql_query("SELECT * FROM pics WHERE size= 4 AND pictime != '0' ORDER BY RAND() LIMIT 1" );while($row = mysql_fetch_array($sql)){$picname = $row["id"];}$new_pic = "../images/$picname.gif";?><?phpecho "$new_pic" ?>

mysite2.com

<?php$show_pic = file_get_contents('http://mysite1.com/all/rand.php');?><?phpecho "$show_pic" ?>

at you can see it is not working and I don't know why.

any help?

Edited by westman
Link to post
Share on other sites

I don't think that's possible because of security reasons unless both websites are hosted from same server. //Prob misunderstood post but

 

$new_pic = "../images/$picname.gif"; <!-- this is only text, not image -->echo "$new_pic" <!-- this ain't closed -->

 

Have you tested your code?

Edited by Mudsaf
Link to post
Share on other sites

Mudsaf is correct that your website host has probably disabled this function. If you can call a script on one of your websites from a different website then it means others can do so to - and you don't want that to happen.

 

You should google for cURL and look at some of the tutorials available. You might be able to do it that way instead, although some hosts disable this as well.

Link to post
Share on other sites
  • 2 weeks later...

I have researched cURL but got nowhere, could you provide a link to an example that is related to what i am looking for?

then show us what you tried and what you got stuck on.

Link to post
Share on other sites

hi,

I looked up the link...

http://davidwalsh.name/curl-download

and man I tried for 2 days, but I just could not get my head around it

 

so this is my code...

mysite1.com (example code)

<?phpinclude "../connect_to_mysql.php";$sql = mysql_query("SELECT * FROM pics WHERE size= 4 AND pictime != '0' ORDER BY RAND() LIMIT 1" );while($row = mysql_fetch_array($sql)){$picname = $row["id"];}$check_new_pic = "../images/$picname.gif";if (file_exists($check_new_pic)) {$pic = "<a href="#" target="_blank"><img src="$check_new_pic" height="300" width="200px" style="border:0;" /></a>";?><?phpecho "$pic";?>

mysite2.com (true code)

<?phpfunction get_data($url) {$ch = curl_init();$timeout = 5;curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);$data = curl_exec($ch);curl_close($ch);return $data;}$returned_content = get_data('http://mysite1.com/all/rand.php');?>
as you can see I am trying to get 1 random image from one site to anotherlol google does it every day with their ads, why is it so hard?
Link to post
Share on other sites

ok people,

I got it working with...

$ch = curl_init();curl_setopt($ch, CURLOPT_URL,'http://mysite1.com/all/rand.php');curl_setopt($ch, CURLOPT_HEADER, false);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);$xml_language = curl_exec($ch);curl_close($ch);echo $xml_language;

now my last question is how do I stop people hacking me with this code and can someone explain line for line how my code works, that would be a big help for days to come.

 

thanks in advance.

Link to post
Share on other sites

That isn't code to protect against a hacker, I don't know what you're asking there. If you want to find out how cURL works, look up the documentation. Look up the reference for any function you don't understand like curl_init or curl_setopt.

Link to post
Share on other sites

If it's online then anyone can reach it. You can add authentication checking or something like that to restrict access only to people who have logged in. I don't really see how a hacker would use that code to attack your server though.

Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...