Search code examples
phpmethodsget

PHP Get Methods


is it possible to make

header("location: ../../index.php?page=account?msg=changesuccess");

so I want 2 messages. 1. is page=account and in index.php it does:

elseif($page == "account"){
    require_once("frontend/pages/accountsettings/account.php");
}
  1. message is, once I open account.php from above, msg=changesuccess

Solution

  • Assuming you're setting $page with

    $page = $_GET['page'];
    

    You just need to change the query string in your URL to add the msg parameter properly.

    header("location: ../../index.php?page=account&msg=changesuccess");
    

    Then you can get it from $_GET as well. Since you're using require_once to load account.php, any variables in index.php will be available in account.php as well.

    // ...
    
    elseif($page == "account"){
        $message = $_GET['msg'];
        require_once("frontend/pages/accountsettings/account.php");
        //account.php will have access to $message
    }
    

    You don't really need to create another variable, because account.php will also be able to access $_GET directly, but I just wanted to show that anything in index.php will be in scope in account.php as well.