djbadger Posted January 23, 2007 Share Posted January 23, 2007 Hi. This is confusing me! Im not a PHP expert by any means, but I am picking things up as I learn. So please bare with me here...I have a website portal page, that I designed myself in PHP. I have purposely made all the different elements of the site (latest forum posts, random gallery pic, random quote, etc) INCLUDES on this page to keep it all neat and tidy. This also allows me to make tweaks to each module without messing with the main portal page.At the top of the INDEX.PHP, I include the SSI.PHP from my SMF Forum so that I can use its FUNCTIONS on the portal page. Then I include the HEADER.PHP, which puts up my nice graphics and uses one of the SSI fuctions (a login box)....this is where my problems begin...Because im including the HEADER.PHP, it doesnt seem to understand the FUNCTIONS that the SSI.PHP had declared moments before. If I add the little code snippet that calls for the SSI function directly to the INDEX.PHP, then it works a treat, but NOT if its in the included header file.Why is that?I would love to just include the SSI.PHP once, and use its functions all the way down my portal page, regardless of wether its directly, or within something included further down.Is it not possible to include a file that declares a bunch of functions on your index page, and then use those functions on files included later down the page?Thanks!DJB Link to comment https://forums.phpfreaks.com/topic/35350-confusion-over-functions-and-includes/ Share on other sites More sharing options...
Cep Posted January 23, 2007 Share Posted January 23, 2007 I am not entirely sure what you mean by your header.php not understanding the functions in SSI.php.Basically you can daisy chain php files together with the use of include and require but I don't think you can use "include" for a page twice.So if php 1 has an include to php 2 and php 3. If php 3 has an include to php 2 you will get an error.I would suggest that if your functions are necessary for your site to run you use "require" instead of "include" and as you may be doing this all over the place use "require_once" instead. Link to comment https://forums.phpfreaks.com/topic/35350-confusion-over-functions-and-includes/#findComment-167079 Share on other sites More sharing options...
djbadger Posted January 23, 2007 Author Share Posted January 23, 2007 Hi CEP, thanks for replying!I will try and explain a bit better...I have the INDEX.PHP file which first calls the SSI.PHP, and then the HEADER.PHP.I use REQUIRE for the SSI.PHP, and INCLUDE for the HEADER.PHP.If I call any of the functions declared in the SSI.PHP from INDEX.PHP, they work perfectly. However, if I put the exact same function call in the HEADER.PHP, it does not.Its acting much like the SSI.PHP include is 'disconnecting' before the header has a chance to utilise it. I know that is a silly thing to say of course, but thats what it feels like.Does that make the issue any clearer?Thanks,DJB Link to comment https://forums.phpfreaks.com/topic/35350-confusion-over-functions-and-includes/#findComment-167096 Share on other sites More sharing options...
Nelak Posted January 23, 2007 Share Posted January 23, 2007 call the ssi file in the header, u should still be able to use them on the index page Link to comment https://forums.phpfreaks.com/topic/35350-confusion-over-functions-and-includes/#findComment-167098 Share on other sites More sharing options...
djbadger Posted January 23, 2007 Author Share Posted January 23, 2007 Yeah, I thought that too but it doesnt seem to work like that.In my entire portal page, I include about 5 modules, 2 of which need functions from the SSI, as well as a tiny function call at the bottom of the page too.If I stick the SSI include in the INDEX.PHP then the later includes cant find the functions, but the little call at the bottom of the page works fine. If I then stick the SSI include in the HEADER instead, it works for all the calls in the header, but for none of the others further down the page...See how im getting confused? LOLDJB Link to comment https://forums.phpfreaks.com/topic/35350-confusion-over-functions-and-includes/#findComment-167133 Share on other sites More sharing options...
Cep Posted January 23, 2007 Share Posted January 23, 2007 I would do this then,index.php[code=php:0]require_once "./ssi.php";include_once "./header.php";[/code]Then in header.php[code=php:0]require_once "./ssi.php";[/code]Remember to put these at the top of your scripts (after any session_start() ). Link to comment https://forums.phpfreaks.com/topic/35350-confusion-over-functions-and-includes/#findComment-167205 Share on other sites More sharing options...
djbadger Posted January 24, 2007 Author Share Posted January 24, 2007 I will try that. Thanks.Question: You mention putting the include before any sessions that might be starting.. Well the SSI.PHP is a file that links to my SMF Forum, and pulls data from that. I believe that it uses the SMF session (perhaps a cookie) to gain data on who is logged on etc. Would that complicate matters?DJB Link to comment https://forums.phpfreaks.com/topic/35350-confusion-over-functions-and-includes/#findComment-167922 Share on other sites More sharing options...
Cep Posted January 24, 2007 Share Posted January 24, 2007 No it shouldn't really be a problem but you have to remember that session_start() must precede any header output, which is why as a rule of thumb I would place it on the first line of any script that requires it. Link to comment https://forums.phpfreaks.com/topic/35350-confusion-over-functions-and-includes/#findComment-167932 Share on other sites More sharing options...
djbadger Posted January 24, 2007 Author Share Posted January 24, 2007 Right, I made those changes to my page. It does seem to do the job in respect to using the supplied functions, but the function doesnt seem to be working properly.The 'login' function is telling me there is nobody logged in to my forum, despite the fact that I am.I would expect I would need to post on the SMF Forums for answers about questions about their SSI.PHP and the sessions it creates wouldnt I.Thanks for all your help here guys!DJB Link to comment https://forums.phpfreaks.com/topic/35350-confusion-over-functions-and-includes/#findComment-167938 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.