How do I get this to work in an include?
<? if (isset($_COOKIE['agent'])){ print (":: <a href=\"http://www.agenturl.com\">Agents</a>"); } else { echo (""); } ?>
How does it not work?
I can not get the include to follow the instructions. I even tried to just ECHO the cookie value in the include (footer navigation bar) but NOTHING - however if I echo the cookie value on the actual page (above the include() line) I see the cookie value so I know the cookie is set...
first of all you should use [man]array_key_exists[/man] not isset, second of all what's the value of the variable?
Hi,
this should work. Is there more code in the include ? Did you check that the file gets included at all by e.g. echoing just something inside the include like echo "file included";
Put ini_set("error_reporting",E_ALL); on top of the script that includes the file to see if anything might be wrong.
Thomas
$agent = yes
if you are trying to use the value from one file in another include file, doesnt the variable have to be declared a global?
Here is the original code
<p>© 2004 Site.com All Rights Reserved </p> <p><a href="http://www.Site.com/" target="blank">Web site Management</a> :: <a href="http://www.Site.com/partners/">Partner Links </a>:: <a href="http://www.Site.com/sitemap.php">Site Map</a> :: <a href="http://www.Site.com/privacy.php">Privacy</a> :: <a href="http://www.Site.comp">Professional Fees</a> :: <a href="http://www.Site.com/terms.php">Terms & Condtions</a> <!-- Only write this if we are an agent --> <? if (isset($COOKIE['agent'])){ print (":: <a href=\"http://www.Site.com/agents\">Agents</a>"); } else { echo (""); } ?>
Ok,
let's print the cookie array to test which data it contains:
<p>© 2004 Site.com All Rights Reserved </p> <p><a href="http://www.Site.com/" target="_blank">Web site Management</a> :: <a href="http://www.Site.com/partners/">Partner Links </a>:: <a href="http://www.Site.com/sitemap.php">Site Map</a> :: <a href="http://www.Site.com/privacy.php">Privacy</a> :: <a href="http://www.Site.comp">Professional Fees</a> :: <a href="http://www.Site.com/terms.php">Terms & Condtions</a> <!-- Only write this if we are an agent --> <?PHP print_r($_COOKIE); if (isset($_COOKIE['agent'])){ echo ":: <a href=\"http://www.Site.com/agents\">Agents</a>"; } } ?>
OK I put an example page up here
Perhaps this will shed some light...
can we see the source of the include file as well please?
try to include the file not using a complete url (might not be allowed because of allow_url_fopen not being set to true in php.ini) but rather the relative path like e.g.
include "files/footbar.php";
Edit: No ... I think you can't use urls with include at all ...
Its there now..
(sorry)
try to include the file not using a complete url (might not be allowed because of allow_url_fopen not being set to true in php.ini) but rather the relative path like...
OK that worked...
The reason I was using [url]http://www....was[/url] because I was using a "blank" page as a makeshift template file....with all the basics in it that I wanted and then have the URLs work no matter where the page was saved...thought it would save me a step or 2...guess that didn't work....
Thanks for the help!
OK so here is an interesting problem --->
The cookie will only work in the AGENT folder and below but not in any of the files in the root (Agent is in the root) or in any folders below the root that ARE NOT in AGENT.
Make any sense?
try to specify the path with setcookie like e.g.
setcookie("agent","yes",time()+3600,"/");
Delete the cookie(s) and try it with this code.
That works like a charm!
Danke sehr!