Danut Milea
Danut Milea

Reputation: 89

include() gives [function.include]: failed to open error while trying to load another page

I'm having some trouble loading a php file in my main php file via the include() function. At first, it works ok, but afterwards it just gives the [function:include]: failed to open error.

This is where it all starts. There is a products page ("products.php") that when I click on a product link it must send the name of the file to link to (in this case "details.php") and a variable (eg. 1 or 2 or some number) so that in the end the whole url looks like "details.php?sent=2" and this url my default php page must include if it received a variable.

<?php
$received="";
$receivedlink =$_GET["sentlink"]; //this gets the file to link to name
$received =$_GET["sent"]; //this gets the other variable
print $received." ".$receivedlink; //this is for testing purposes. this shows "2 details.php". all ok here.

if ($received == "") {
    include("products.php"); //if no variable received show the first page
} else {
    print ($receivedlink."?sent=".$received); //this too is for testing purposes. this shows "details.php?sent=2". all ok here
    include($receivedlink."?sent=".$received); //this is where the error occurs
} 
?>

The else part is the one I'm having trouble with. After I click a link and all variables are sent and received and my default php page must show the details page via include() function it gives me that damn error. All files are in place. No variable is missing. All links work. Testing done with the "print" in this script shows that it is all ok.

Is there some other function I can call to load different pages when links are clicked?

Upvotes: 0

Views: 98

Answers (1)

Your Common Sense
Your Common Sense

Reputation: 157940

include (if you care to read manual page) is intended for inserting some PHP code from some file into calling script. Not for including whatever "pages".

There is NO file named details.php?sent=2 on your disk. There is a file details.php and you have to include this one.

also your code is way insecure. at least sanitize the filename with basename() function.

Upvotes: 1

Related Questions