ev5unleash Posted March 17, 2009 Share Posted March 17, 2009 Hi, I'm currently making a website with PHP Include so that I can easily edit it. I currently have this code to include different pages <?php include('indextop.php'); if( !isset($_GET['id']) ) { $xid = 'default'; } else { $xid = strtolower($_GET['id']); } switch($xid) { case 'default': include('indexhome.php'); break; case 'teacherlogin': include('pages/teacherresources/login.php'); break; case 'teacherauth': include('pages/teacherresources/auth.php'); break; } include('indexbottom.php'); ?> Which let's me make a certain page show when the ?id=teachlogin is shown. Now I have the part teacher auth, which leads to the php file of this code <?php if( !isset($_GET['code']) ) { $xid = 'default'; } else { $xid = strtolower($_GET['id']); } switch($xid) { case 'default': include('pages/teacherresources/loginfailed.php'); break; case 'Lnvb773c2y': include('pages/teacherresources/index.php'); break; case 'spage1': include('pagespage1.php'); break; } ?> When I try "?id=teacherauth?code=Lnvb773c2y" or "?id=teacherauth&code=Lnvb773c2y" The page other than the top and the bottom code is blank. Can anyone tell me why when I include multiple times it won't show the page that's included? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/149749-including-more-than-once-with-php/ Share on other sites More sharing options...
MadTechie Posted March 17, 2009 Share Posted March 17, 2009 auth.php is in the directory "pages/teacherresources" so you need to update the paths try this switch($xid) { case 'default': include('loginfailed.php'); break; case 'Lnvb773c2y': include('index.php'); break; case 'spage1': include('../../pagespage1.php'); break; } Quote Link to comment https://forums.phpfreaks.com/topic/149749-including-more-than-once-with-php/#findComment-786361 Share on other sites More sharing options...
ev5unleash Posted March 17, 2009 Author Share Posted March 17, 2009 Okay, I updated auth.php file so now it's <?php if( !isset($_GET['code']) ) { $xid = 'default'; } else { $xid = strtolower($_GET['id']); } switch($xid) { case 'default': include('loginfailed.php'); break; case 'Lnvb773c2y': include('index.php'); break; case 'spage1': include('../../pagespage1.php'); break; } ?> Now when I try "?id=teacherauth" I get the message Warning: include(/loginfailed.php) [function.include]: failed to open stream: No such file or directory in C:\wamp\www\websites\biologywebsite\pages\teacherresources\auth.php on line 15 Quote Link to comment https://forums.phpfreaks.com/topic/149749-including-more-than-once-with-php/#findComment-786375 Share on other sites More sharing options...
MadTechie Posted March 17, 2009 Share Posted March 17, 2009 can you provide a directory structor otherwise i am going to be guessing alot Quote Link to comment https://forums.phpfreaks.com/topic/149749-including-more-than-once-with-php/#findComment-786386 Share on other sites More sharing options...
ev5unleash Posted March 17, 2009 Author Share Posted March 17, 2009 Okay here's the root of the main file index.php (which has teacherresource and teacherauth include in it. \index.php (withholds the code below) <?php include('indextop.php'); if( !isset($_GET['id']) ) { $xid = 'default'; } else { $xid = strtolower($_GET['id']); } switch($xid) { case 'default': include('indexhome.php'); break; case 'teacherlogin': include('pages/teacherresources/login.php'); break; case 'teacherauth': include('pages/teacherresources/auth.php'); break; } include('indexbottom.php'); ?> \pages\teacherresources\auth.php (withholds the code below) <?php if( !isset($_GET['code']) ) { $xid = 'default'; } else { $xid = strtolower($_GET['id']); } switch($xid) { case 'default': include('loginfailed.php'); break; case 'Lnvb773c2y': include('index.php'); break; case 'spage1': include('../../pagespage1.php'); break; } ?> \pages\teacherresources\index.php (Shows the message when the login is successful) \pages\teacherresources\indexfailed.php (Shows the message when the login has failed) \pages\teacherresources\login.php (has the login page) will Quote Link to comment https://forums.phpfreaks.com/topic/149749-including-more-than-once-with-php/#findComment-786653 Share on other sites More sharing options...
The Little Guy Posted March 17, 2009 Share Posted March 17, 2009 <?php if( !isset($_GET['code']) ) { $xid = 'default'; } else { $xid = strtolower($_GET['id']); } switch($xid) { case 'default': include('loginfailed.php'); break; case 'Lnvb773c2y': include('index.php'); break; case 'spage1': include('../../pagespage1.php'); break; } ?> I would recommend modifying the code like this: <?php switch(strtolower($_GET['id'])) { case 'Lnvb773c2y': include('index.php'); break; case 'spage1': include('../../pagespage1.php'); break; default: include('loginfailed.php'); break; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/149749-including-more-than-once-with-php/#findComment-786656 Share on other sites More sharing options...
ev5unleash Posted March 17, 2009 Author Share Posted March 17, 2009 I'm still getting this error Warning: include(loginfailed.php) [function.include]: failed to open stream: No such file or directory in C:\wamp\www\pages\teacherresources\auth.php on line 11 Quote Link to comment https://forums.phpfreaks.com/topic/149749-including-more-than-once-with-php/#findComment-786713 Share on other sites More sharing options...
The Little Guy Posted March 17, 2009 Share Posted March 17, 2009 basically you are calling "loginfailed.php", which you are saying is located here: C:\wamp\www\pages\teacherresources\loginfailed.php Make sure you are spelling everything right, and casing is the same, because this is case sensitive. Quote Link to comment https://forums.phpfreaks.com/topic/149749-including-more-than-once-with-php/#findComment-786715 Share on other sites More sharing options...
MadTechie Posted March 17, 2009 Share Posted March 17, 2009 and casing is the same, because this is case sensitive. WAMP is not case sensitive. Also is it indexfailed.php or loginfailed.php if it's loginfailed.php when is that file ? Quote Link to comment https://forums.phpfreaks.com/topic/149749-including-more-than-once-with-php/#findComment-786732 Share on other sites More sharing options...
ev5unleash Posted March 17, 2009 Author Share Posted March 17, 2009 The code worked with the "The Little Guys" code, I was also stuck because for some reason PHP wouldn't let me link index.php for the include on the auth.php file. Thanks for pointing out the loginfailed.php error, it was indexfailed.php. Quote Link to comment https://forums.phpfreaks.com/topic/149749-including-more-than-once-with-php/#findComment-787081 Share on other sites More sharing options...
ev5unleash Posted March 17, 2009 Author Share Posted March 17, 2009 Although I marked this as topic solved I have one problem for the default code. When you submit the wrong include like ?code=sdjfh9 people get this error message. Notice: Undefined index: id in C:\wamp\www\websites\biologywebsite\pages\teacherresources\auth.php on line 10 any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/149749-including-more-than-once-with-php/#findComment-787102 Share on other sites More sharing options...
MadTechie Posted March 17, 2009 Share Posted March 17, 2009 if(isset($_GET['id'])) //add this line switch(strtolower($_GET['id'])) Quote Link to comment https://forums.phpfreaks.com/topic/149749-including-more-than-once-with-php/#findComment-787111 Share on other sites More sharing options...
ev5unleash Posted March 17, 2009 Author Share Posted March 17, 2009 The code is this now <?php if(isset($_GET['code'])) //add this line switch(strtolower($_GET['code'])) { case 'lnvb773c2y': include('indexsucessful.php'); break; default: include('indexfailed.php'); break; } ?> Now when nothing is put in for the code it's blank and does not point to the login failed page. Although, now it does when a wrong include is put in with no error. Quote Link to comment https://forums.phpfreaks.com/topic/149749-including-more-than-once-with-php/#findComment-787115 Share on other sites More sharing options...
ev5unleash Posted March 17, 2009 Author Share Posted March 17, 2009 I mean when you put ?id=teachauth you get a blank screen instead of the indexfailed.php. Quote Link to comment https://forums.phpfreaks.com/topic/149749-including-more-than-once-with-php/#findComment-787146 Share on other sites More sharing options...
POG1 Posted March 17, 2009 Share Posted March 17, 2009 Validate the code a bit nicer $page = (isset($_GET['code']) AND ctype_alnum($_GET['code'])) ? strtolower($_GET['code']) : 'default' ; switch($page) { Quote Link to comment https://forums.phpfreaks.com/topic/149749-including-more-than-once-with-php/#findComment-787155 Share on other sites More sharing options...
ev5unleash Posted March 17, 2009 Author Share Posted March 17, 2009 I'm still running into a similar problem. Now when a wrong code is inserted I get a blank response not the indexfailed.php Quote Link to comment https://forums.phpfreaks.com/topic/149749-including-more-than-once-with-php/#findComment-787171 Share on other sites More sharing options...
ev5unleash Posted March 17, 2009 Author Share Posted March 17, 2009 Never mind, It seems to work now. Quote Link to comment https://forums.phpfreaks.com/topic/149749-including-more-than-once-with-php/#findComment-787176 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.