|
|
|
|
![]() ![]() |
Dec 10 2007, 12:24 PM
Post
#1
|
|
|
Newbie [ Level 2 ] Group: Members Posts: 24 Joined: 9-August 07 Member No.: 23,954 |
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 CODE <?php print "Initiating Test...<BR>"; include "http://www.supacomix.co.uk/test2.php"; print "<BR>...test complete."; ?> test2.php This page is at www.supacomix.co.uk CODE <?php echo "<P>Hello World</P>"; ?> Yet when i run test.php all i get is: Initiating Test... ...test complete. Does anyone know why? |
|
|
|
Dec 10 2007, 02:40 PM
Post
#2
|
|
|
Premium Member Group: [HOSTED] Posts: 373 Joined: 16-February 06 From: Kolkata, India Member No.: 11,322 |
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://mysite.com/myfile.php?name=max' will try to include the file myfile.php?name=max and not myfile.php.
|
|
|
|
Dec 10 2007, 06:30 PM
Post
#3
|
|
|
the Q Group: [HOSTED] Posts: 1,022 Joined: 13-July 05 From: Lithuania, Vilnius Member No.: 7,059 |
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 |
|
|
|
Dec 10 2007, 09:59 PM
Post
#4
|
|
|
Newbie [ Level 2 ] Group: Members Posts: 24 Joined: 9-August 07 Member No.: 23,954 |
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? |
|
|
|
Dec 11 2007, 04:05 AM
Post
#5
|
|
|
the Q Group: [HOSTED] Posts: 1,022 Joined: 13-July 05 From: Lithuania, Vilnius Member No.: 7,059 |
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 |
|
|
|
Dec 11 2007, 08:34 AM
Post
#6
|
|
|
Newbie [ Level 2 ] Group: Members Posts: 24 Joined: 9-August 07 Member No.: 23,954 |
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 www.supacomix.co.uk and the other at www.galx.ulmb.com. 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. This post has been edited by Supa Comix: Dec 11 2007, 08:38 AM |
|
|
|
Dec 11 2007, 12:50 PM
Post
#7
|
|
|
Premium Member Group: [HOSTED] Posts: 373 Joined: 16-February 06 From: Kolkata, India Member No.: 11,322 |
That doesn't sound too difficult. On the Gal X forum, create a PHP file, say http://www.galx.ulmb.com/news.php 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:-
CODE GET /news.php HTTP/1.1 Host: www.galx.ulmb.com Connection: Close Use the fputs function to send this request to www.galx.ulmb.com 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:- CODE // Open the Socket
$fp = fsockopen('www.galx.ulmb.com', 80); // Make the request fputs($fp, "GET /news.php HTTP/1.1\n"); fputs($fp, "Host: www.galx.ulmb.com\n"); fputs($fp, "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 started fclose($fp); |
|
|
|
Dec 11 2007, 03:29 PM
Post
#8
|
|
|
Newbie [ Level 2 ] Group: Members Posts: 24 Joined: 9-August 07 Member No.: 23,954 |
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? |
|
|
|
Dec 11 2007, 08:52 PM
Post
#9
|
|
|
Member - Active Contributor Group: [HOSTED] Posts: 78 Joined: 29-June 07 Member No.: 23,027 |
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. |
|
|
|
Dec 12 2007, 06:07 AM
Post
#10
|
|
|
the Q Group: [HOSTED] Posts: 1,022 Joined: 13-July 05 From: Lithuania, Vilnius Member No.: 7,059 |
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? |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 7th September 2008 - 11:56 PM |