Trying to include file in .php file:
<?php
$lesson = $_GET["lesson"];
include_once($lesson + "_title.php");
?>
But for some reason I keep getting this error:
Warning: include_once(0): failed to open stream: No such file or directory in C:\xampp\htdocs\Periodic Tutor\layout.php on line 10
Warning: include_once(): Failed opening '0' for inclusion (include_path='.;\xampp\php\PEAR') in C:\xampp\htdocs\Periodic Tutor\layout.php on line 10
It keeps showing that the file doesn't exist, yet it does. I have done an echo statement to check the arguments being passed to the include function and the string is correct.
I am using XAMPP as my testing server and Dreamweaver, but PHP url variables and include/require statements have never been a problem before.
Any suggestions? Thanks!
When concatenating a string, you use "." not "+". include_once($lesson."_title.php");
Keep in mind that including things that way is a bit dangerous as people could use absolute paths in $_GET["lesson"] to include things that could be private.
In this line:
include_once($lesson + "_title.php");
You're arithmetically adding the two terms, which gives a result of zero.
Do this:
include_once($lesson . "_title.php");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.