westman 10 Posted September 28, 2013 Report Share Posted September 28, 2013 (edited) 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 September 28, 2013 by westman Quote Link to post Share on other sites
Mudsaf 17 Posted September 30, 2013 Report Share Posted September 30, 2013 (edited) 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 September 30, 2013 by Mudsaf Quote Link to post Share on other sites
murfitUK 0 Posted September 30, 2013 Report Share Posted September 30, 2013 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. Quote Link to post Share on other sites
westman 10 Posted October 1, 2013 Author Report Share Posted October 1, 2013 The code I wrote is just a simple example of my true code I have. how do I get my code working with cURL? Quote Link to post Share on other sites
westman 10 Posted October 10, 2013 Author Report Share Posted October 10, 2013 any help? Quote Link to post Share on other sites
justsomeguy 1,135 Posted October 10, 2013 Report Share Posted October 10, 2013 Have you researched cURL? The documentation is online. You should find several examples also. Quote Link to post Share on other sites
westman 10 Posted October 10, 2013 Author Report Share Posted October 10, 2013 I have researched cURL but got nowhere, could you provide a link to an example that is related to what i am looking for? Quote Link to post Share on other sites
justsomeguy 1,135 Posted October 10, 2013 Report Share Posted October 10, 2013 There are examples everywhere. This is the second result for "php curl download": http://davidwalsh.name/curl-download Quote Link to post Share on other sites
thescientist 231 Posted October 11, 2013 Report Share Posted October 11, 2013 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. Quote Link to post Share on other sites
westman 10 Posted October 12, 2013 Author Report Share Posted October 12, 2013 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? Quote Link to post Share on other sites
westman 10 Posted October 12, 2013 Author Report Share Posted October 12, 2013 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. Quote Link to post Share on other sites
justsomeguy 1,135 Posted October 14, 2013 Report Share Posted October 14, 2013 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. Quote Link to post Share on other sites
westman 10 Posted October 15, 2013 Author Report Share Posted October 15, 2013 I looked it up and understand it now but how do I stop this code been used by someone I don't know (hacker)? Quote Link to post Share on other sites
justsomeguy 1,135 Posted October 15, 2013 Report Share Posted October 15, 2013 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. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.