tags:

views:

39

answers:

2

I'm trying to hide the following code listed below from members that are not logged in how can I do this? And what parts of my code do I need to change or add to it?

Here is the code I want only logged in members to see.

<div id="r">
 <h2>some thing</h2>
  <form method="post" action="index.php">
   <fieldset>
    <input type="text" size="40" class="g" name="tag" value="<?php if (isset($_POST['tag'])) echo $_POST['tag']; ?>" />
    <input type="submit" name="submit" id="submit" value="s" class="t" />
    <input type="hidden" name="submitted" value="TRUE" />
    <br />
    <span>(Some words)</span>
   </fieldset>
  </form> 
</div>
+1  A: 

it depends on how you are tracking how they are logged in. I'm assuming you have something in $_SESSION. if you, so you can just do this:

<?php if($_SESSION['logged_in']): ?> //whatever variable you use for logins.
    <div id="r">
       //your html here
    </div>
<?php endif; ?>
GSto
Ah. Looks like you beat me to it ;)
Dan Loewenherz
I tried this it didn't work, I'll give it a second try.
SlapThiS
It worked the second time wow.
SlapThiS
+1  A: 

Let's say you've stored a boolean that indicated whether someone is logged in with something like $_SESSION['loggedin']. In this case, all you really need to do is:

<?php

if ($_SESSION['loggedin']) {
  echo <<<HTML
<div id="r">
        <h2>some thing</h2>
                <form method="post" action="index.php">
                        <fieldset>
                                <input type="text" size="40" class="g" name="tag" value="<?php if (isset($_POST['tag'])) echo $_POST['tag']; ?>" />
                                <input type="submit" name="submit" id="submit" value="s" class="t" />
                                <input type="hidden" name="submitted" value="TRUE" />
                                <br />
                                <span>(Some words)</span>
                        </fieldset>
                </form> 
</div>
HTML;
}

?>
Dan Loewenherz
This messes up my HTML code :(
SlapThiS
How does it mess up your HTML code?
Dan Loewenherz
It throws off my CSS code.
SlapThiS