0

i am using the PHP function require_once to require a file:

<?php require_once 'reviewtickets_history.php?seq='.$_GET["seq"].'&type=history' ;?>

but i am getting the error:

Warning: require_once(reviewtickets_history.php?seq=34844&type=history) [function.require-once]: failed to open stream: No such file or directory in /home/user/public_html/admin/helpdesk/reviewtickets.php on line 316

but if i remove my .php file from the URL and enter in the .php page in the brackets above (reviewtickets_history.php?seq=34844&type=history) it displays fine

8
  • 2
    No you're not requiring a file, you're requiring a url: Commented Jan 3, 2014 at 22:20
  • If "URL include wrappers" are enabled in PHP, you can specify the file to be included using a URL (via HTTP or other supported wrapper - see Supported Protocols and Wrappers for a list of protocols) instead of a local pathname. If the target server interprets the target file as PHP code, variables may be passed to the included file using a URL request string as used with HTTP GET. Commented Jan 3, 2014 at 22:23
  • This is not strictly speaking the same thing as including the file and having it inherit the parent file's variable scope; the script is actually being run on the remote server and the result is then being included into the local script. Commented Jan 3, 2014 at 22:24
  • 1
    Wouldn't it be easier to link to the docs? :) Commented Jan 3, 2014 at 22:24
  • What do you exactly want to do ? Commented Jan 3, 2014 at 22:25

2 Answers 2

2

Option 1: To require a file, use local path.

require_once '/path/to/reviewtickets_history.php';

This will include the full script source, and evaluate the PHP code in your current file. You cannot pass query parameters with this method.

Option 2: To require a URL, use a full URL.

require_once 'http://mydomain.com/reviewtickets_history.php?myparam=val';

This will include the output of the script, not the PHP source. You can use query parameters here.

Note that allow_url_fopen has to be enabled for this second option to work.

Sign up to request clarification or add additional context in comments.

5 Comments

Warning: require_once(/admin/helpdesk/reviewtickets_history.php?seq=34838&type=history) same thing, it works on every other page I'm not sure what the issue could be
@charliejsford It must be a FULL url. Include http:// at the beginning, and the domain name.
allow_url_fopen is not enabled
@charliejsford Then you can't include or require a URL. Use require_once 'reviewtickets_history.php';. Realize you can't append query parameters when requiring a file like this though.
@charliejsford Show an example of exactly how you're doing it on another page. You're clearly not doing this exact same thing, or you'd get the same result.
0

in require_once need to set a path on the server to the file but not a URL. For example you can't pass http://www.example.com/somefile.php but you can do /var/www/folder/somefile.php.

In case then you

require_once 'http://mydomain.com/reviewtickets_history.php'

it will include the output and not the php functions

1 Comment

You absolutely can pass a URL, if allow_url_fopen is enabled.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.