samg Posted July 8, 2013 Share Posted July 8, 2013 Hi, I have the "include" in my code but it errors out with "failed to open stream: HTTP request failed! " error. I already have this set in php.ini "allow_url_include = On" but it still fails. Can anybody help? Thanks Link to comment https://forums.phpfreaks.com/topic/279971-php-error-failed-to-open-stream/ Share on other sites More sharing options...
samg Posted July 8, 2013 Author Share Posted July 8, 2013 ======= Link to comment https://forums.phpfreaks.com/topic/279971-php-error-failed-to-open-stream/#findComment-1439940 Share on other sites More sharing options...
Svenskunganka Posted July 8, 2013 Share Posted July 8, 2013 Provide your code please... Link to comment https://forums.phpfreaks.com/topic/279971-php-error-failed-to-open-stream/#findComment-1439941 Share on other sites More sharing options...
Irate Posted July 8, 2013 Share Posted July 8, 2013 You are including a file from your own server, right? Otherwise, the server you're trying to send the request to might have set header('Access-Control-Access-Origin: http://owndomain.com'); so that only their own domain can send HTTP requests to their site and get responses. Just an educated guess, though. Link to comment https://forums.phpfreaks.com/topic/279971-php-error-failed-to-open-stream/#findComment-1439943 Share on other sites More sharing options...
AbraCadaver Posted July 8, 2013 Share Posted July 8, 2013 How about: allow_url_fopen Link to comment https://forums.phpfreaks.com/topic/279971-php-error-failed-to-open-stream/#findComment-1439944 Share on other sites More sharing options...
samg Posted July 8, 2013 Author Share Posted July 8, 2013 Thanks for the quick response. @Svenskunganka : I tried to post my code but it doesn't allow me . As soon as I click save, it disappears . Let me try again. @Irate: Yes I am trying to include a file on my sever itself. 1. Here is the dir structure: a) /test/foo.php --> this has include to my own server. I tried to paste the exact code but it removed it . bascially its pointing to my own server using SERVER variables pointing to "bar.php" b) /test/bar.php 2. Apache document root is pointing to "/test" like ===== /var/www/html --> /test ===== 3. echo __DIR__ shows me "/test" so its definitely pointing to the right directory. 4. I have given full permssiion to this directory, in case that's the issue but no luck. 5. Exact error in apache error log. I had to remove the exact URL as this post doesn't allow me post that. ===== [Mon Jul 08 10:41:49 2013] [error] [client ] PHP Warning: include<URL>: failed to open stream: HTTP request failed! in /test/foo.php [Mon Jul 08 10:39:49 2013] [error] [client ] PHP Warning: include(): Failed opening <URL> for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in /test/foo.php ===== Let me know if any other info is needed. Thanks Link to comment https://forums.phpfreaks.com/topic/279971-php-error-failed-to-open-stream/#findComment-1439945 Share on other sites More sharing options...
samg Posted July 8, 2013 Author Share Posted July 8, 2013 @AbraCadaver: Yep. that property is already set to "On". Link to comment https://forums.phpfreaks.com/topic/279971-php-error-failed-to-open-stream/#findComment-1439946 Share on other sites More sharing options...
AbraCadaver Posted July 8, 2013 Share Posted July 8, 2013 Why not just: include('bar.php'); Link to comment https://forums.phpfreaks.com/topic/279971-php-error-failed-to-open-stream/#findComment-1439947 Share on other sites More sharing options...
samg Posted July 8, 2013 Author Share Posted July 8, 2013 @Shawn: with that I get, No such file or directory even though "echo __DIR__" returns "test" which contains "bar.php" Link to comment https://forums.phpfreaks.com/topic/279971-php-error-failed-to-open-stream/#findComment-1439949 Share on other sites More sharing options...
samg Posted July 8, 2013 Author Share Posted July 8, 2013 I may have figured out what the problem may be. I am passing query parameters to the file in include and I guess it considers those parameters as part of file name. Do you know how I can pass query parameters in the "include"? Link to comment https://forums.phpfreaks.com/topic/279971-php-error-failed-to-open-stream/#findComment-1439951 Share on other sites More sharing options...
AbraCadaver Posted July 8, 2013 Share Posted July 8, 2013 You don't include with query parameters, just use variables: //foo.php $a = 1; include('bar.php'); //bar.php echo $a; Link to comment https://forums.phpfreaks.com/topic/279971-php-error-failed-to-open-stream/#findComment-1439952 Share on other sites More sharing options...
samg Posted July 8, 2013 Author Share Posted July 8, 2013 If I have multiple "include" for the same file with same parameters but with different values for those parameters, should I re-initialize my parameters before each include? Is that the way to go? Link to comment https://forums.phpfreaks.com/topic/279971-php-error-failed-to-open-stream/#findComment-1439957 Share on other sites More sharing options...
AbraCadaver Posted July 8, 2013 Share Posted July 8, 2013 I assume you mean multiple includes in the same file. If so, then two ways. One is what you just described, but if you use a function you only need one include: //foo.php $a=1; $b=2; include('bar.php'); $a=3; $b=4; include('bar.php'); //bar.php echo $a+$b; Or using a function: //foo.php include('bar.php'); show_addition(1, 2); show_addition(3, 4); //bar.php function show_addition($arg1, $arg2) { echo $arg1+$arg2; } Link to comment https://forums.phpfreaks.com/topic/279971-php-error-failed-to-open-stream/#findComment-1439965 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.