justAnoob Posted February 2, 2009 Share Posted February 2, 2009 Hi everyone. I am trying to hide a div until someone is authenticated on my page. This is what I have so far. Oh,, by the way, it doesn't work. LoL. <div id="admin"><img src="--------/---------.png" alt="admin" width="28" height="32" /> <?php session_start(); if(isset($_SESSION['auth'])) { echo <div id="admin">; } ?> </div> Quote Link to comment https://forums.phpfreaks.com/topic/143431-solved-echo-a-div/ Share on other sites More sharing options...
genericnumber1 Posted February 2, 2009 Share Posted February 2, 2009 You need session_start(); at the top of your page before any content is sent. Enable errors and you will see many Quote Link to comment https://forums.phpfreaks.com/topic/143431-solved-echo-a-div/#findComment-752346 Share on other sites More sharing options...
killah Posted February 2, 2009 Share Posted February 2, 2009 <?php session_start(); ?> <div id="admin"><img src="--------/---------.png" alt="admin" width="28" height="32" /> <?php session_start(); if(isset($_SESSION['auth'])) { echo '<div id="admin">'; } ?> </div> Quote Link to comment https://forums.phpfreaks.com/topic/143431-solved-echo-a-div/#findComment-752368 Share on other sites More sharing options...
justAnoob Posted February 2, 2009 Author Share Posted February 2, 2009 Thank you for the help on this. But wouldn't I also need to hide this div before I check for authentication to display it. Right now with that code, it is telling me to display the div and then if the user is authenticated, continue to display it. Right? Quote Link to comment https://forums.phpfreaks.com/topic/143431-solved-echo-a-div/#findComment-752969 Share on other sites More sharing options...
gevans Posted February 2, 2009 Share Posted February 2, 2009 <?php session_start(); if(isset($_SESSION['auth'])) { echo '<div id="admin"> <img src="--------/---------.png" alt="admin" width="28" height="32" /> </div>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/143431-solved-echo-a-div/#findComment-752974 Share on other sites More sharing options...
justAnoob Posted February 2, 2009 Author Share Posted February 2, 2009 Well gevans, I'm not sure if you were trying to tell me this, but I found something that works.(so far) I put this on the top of my page. <?php session_start(); if(isset($_SESSION['auth'])) { echo '<div id="reguser"><img src="------/------.png" alt="home" width="32" height="32" /></div>'; } ?> And then also I just positioned my div on the page where I wanted it and just kept it empty, like this <div id="reguser"></div> Maybe that is what you were explaining. Well anyways, maybe this can help someone else out in the future. Thanks again fellow PHPers. Oh yeh, the div name I changed after everything was working ok. That did not play a part with this not working, just to let everyone know. Quote Link to comment https://forums.phpfreaks.com/topic/143431-solved-echo-a-div/#findComment-753026 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.