Forum Moderators: coopster

Message Too Old, No Replies

PHP include() Parsing Issue

         

UreMaker

4:37 pm on Jul 9, 2008 (gmt 0)

10+ Year Member



I am trying to use the php include() method to read in a login box to my site. However, i want the login box to display different content if the user is already logged in. My solution to this was to have a script turn on/off the form using php included from the include file. However, when i try to include the second level, the php is simply read and is still in the source (ie. not parsed by the server) does anybody know how to get the second level pasrsing to work properly?
Thanks in advance,
maker

eelixduppy

5:01 pm on Jul 9, 2008 (gmt 0)



Welcome to WebmasterWorld! :)

In the file that isn't being parsed do you have the code surround by the PHP opening and closing tags? It should. Are you including that file as a URL (ie http://www.example.com/script.php) because then the PHP will be parsed before being sent to your script.

It shouldn't be that difficult to make what you want happen and shouldn't require so many includes. Here's an example of how I would do it:


if(#check if user is logged in#)
include('logged_in.html);
else
include('login_form.html');

UreMaker

5:33 pm on Jul 9, 2008 (gmt 0)

10+ Year Member



Thanks eelixduppy! I'll use the in-page switch for now, but i'd like to figure out why the second include wont work... I am currently including it as a url, is that not the way to do it? If not, how do I get the pages which are including it to find the second include?

eelixduppy

5:59 pm on Jul 9, 2008 (gmt 0)



By including the file as a URL the PHP gets parsed before it gets included. If the script is on your server then you should be using a relative or absolute path to the include file. Try this first and see if it fixes your problem.

UreMaker

6:01 pm on Jul 9, 2008 (gmt 0)

10+ Year Member



Super! Thanks for the help eelixduppy! works perfect now

eelixduppy

6:02 pm on Jul 9, 2008 (gmt 0)



Glad to help :)