0

I have the following php code:

<?php
session_start();

if (isset($_SESSION['email']) && $_SESSION['email'] == true) {
  echo "&nbsp You logged in as ", $_SESSION['email'];
 echo "<br/>&nbsp<a href='logout.php'>logout</a>";
} else {
    header('Location: login.php');
}
?>

This is a code for welcome and logout for logged in users but this is showing like both side by side. I need to align echo "&nbsp You logged in as ", $_SESSION['email']; to left and echo "<br/>&nbsp<a href='logout.php'>logout</a>" to right. How can I do this using html?

4
  • actually it appears on the top of the page . currently its not inside html. Commented Jun 2, 2018 at 7:17
  • Add it in html and add required styles to it Commented Jun 2, 2018 at 7:18
  • If you want nobreakable spaces you should use &nbsp; instead of &nbsp Commented Jun 2, 2018 at 7:19
  • can you share working demo? Commented Jun 2, 2018 at 7:41

1 Answer 1

1

Put them both in divs like

echo "<div class='div-left'> You logged in as " . $_SESSION['email'] . "</div>";
 echo "<div class='div-right'><a href='logout.php'>logout</a></div>";

Then style the divs using css so that one floats right and the other left.

Sign up to request clarification or add additional context in comments.

4 Comments

Parse error: syntax error, unexpected 'float' (T_STRING), expecting ',' or ';' in C:\xampp\htdocs\nurse\index.php on line 6
@ZubairNazerOliyat sorry I’ve edited the answer it should work now.
@ZubairNazerOliyat retype the double quotes at the end of line 1 around </div> I can’t type them properly on mobile
Replace those with ' and with ". I edited the code for you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.