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!
You can't pass the variable like that... Try... $_REQUEST['product'] = 'Books'; include ( 'main.php' ); Amazon app? What API?
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!
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/
Hi Sarahk Thanks for your help, but I'm not sure about the code for this: "variable $product available to the next script".
or try full url: include ( 'http://...' ); should also work if url's are allowed by php configuration
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
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):
Just funny to see a kind of solid discussion here. It may be the simplest question relate to php and 3 different solutions already . P.S. I think over starting thread: what is better <?php ?> or just <? ?>
I'd use <?php every time as it's an explicit command to the server. Only takes a second longer to type.
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.
XML uses <? ?>, PHP must use <?php ?>. Though short tags will still work on PHP but its not recommended.