'how to remove a function once called in php

I have a login form and a registration form in my index.php when user open the page it shows the login page it works fine but when i click "registr now" i need to remove the login form from the page i need login to disappaer and registration to apperar

The code

function loginForm(){
    echo
    '<div class="loginform-first">
    <p>Username and Password to continue</p>
    <form class="formq" action="index.php" method="post" autocomplete="off">
      <label for="name">Name </label>
      <input type="text" name="name" id="name" autocomplete="off"/>
      <label for="password">Password </label>
      <input type="password" name="password" id="name" autocomplete="off"/>
      <input type="submit" name="enter" id="enter" value="Enter" />
      <p>Not a User ?.<a href="index.php?register=true">Register now</a></p>
    </form>
  </div>';
}

function register(){
    echo
    '<div class="loginform-first">
    <p>registration</p>
    <form class="formq" action="index.php" method="post" autocomplete="off">
      <label for="name">Name </label>
      <input type="text" name="name" id="name" autocomplete="off"/>
      <label for="password">Password </label>
      <input type="password" name="password" id="name" autocomplete="off"/>
      <input type="submit" name="enter" id="enter" value="Enter" />
      <p>Not a User ?.<a href="index.php?register=true">Register now</a></p>
    </form>
  </div>';
}


?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
 
        <title>Chat</title>
        <meta name="description" content="Allyouwant chat place" />
        <meta content="width=device-width, initial-scale=1" name="viewport" />
        <link rel="stylesheet" href="style.css" />
    </head>
    <body>
    <?php
    if(isset($_GET['register'])) {
        register();
    }

    if(!isset($_SESSION['username'])){
        loginForm();
    }
    else {
    ?>
        <div id="wrapper">
            <div id="menu">
                <p class="welcome">Welcome, <b><?php echo $_SESSION['username']; ?></b></p>
                <p class="logout"><a id="exit" href="#">Leave Chat</a></p>
            </div>
php


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source