-2

Block of code that demonstrate the header.php

This is common and I have been googling for hours but found not many helpful answers. How would I get rid of the sign up button after user has been logged in? can we modify or chanage things outside of the php block of code?

5
  • 2
    Please post code as text, not images. Commented Mar 1, 2020 at 6:13
  • 2
    Put an if statement around the code that displays the sign up button. Commented Mar 1, 2020 at 6:14
  • Who do both the login and signup buttons both link to the same register.php script? Commented Mar 1, 2020 at 6:14
  • Does this answer your question? Conditional Statements in PHP code Between HTML Code Commented Mar 1, 2020 at 10:42
  • Barmar, we have Jquery run hide and show methods for the login form and register form respectively so you don't have to create each page for each form, maybe this is not the best way to build a website but it works though. Commented Mar 1, 2020 at 18:39

2 Answers 2

0

Try this code:

<?php 
if(!$logged_in)
{ 
   echo "<li><a href='register.php'>Sign up!</a></li>"; 
}  
?>

Change if condition based on your authentication code.

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

Comments

0

Just add another php code block around the button, and render the button conditionally. That would then execute on the server, which is likely the best.

Alternatively, client-side code can be written to achieve the same (javascript), but it would likely be more complex for you (it would potentially involve an ajax request and some js code, depending on how you deliver the rest of the page.content.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.