Page 1 of 2

require_once() using a url, how do I enable it in the server

Posted: Mon Nov 24, 2014 11:36 am
by PHPHelpNeeded
Hi,

NOTE: for the domain, in this help support forum I wrote 00.00.00.00 because I dont' want to give away my ip, I hope that's ok.

But I was hoping i can get help for these two errors I am getting:

---------------------------------
[24-Nov-2014 12:23:32 America/New_York] PHP Warning: require_once(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in %WinDir%:\Eclipse_Projects\PHP_Project1\Client\Login\LoginAuth.php on line 7
[24-Nov-2014 12:23:32 America/New_York] PHP Warning: require_once(http://00.00.00.00/Server/Libraries/ServerPackage.php): failed to open stream: no suitable wrapper could be found in %WinDir%\Eclipse_Projects\PHP_Project1\Client\Login\LoginAuth.php on line 7
--------------------------------

I was trying to use a require_once with an URL but it says that I need to enable that at the server.

I am using IIS, is it referring to IIS as the server or what?

Re: require_once() using a url, how do I enable it in the se

Posted: Mon Nov 24, 2014 12:11 pm
by Celauran
http://php.net/manual/en/function.include.php
I was trying to use a require_once with an URL
As the error suggests, you can enable this behaviour by changing allow_url_fopen and allow_url_include. However, this is a bad, bad, bad idea. Why are you doing it this way? What is the goal here?

Re: require_once() using a url, how do I enable it in the se

Posted: Mon Nov 24, 2014 1:14 pm
by PHPHelpNeeded
Celauran wrote:http://php.net/manual/en/function.include.php
However, this is a bad, bad, bad idea. Why are you doing it this way? What is the goal here?
I am running iis, and therefore, the PHP server is not located at another computer that is not my server computer (which is my desktop), therefore, if I try to include or require the file from the root directory, it will not find it, for example, If I were to run the php file at another computer like laptop or from another computer not connect to the private network.

Any ideas as to how I can do this?

Re: require_once() using a url, how do I enable it in the se

Posted: Mon Nov 24, 2014 1:35 pm
by Celauran
If I were to run the php file at another computer like laptop or from another computer not connect to the private network.
You can't. The PHP file needs to be run on the same machine as the web server, and that needs to be accessible across the network.

Re: require_once() using a url, how do I enable it in the se

Posted: Mon Nov 24, 2014 1:49 pm
by PHPHelpNeeded
Celauran wrote:You can't. The PHP file needs to be run on the same machine as the web server, and that needs to be accessible across the network.
Ok you mean, the web server has to be accessed across the network?

How do you do that with IIS?

Re: require_once() using a url, how do I enable it in the se

Posted: Mon Nov 24, 2014 3:11 pm
by Celauran
If it's working locally, it should already be listening on port 80. Just point your browser to the correct IP or set up a rule in your hosts file to resolve it by domain name.

Re: require_once() using a url, how do I enable it in the se

Posted: Mon Nov 24, 2014 6:04 pm
by PHPHelpNeeded
Celauran wrote:If it's working locally, it should already be listening on port 80. Just point your browser to the correct IP or set up a rule in your hosts file to resolve it by domain name.
I am using the correct IP...you might not be seeing the IP that I am using cause I omitted it out to post this forum question, but I personally know that I am using the correct PUBLIC ip address.

When you say "set up a rule in your hosts file to resolve it by domain name." Do you mean to add a BINDING on the IIS website to resolve the host to the PUBLIC IP?

Let me try that in the mean time....

UPDATE: in case you were referring to adding a binding to resolve to the public ip, it didn't work, now I get this error message:

Code: Select all

          [24-Nov-2014 19:06:13 America/New_York] PHP Fatal error:  Class 'Hello' not found in %WinDir%\Eclipse_Projects\PHP_Project1\Client\Login\LoginAuth.php on line 9
UPDATE: So some part of it is working, but now classes I have defined inside the file serverpackage.php which is the one being require_once() inside LoginAuth.php are NOT being found.

So what's wrong now

Re: require_once() using a url, how do I enable it in the se

Posted: Mon Nov 24, 2014 7:20 pm
by Celauran
I wasn't referring to public IPs at all. I assumed this was being accessed over a private network. Shouldn't matter much either way. That you're getting errors at all looks like progress. What's line 9 of LoginAuth.php? What's this serverpackage.php you mentioned?

Re: require_once() using a url, how do I enable it in the se

Posted: Tue Nov 25, 2014 4:36 am
by PHPHelpNeeded
Celauran wrote:I wasn't referring to public IPs at all. I assumed this was being accessed over a private network. Shouldn't matter much either way. That you're getting errors at all looks like progress. What's line 9 of LoginAuth.php? What's this serverpackage.php you mentioned?
LoginAuth.php => this file will be my login authentication page, for instance, that's where users will log in and for my current situation, since I am testing whether I can include() a library through a URL. The file looks like this:

Code: Select all

             <?php
                           require_once "http://my public IP/server/libraries/ServerPackage.php";

                           Echo Hello::HelloWorld("My Name");

               ?>

The error on Line 9, it is referring to the Class Hello which It is found in ServerPackage.php, that error is saying that class is not found.

ServerPackage.php => this file will be a library of functions and classes I will want to include(), and it looks like this:

Code: Select all

             <?php
                           class Hello {
                                      public static function HelloWorld($name){
                                                    return "Hello World Mr. {$name}";
                                      }
                            }
               ?>

Let me know if you find the reason why I am getting that error.

Re: require_once() using a url, how do I enable it in the se

Posted: Tue Nov 25, 2014 5:56 am
by Celauran
Since LoginAuth and ServerPackage are on the same machine, you should be able to require them via file path, but that's just an aside. require_once seems to be working as it throws a fatal error otherwise. Based on the code you've posted, I see no reason this wouldn't work. Is this the entirety of both files?

Re: require_once() using a url, how do I enable it in the se

Posted: Tue Nov 25, 2014 6:00 am
by PHPHelpNeeded
Celauran wrote:Since LoginAuth and ServerPackage are on the same machine, you should be able to require them via file path, but that's just an aside. require_once seems to be working as it throws a fatal error otherwise. Based on the code you've posted, I see no reason this wouldn't work. Is this the entirety of both files?

Yes, this is exactly what you see in each entire file...I got nothing else.

But even when I run the require_once("http://url") in the same machine of the web server, I still get that fatal error that says, CLASS NOT FOUND.

So I am puzzled, is like the allow_url_enable seems to be working, but the content of the file being included() is being restricted.

Re: require_once() using a url, how do I enable it in the se

Posted: Tue Nov 25, 2014 6:02 am
by Celauran
Have you tried using require by file path instead?

Re: require_once() using a url, how do I enable it in the se

Posted: Tue Nov 25, 2014 9:07 am
by PHPHelpNeeded
Celauran wrote:Have you tried using require by file path instead?
I understand that the file can be acquired through file path.

Anyway, my purpose is not to access the file through file path because as a website, it will be hosted from my desktop and be accessed from other computers outside the network.

Other outside computers cannot access the file through file path because it will not be found in those outside computers.

I think I have mentioned this.

Re: require_once() using a url, how do I enable it in the se

Posted: Tue Nov 25, 2014 9:43 am
by Celauran
You have, and your understanding appears to be flawed. Other computers will not be accessing those files directly. Their access is restricted to what is exposed by the web server. PHP is all processed server side and only the results are sent to the client. Thus, it is not the client requesting those files directly, but PHP itself.

Re: require_once() using a url, how do I enable it in the se

Posted: Tue Nov 25, 2014 9:51 am
by PHPHelpNeeded
Celauran wrote:You have, and your understanding appears to be flawed. Other computers will not be accessing those files directly. Their access is restricted to what is exposed by the web server. PHP is all processed server side and only the results are sent to the client. Thus, it is not the client requesting those files directly, but PHP itself.
are you saying I have to enabled or UNrestrict something in IIS in order to fix this? Or are you saying this is completely impossible?

If it is completely impossible, then I will have to ask a different question as to how I can perform what I want to do, with a different approach.

Let me know if you want me to explain what I want to perform, I need to get an answer from this...my personal problem with PHP is that I am not very familiar with how things work. Sometimes I find myself typing some concept that would work in Java but are not reliable or does not work with PHP. Though Java and PHP tend to be similar.