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 8 of 8
  1. #1
    New Coder
    Join Date
    Dec 2007
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts

    error include url

    i have two problem with url in my code . Example :
    Code:
    <?PHP if (empty($_GET[page])) $_GET[page] = home; include "$svr_rootself/$_GET[page].php"; ?>
    with this method my url is www.mysite.com/?page=example&ex=2&exe=3 . ( example=example.php in server root and worked 100&#37; ) now when change manually url to ?page=example.php i have two error .
    Code:
    Warning: include(htdocs/site/example.php.php) [function.include]: failed to open stream: No such file or directory in htdocs\site\index.php on line 49
    
    Warning: include() [function.include]: Failed opening 'htdocs/site/detail.php.php' for inclusion (include_path='.;\php\pear\') in site\index.php on line 49
    how to fix this error ? regards
    Last edited by eric float; 07-22-2008 at 07:09 AM.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Code:
    include "$svr_rootself/$_GET[page].php";
    The above code assumes $_GET[page] contains the name of the file and no extension.
    So would include
    Code:
    include "$svr_rootself/example.php";
    and
    Code:
    ?page=example.php
    would try to include example.php.php, which may not be available. However ?page=example this should work.

    PS: $_GET['page'] is the proper way to access global array variables.
    You need to add a code to check whether the file is actually present in that directory (file_exists()). Otherwise a request like ?page=blah will always give an error
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    Dec 2007
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts
    any idea for fix this error ??

  • #4
    Regular Coder mic2100's Avatar
    Join Date
    Feb 2006
    Location
    Scunthorpe
    Posts
    562
    Thanks
    15
    Thanked 28 Times in 27 Posts
    try this and show me ur results

    PHP Code:
    <?PHP if (empty($_GET[page])) $_GET[page] = home; include $svr_rootself."/".$_GET[page]; ?>

  • #5
    New Coder
    Join Date
    Dec 2007
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts
    no ! not worked this code .

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    The error indicates that you cannot find the file, or that the file cannot be read. Make sure that the file exists in the location its seeking, and that you're server has read access to the file. Abdura already mentioned about the ?page=example.php, which is also what you're error shows: Failed opening 'htdocs/site/detail.php.php'. Don't worry about the two errors, they both equate to one problem. The set to $_GET[page] = home; should also be $_GET['page'] = 'home';, since home refers to a constant while 'home' refers to a string. I would debug like so:
    PHP Code:
    <?php

    if (!isset($_GET['page']) || empty($_GET['page']))
    {
        
    $_GET['page'] = 'home';
    }

    $fileSeek $svr_rootself '/' $_GET['page'] .  '.php';
    printf("File '%s' exists? %s\n"$fileSeek, (file_exists($fileSeek)) ? 'yes' 'no');
    printf("File '%s' is readable? %s\n"$fileSeek, (is_readable($fileSeek)) ? 'yes' 'no');
    include 
    $fileSeek;
    If either of those say 'no', you've got a problem with either no file, or being unable to read the file. If the file is there, chmod or chown the file if you're on linux, manually assign on windows.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #7
    New Coder
    Join Date
    Dec 2007
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts
    my idea is : when page=example to page=example.php direct page to any page for error ! so example : mysite.com/index.php?page=example.php direct to mysite.com/anypage.php ( YOUR PAGE NOT Exit ) or any text error .

    Quote Originally Posted by Fou-Lu View Post
    The error indicates that you cannot find the file, or that the file cannot be read. Make sure that the file exists in the location its seeking, and that you're server has read access to the file. Abdura already mentioned about the ?page=example.php, which is also what you're error shows: Failed opening 'htdocs/site/detail.php.php'. Don't worry about the two errors, they both equate to one problem. The set to $_GET[page] = home; should also be $_GET['page'] = 'home';, since home refers to a constant while 'home' refers to a string. I would debug like so:
    PHP Code:
    <?php

    if (!isset($_GET['page']) || empty($_GET['page']))
    {
        
    $_GET['page'] = 'home';
    }

    $fileSeek $svr_rootself '/' $_GET['page'] .  '.php';
    printf("File '%s' exists? %s\n"$fileSeek, (file_exists($fileSeek)) ? 'yes' 'no');
    printf("File '%s' is readable? %s\n"$fileSeek, (is_readable($fileSeek)) ? 'yes' 'no');
    include 
    $fileSeek;
    If either of those say 'no', you've got a problem with either no file, or being unable to read the file. If the file is there, chmod or chown the file if you're on linux, manually assign on windows.
    Fou-Lu Your code not worked . thanks
    Last edited by eric float; 07-23-2008 at 12:06 PM.

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    I understand what you are trying to do. What does the output for the above debugging produce, is it yes or no?

    Edit:
    I didn't say my code would work. I said thats how I would debug it. Remember, we're here to help you, not fix you're code for you.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

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