samg Posted July 8, 2013 Share Posted July 8, 2013 (edited) 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 Edited July 8, 2013 by samg Quote Link to comment Share on other sites More sharing options...
samg Posted July 8, 2013 Author Share Posted July 8, 2013 (edited) ======= Edited July 8, 2013 by samg Quote Link to comment Share on other sites More sharing options...
Svenskunganka Posted July 8, 2013 Share Posted July 8, 2013 Provide your code please... Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted July 8, 2013 Share Posted July 8, 2013 How about: allow_url_fopen Quote Link to comment Share on other sites More sharing options...
samg Posted July 8, 2013 Author Share Posted July 8, 2013 (edited) 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 Edited July 8, 2013 by samg Quote Link to comment 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". Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted July 8, 2013 Share Posted July 8, 2013 Why not just: include('bar.php'); Quote Link to comment Share on other sites More sharing options...
samg Posted July 8, 2013 Author Share Posted July 8, 2013 (edited) @Shawn: with that I get, No such file or directory even though "echo __DIR__" returns "test" which contains "bar.php" Edited July 8, 2013 by samg Quote Link to comment Share on other sites More sharing options...
samg Posted July 8, 2013 Author Share Posted July 8, 2013 (edited) 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"? Edited July 8, 2013 by samg Quote Link to comment 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; Quote Link to comment 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? Quote Link to comment 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; } Quote Link to comment Share on other sites More sharing options...
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.