PHP include error ?

Discussion in 'PHP' started by adwordguru, Jun 19, 2006.

  1. #1
    I have this error when implementing this:
    "failed to open stream: No such file or directory"

    include ( 'main.php?product=books' );


    But when I link it, is OK:

    <a href='main.php?product=books'>Books</a><br>

    Anyone any idea ?
    Thanks!
     
    adwordguru, Jun 19, 2006 IP
  2. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #2
    You can't pass the variable like that...

    Try...

    $_REQUEST['product'] = 'Books';
    include ( 'main.php' );

    Amazon app? What API?
     
    noppid, Jun 19, 2006 IP
  3. sarahk

    sarahk iTamer Staff

    Messages:
    28,828
    Likes Received:
    4,541
    Best Answers:
    123
    Trophy Points:
    665
    #3
    When you open a page you are doing it from the browser, ie clientside and certain translations happen

    When you include a file you're doing it back on the server. A ? means nothing in this context and you need to be pointing to the right location on the server.

    To have the variable $product available to the next script just create it, and it's there like magic

    And when you include main.php make sure you have the path right

    good luck!
     
    sarahk, Jun 19, 2006 IP
  4. sarahk

    sarahk iTamer Staff

    Messages:
    28,828
    Likes Received:
    4,541
    Best Answers:
    123
    Trophy Points:
    665
    #4
    Noppid, what are you on about? But so long as we're talking amazon, check out the search tool on my blog... http://www.itamer.com/sunsilk/284/
     
    sarahk, Jun 19, 2006 IP
  5. adwordguru

    adwordguru Peon

    Messages:
    470
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hi Sarahk

    Thanks for your help, but I'm not sure about the code for this:
    "variable $product available to the next script".
     
    adwordguru, Jun 19, 2006 IP
  6. yugu

    yugu Peon

    Messages:
    98
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    or try full url:
    include ( 'http://...' );
    should also work if url's are allowed by php configuration
     
    yugu, Jun 20, 2006 IP
  7. sarahk

    sarahk iTamer Staff

    Messages:
    28,828
    Likes Received:
    4,541
    Best Answers:
    123
    Trophy Points:
    665
    #7
    I wouldn't recommend that.

    Important scripts should be held in a secure location not accessible by http://
    We all break that rule, constantly, but it's what we should be doing.
    http://www.itamer.com/secure-file-locations/72/

    noppid's method is best
     
    sarahk, Jun 20, 2006 IP
    Chemo likes this.
  8. prch

    prch Peon

    Messages:
    11
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    If it is include, variable will pass on. Just create the variable before the include.

    if(isset($some_action)) {
    $product = "books";
    include("main.php");
    }
    Code (markup):
     
    prch, Jun 23, 2006 IP
  9. yugu

    yugu Peon

    Messages:
    98
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    :D Just funny to see a kind of solid discussion here.
    It may be the simplest question relate to php and 3 different solutions already:D .
    P.S. I think over starting thread:
    what is better <?php ?> or just <? ?>:D
     
    yugu, Jun 24, 2006 IP
  10. sarahk

    sarahk iTamer Staff

    Messages:
    28,828
    Likes Received:
    4,541
    Best Answers:
    123
    Trophy Points:
    665
    #10
    I'd use <?php every time as it's an explicit command to the server. Only takes a second longer to type.
     
    sarahk, Jun 24, 2006 IP
  11. sllik

    sllik Active Member

    Messages:
    419
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #11
    I use <? ?> in all of my scripts... I really don't see a problem with it, especially since all of my sites are on a privately owned server that I configured.
     
    sllik, Jun 24, 2006 IP
  12. daworm

    daworm Peon

    Messages:
    121
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    XML uses <? ?>, PHP must use <?php ?>. Though short tags will still work on PHP but its not recommended.
     
    daworm, Jun 25, 2006 IP
  13. yugu

    yugu Peon

    Messages:
    98
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Anybody using ASP <%...%> wrappers in PHP? :)
     
    yugu, Jun 26, 2006 IP
  14. sarahk

    sarahk iTamer Staff

    Messages:
    28,828
    Likes Received:
    4,541
    Best Answers:
    123
    Trophy Points:
    665
    #14
    No. Makes no sense.
     
    sarahk, Jun 26, 2006 IP