Supa Comix 0 Report post Posted December 10, 2007 Hello there. I am extremely curious into the include function. I have started using it a lot in order to cut down sizes of my websites as it prevents me having to type about 20 lines of code over and over again. But i am curious if i can use the include function to include pages that are not on the website. For instance, i have two pages: test.php This page is on one domain <?phpprint "Initiating Test...<BR>";include "http://forums.xisto.com/no_longer_exists/ "<BR>...test complete.";?> test2.phpThis page is at http://forums.xisto.com/no_longer_exists/ <?phpecho "<P>Hello World</P>";?> Yet when i run test.php all i get is: Initiating Test... ...test complete. Does anyone know why? Share this post Link to post Share on other sites
turbopowerdmaxsteel 0 Report post Posted December 10, 2007 If allow_url_fopen is enabled on the server, then it should work. I think if it isn't enabled, you'll see an appropriate error message. Make sure you don't have the error_reporting flag turned on. Also, remote files with parameters, such as include 'http://forums.xisto.com/no_longer_exists/' will try to include the file myfile.php?name=max and not myfile.php. Share this post Link to post Share on other sites
Quatrux 4 Report post Posted December 10, 2007 Yeah, if you include from url, you'll get the parsed version of the file if it was a php file, I don't think that using an include function like that is logical, well I remember I used to do it, but from my own server, after some time I realized that I can use absolute path and even use ./ ../ current, parent directories..if you're running on php5, there is a setting allow_url_fopen and it is true false for fopen and similar files, which can't do anything with the code without eval() thats why for include function another setting was introduced allow_url_include, if it is turned of you can't use the include function like that and note that even though allow_url_include is set to on, but if allow_url_fopen is false, then you can't even include..I remember I used to play with opening things remotely into a string or array and used to str_replace things the way I wanted I felt the speed differencies.. Share this post Link to post Share on other sites
Supa Comix 0 Report post Posted December 10, 2007 Well what im trying to do is just to get some data from another website of mine and then pasting it on another website. For instance if there is a variable in website 1, i would like to retrieve it from its mysql database and then print it on the second website.Is there a better way of doing it? Share this post Link to post Share on other sites
Quatrux 4 Report post Posted December 11, 2007 Well, I guess you can do it with fsockopen() read about it on the PHP Manual.. also you can do it with file_get_contents() if the settings will let you opening urls.. If you want to on your Website-1 to include something from Website-2 just create a php or whatever file on Website-2 with the content you require for Website-1 then from the Website-1 get the content with that function by linking to that file, so you'll get an variable with that content and you can do anything you want with it on your Website-1.. ? I don't really understand the thing you want to do..For example if you don't have access to Website-2 and only can read the parsed data by Website-2 then you'll get the content.. Even though if on Website-2 you have access you can rename the file from .php to .incl for example and the server won't parse it as a PHP script, it will show the code, then you can include that url with that code from Website-2 to Website-1 !!!Why not just use everything locally Share this post Link to post Share on other sites
Supa Comix 0 Report post Posted December 11, 2007 (edited) I will explain what i am trying to do a bit clearer.Right On Website 1, we shall call this Supa Comix. This has its own forum and website and thus its own mysql databases and stuff... just easily configured.Now website 2, we shall call this Gal X is a website with its own seperate forum and website and stuff. But the Gal X website is completely seperate from the Supa Comix one. One is at http://forums.xisto.com/no_longer_exists/ and the other at http://forums.xisto.com/no_longer_exists/. Now what i'd like to do is to have it so that the Supa Comix website, on loading for example, will get some information from the Gal X mysql database and place it on the Supa Comix one. Now i was originally going to do this through the include function, by including a file on the Gal X website that got the data and stuck it into variables and then passed it back to the Supa Comix website so that it can be put on the page.It doesn't have to be complicated or anything. I am just curious about it as the two forums although seperate i would like to link. I don't want to join them together under one domain becuase of how big Gal X is going to be but i want them linked so that when i post news (for instance) on the Gal X forum that it is picked up by the Supa Comix website when the player opens up the news page on the Supa Comix website.EDIT: I have just found out that allow_url_fopen is disabled on the Supa Comix site. Edited December 11, 2007 by Supa Comix (see edit history) Share this post Link to post Share on other sites
turbopowerdmaxsteel 0 Report post Posted December 11, 2007 That doesn't sound too difficult. On the Gal X forum, create a PHP file, say http://forums.xisto.com/no_longer_exists/ that outputs the news information in plain text. Next, use fsockopen to open the URL. You would have to make a GET request using the HTTP protocol which goes something like this:- GET /news.php HTTP/1.1Host: galx.ulmb.comConnection; Close Use the fputs function to send this request to http://forums.xisto.com/no_longer_exists/ once the socket is open. Now, run a while loop and read all of the contents using fgets function. Finally close the socket. Given below is the entire code:-// Open the Socket$fp = fsockopen('galx.ulmb.com;, 80);// Make the requestfputs($fp, "GET /news.php HTTP/1.1\n");fputs($fp, "Host: galx.ulmb.com, "Connection: Close\n\n"); // Send two New Lines to Signal Header End// Read the Output$readText = "";while(!feof($fp)){$readText .= fgets($fp);}// Never forget to end what you startedfclose($fp); Share this post Link to post Share on other sites
Supa Comix 0 Report post Posted December 11, 2007 Thanks but i don't fully understand the code...Would i be able to use php and mysql to set the Get code?Where would i put this?How would i extract the data at the supa comix end? Share this post Link to post Share on other sites
Impious 0 Report post Posted December 11, 2007 Supa Comix, you cant use includes or requires after print some html code, like using print function or echo... ever you use that the code wont be perfectly runned. Share this post Link to post Share on other sites
Quatrux 4 Report post Posted December 12, 2007 Supa Comix, you cant use includes or requires after print some html code, like using print function or echo... ever you use that the code wont be perfectly runned. What do you mean by you can't use include or require after you outputted something with print and echo? Share this post Link to post Share on other sites
turbopowerdmaxsteel 0 Report post Posted December 12, 2007 Thanks but i don't fully understand the code...Would i be able to use php and mysql to set the Get code?Where would i put this?How would i extract the data at the supa comix end? Remember that in this way, you are not including the file, rather reading it from another site as an HTML.Say your news is stored in a MySQL table. Create a file http://forums.xisto.com/no_longer_exists/ that outputs this news. Now, whenever you open this URL, the recent news is echo-ed. All you need to do now is read this from the Super Comix site. The code I wrote before will do just that.You can also pass parameters to the file news.php to retrieve the news for say a specific date/topic. For example, http://forums.xisto.com/no_longer_exists/?topic=sports outputs all the sports news. To read this file, just change the GET header to: fputs($fp, "GET /news.php?topic=sports HTTP/1.1\n"); Share this post Link to post Share on other sites
Supa Comix 0 Report post Posted December 13, 2007 Right i set up the two pages. One reads the news and then uses an echo function to post it. The other links to the file but on running it just shows a black page with no source. This is the page its reading: (test.php on Gal x) <?php $sql = mysql_query("SELECT lastposter, lastposttid, lastpostsubject FROM mybb_forums WHERE fid='4'") or die("Error Line: " . mysql_error()); while ($row = mysql_fetch_array($sql)){ $lastposter = $row["lastposter"]; $lastpostid = $row["lastposttid"]; $lastpostsubject = $row["lastpostsubject"]; } echo("<font size='2'><a href='/forum/showthread.php?tid=" . $lastposttid . "'>" . $lastpostsubject . "</a></font><BR><font size='-3'>by: " . $lastposter . "</font>");?> and this is the code of the page "test2.php on the supa comix website:<?php// Open the Socket$fp = fsockopen('galx.ulmb.com;, 80);// Make the requestfputs($fp, "GET /test.php HTTP/1.1\n");fputs($fp, "Host: galx.ulmb.com, "Connection: Close\n\n"); // Send two New Lines to Signal Header End// Read the Output$readText = "";while(!feof($fp)){$readText .= fgets($fp);}// Never forget to end what you startedfclose($fp);?> Share this post Link to post Share on other sites
turbopowerdmaxsteel 0 Report post Posted December 13, 2007 All the news content is now in the $readText variable. You can do anything with it beyond the while loop (and preferably below the fclose too). Share this post Link to post Share on other sites