probably a stupid question, but i didn’t see an answer existing that solved it. (saw some that didn’t solve it).
i have a simple login script snippit that works fine using setcookie when run by itself, but when used inside a require_once, it is completely useless.
the gist of the code is this:
<several lines of HTML code first>
if(!isset($_COOKIE['MY_USER']) && isset($_POST['submit']) && <passwordmatch>) {
setcookie('MY_USER',$_POST['username'],time()+3600);
} else if(isset($_COOKIE['MY_USER'] && isset($_POST['logout'])) {
setcookie('MY_USER',$_POST['username'],time()-3600);
}
<later>
if(<logged in>) {
<code for logout>
} else {
<code for login submit>
}
all this works fine if i just run this code natively (filename ‘login.php’), but if i include the code within another file (as a sidebar
i’ve tried setting the path argument, domain argument, no luck.
other suggestions include making sure this php code is the absolute first thing in the page, which i guess precludes any use within a require_once (unless it is the first require_once). if that is the case, how do i get my preceding text in there that “sets up” the login?
any thoughts or experiences?
many thanks,
sj