-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?

Barmar
  • 741,623
  • 53
  • 500
  • 612
Alvis Luu
  • 25
  • 4
  • 2
    Please post code as text, not images. – Barmar Mar 01 '20 at 06:13
  • 2
    Put an `if` statement around the code that displays the sign up button. – Barmar Mar 01 '20 at 06:14
  • Who do both the login and signup buttons both link to the same `register.php` script? – Barmar Mar 01 '20 at 06:14
  • Does this answer your question? [Conditional Statements in PHP code Between HTML Code](https://stackoverflow.com/questions/3812526/conditional-statements-in-php-code-between-html-code) – rene Mar 01 '20 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. – Alvis Luu Mar 01 '20 at 18:39

2 Answers2

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.

Hari Lubovac
  • 622
  • 4
  • 14
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.

RBT
  • 24,161
  • 21
  • 159
  • 240
Rudra
  • 704
  • 8
  • 16