Darkmatter5 Posted July 8, 2008 Share Posted July 8, 2008 Here's my code <?php ob_start(); session_start(); $page=$_GET['page']; if(session_is_registered('member_id')) { include '$page'; } else { header("Location: index.php"); } ob_end_flush(); ?> If I have this code <a href='checkLogin.php?page=res_admin.php'>SITE ADMIN</a> in a page and I put an echo of $page in the top code. res_admin.php is outputted. So why am I getting the following error with the code as is? ERROR Warning: include() [function.include]: Failed opening '' for inclusion (include_path='.;C:\php5\pear') in C:\wamp\www\ecabinet\checkLogin.php on line 7 Link to comment https://forums.phpfreaks.com/topic/113812-question-on-include-command/ Share on other sites More sharing options...
lemmin Posted July 8, 2008 Share Posted July 8, 2008 "Be sure to have an appropriate include_path setting as well" From php.net! http://www.php.net/manual/en/ini.core.php#ini.include-path Link to comment https://forums.phpfreaks.com/topic/113812-question-on-include-command/#findComment-584849 Share on other sites More sharing options...
wildteen88 Posted July 8, 2008 Share Posted July 8, 2008 Do not use variables within single quotes. PHP will treat variables as normal text within single quotes. Put simply remove the quotes. Also do not use session_is_registered or session_register functions, they are depreciated. A replacement for session_is_registered is isset($_SESSION['your_variable']) Link to comment https://forums.phpfreaks.com/topic/113812-question-on-include-command/#findComment-584851 Share on other sites More sharing options...
Darkmatter5 Posted July 8, 2008 Author Share Posted July 8, 2008 So it should be isset($_SESSION['member_id']) instead? Link to comment https://forums.phpfreaks.com/topic/113812-question-on-include-command/#findComment-584854 Share on other sites More sharing options...
wildteen88 Posted July 8, 2008 Share Posted July 8, 2008 Yes, still go to be in the if statement though: if(isset($_SESSION['member_id'])) { Link to comment https://forums.phpfreaks.com/topic/113812-question-on-include-command/#findComment-584858 Share on other sites More sharing options...
Darkmatter5 Posted July 8, 2008 Author Share Posted July 8, 2008 I don't want to go about adding this one directory to the include path, so can't I make $page="C:\wamp\www\project\"; and then append $_GET['page'] onto the end of $page? Is that is possible, what is the syntax? Link to comment https://forums.phpfreaks.com/topic/113812-question-on-include-command/#findComment-584859 Share on other sites More sharing options...
wildteen88 Posted July 8, 2008 Share Posted July 8, 2008 Yes, look into the concatenation operator. Link to comment https://forums.phpfreaks.com/topic/113812-question-on-include-command/#findComment-584860 Share on other sites More sharing options...
Darkmatter5 Posted July 8, 2008 Author Share Posted July 8, 2008 Okay one last question I think. I've found that if I do $pagepath = "C:\wamp\www\project"; $page = $pagepath . $_GET['page'])); echo $page; The "\" in $pagepath aren't recognized. If I try "/" php takes it, but reports it can't find the path as it's now using "/" instead of "\" when going to a directory, so how can I get around this? Link to comment https://forums.phpfreaks.com/topic/113812-question-on-include-command/#findComment-584866 Share on other sites More sharing options...
wildteen88 Posted July 8, 2008 Share Posted July 8, 2008 PHP sees a \ as an escape character. When using \ in a file path do \\ instead. You can use / in file paths too. Examples: $path = "C:\\wamp\\www\\project\\"; $page = $path . $_GET['page']; // OR $path = "C:/wamp/www/project/"; $page = $path . $_GET['page']; Link to comment https://forums.phpfreaks.com/topic/113812-question-on-include-command/#findComment-584869 Share on other sites More sharing options...
Darkmatter5 Posted July 9, 2008 Author Share Posted July 9, 2008 No matter what I do I can't get the res_admin.php file to include. I've added C:\wamp\www\project to my php.ini file, still nothing. I've tried <?php ob_start(); session_start(); $page = $_GET['page']; $path = "C:\\wamp\\www\\ecabinet\\"; $pathpage = $path . $page; if(isset($_SESSION['member_id'])) { include $pathpage; } else { header("Location: index.php"); } ob_end_flush(); ?> Still nothing. Always the same error a listed in my original post on this topic. Anyone know what's going on? Am I going about protecting my pages completely the wrong way? Link to comment https://forums.phpfreaks.com/topic/113812-question-on-include-command/#findComment-584929 Share on other sites More sharing options...
wildteen88 Posted July 9, 2008 Share Posted July 9, 2008 What happens when you echo $pagepath? Also do not modify the include_path directive, always it leave as default. Post the error message in full here (i know you posted it before, but it may have changed since). I cannot see why the above code is not working. Link to comment https://forums.phpfreaks.com/topic/113812-question-on-include-command/#findComment-585647 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.