dh526 Posted May 21, 2009 Share Posted May 21, 2009 hi everyone and thank you for looking I have a login system where you enter a username and password, then if they are correct you are signed in. There is a Cookie called 'username' which holds the username from the sign in field. Is it possible to do something like this : If Cookie is set then echo "<a href='usersignedin.php'>$username</a>; else echo "<a href='login.php'>Login</a> Thank you for you help Any help would be much appreciated:) Quote Link to comment https://forums.phpfreaks.com/topic/159148-solved-cookies-and-javascript/ Share on other sites More sharing options...
jackpf Posted May 21, 2009 Share Posted May 21, 2009 Yeah. Don't know why you're wanting to do it with javascript though. Cookies are way harder to handle with js. if(isset($_COOKIE['username'])) { echo 'this cookie exists'; } Quote Link to comment https://forums.phpfreaks.com/topic/159148-solved-cookies-and-javascript/#findComment-839315 Share on other sites More sharing options...
dh526 Posted May 21, 2009 Author Share Posted May 21, 2009 So would something like this work: <?php if (isset($_COOKIE['username'])) { echo "<a href='signedin.php'>$username</a>"; } else { echo "<a href='login.html'>login</a>"; } ; ?> Ps. I'm unsure if i got the ;'s in the right place... Quote Link to comment https://forums.phpfreaks.com/topic/159148-solved-cookies-and-javascript/#findComment-839325 Share on other sites More sharing options...
dh526 Posted May 21, 2009 Author Share Posted May 21, 2009 Thanks man It works now How do I set this to resolved? Quote Link to comment https://forums.phpfreaks.com/topic/159148-solved-cookies-and-javascript/#findComment-839333 Share on other sites More sharing options...
jackpf Posted May 21, 2009 Share Posted May 21, 2009 Ahaha, I have never seen anyone use curly brackets like that before. There's a link at the bottom. Quote Link to comment https://forums.phpfreaks.com/topic/159148-solved-cookies-and-javascript/#findComment-839351 Share on other sites More sharing options...
dh526 Posted May 21, 2009 Author Share Posted May 21, 2009 <?php if (isset($_COOKIE['username'])) { echo "<a href='signedin.php'>$username</a>"; } else { echo "<a href='login.html'>login</a>"; } ?> Better lol Thanks a lot dude Quote Link to comment https://forums.phpfreaks.com/topic/159148-solved-cookies-and-javascript/#findComment-839368 Share on other sites More sharing options...
jackpf Posted May 21, 2009 Share Posted May 21, 2009 Lol yeah, nice one. Quote Link to comment https://forums.phpfreaks.com/topic/159148-solved-cookies-and-javascript/#findComment-839370 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.