Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Include Blocks Cookie?

Status
Not open for further replies.

Actorial

Programmer
Aug 23, 2006
38
US
Hello,

I'm trying to check if a user is logged in. I'm using this

if (isset($_COOKIE['name'])) {
echo 'something';
}

It works fine in the one file. However when I put this another file and include it in the first file, it doesn't work! I can't figure out why. Seems like it should be a simple fix, I just can't figure it out, any ideas?

Thanks for your help!
 
yes, I've got the <?php ?> in there. The separate php file works on it's own, just not when I include it in another file.
 
is it from another domain (albeit the same server)?
 
And the path reference is straight? The path reference (if applicable) between the "php" and the "include"?
 
not from another domain. the included file (logo.php) has regular html in it, then

Code:
<?php if (isset($_COOKIE['name'])) {
echo 'something';
}

then some more html.


the include statement in the 1st file is:

Code:
<? include '[URL unfurl="true"]http://www.mysite.com/logo.php';?>[/URL]

does the html before and after have any effect on this?
 
OK I solved it! You have to make the included file a different extension because the php parsing screws up when you include a .php file. so i just changed logo.php to logo.inc, included that, and it worked! Peace I'm outta here! Thank you all for the assitance, got me thinking on the right track.
 
AFAIK, the code will get parsed if you include it via the http protocol. If this included file exists outside your server, then that's what you need to do. However, if you can include the file by simply referencing its path (the included file and the file in which you are including it lie on the same server) then you should keep the .php extension (for security purposes) and include it via the filesystem. That will also help with less overhead.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top