Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts

    Problem with require_once

    Hi, I an having difficulty calling a script.

    I get an error saying the file is not present but when I run it from the web browswer it works fine.

    In my php script I have:
    PHP Code:
    $qrcode_script =  "/home/mobpage/public_html/qr/phpqrcode/qrcode_gen.php?size=$page_size&imagename=$qr_image_name&page=$N_page_id&data=$page_url";

    require_once(
    "$qrcode_script"); 
    Then I get this error:

    Warning: require_once(/home/mobpage/public_html/qr/phpqrcode/qrcode_gen.php?size=30&imagename=freewine_dav592_6.png&page=6&data=www.mbpg.net/coupon.php?a=6): failed to open stream: No such file or directory in /home/mobpage/public_html/write_first1.php on line 63 Fatal error: require_once(): Failed opening required '/home/mobpage/public_html/qr/phpqrcode/qrcode_gen.php?size=30&imagename=freewine_dav592_6.png&page=6&data=www.mbpg.net/coupon.php?a=6' (include_path='.:/usr/share/pear:/usr/share/php') in /home/mobpage/public_html/write_first1.php on line 63

    BUT when I run the same program in the web browser using:

    http://www.mbpg.net/qr/phpqrcode/qrc...coupon.php?a=5

    Then the script runs fine.

    So am I doing something wrong ?




    .
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #2
    rgb
    rgb is offline
    New Coder
    Join Date
    Jul 2011
    Posts
    17
    Thanks
    0
    Thanked 2 Times in 2 Posts
    I would try calling the file on a path relative to the calling file rather than an absolute path - just in case I had the absolute path wrong.

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,327
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    It's because you are opening it as a local file on the disk instead of via the webserver.

    When you open a file on the disk you can't open it using url parameters. The operating system doesn't know what they are and thinks its part fo the file name. Relative or absolute paths will make no difference.

    When you call the file via a web address (url) PHP deals with the parameters automatically and recognises the file name.
    Last edited by tangoforce; 12-16-2012 at 06:41 PM.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    This ^
    You simply cannot add a querystring to a file opened with the filesystem wrappers. You can use a querystring with file opened with url wrappers as that's processed by the server and hands the result.
    Since its local, there is no reason to provide that information in an include. Simply include the processing in and create the variables before the inclusion that it needs to make use of.

  • #5
    Regular Coder
    Join Date
    Sep 2007
    Location
    Grahamstown, South Africa
    Posts
    237
    Thanks
    6
    Thanked 17 Times in 17 Posts
    You could just change require_once to file_get_contents... That will 'call' the script like you are doing in your web browser and return the contents. This isn't strictly the correct way of doing it though.

    I think you need to go through the responses to really understand what exactly the issue actually is.

    A webserver passes get params etc in a url string. What you are doing is trying to INCLUDE a file into your script. Two completely separate concepts.

  • #6
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,327
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    Quote Originally Posted by idalatob View Post
    You could just change require_once to file_get_contents... That will 'call' the script like you are doing in your web browser and return the contents. This isn't strictly the correct way of doing it though.
    No because require / include / once can still use URLs too so that makes no difference. It's the use of url parameters in a disk based address that is the issue here.

    Quote Originally Posted by idalatob View Post
    A webserver passes get params etc in a url string. What you are doing is trying to INCLUDE a file into your script. Two completely separate concepts.
    Include or not, include does work with urls and url parameters but you can't use url parameters on a local disk based file using a disk based address. It's the same thing as using file_get_contents() - that can also read system files or remote files via url. Require and include work the same way.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •