Php check if link has been clicked

PHP

Hi I'm a novice at php could some please help. I'm making a website it has a menu, I need it so that if a link like "link1" is clicked page1.php will load into the the mainSection div and if link2 is clicked page2.php will load in mainSection etc. so all the pages: page1, page2, page3 etc will load into this single page depending on what link has been clicked. Is this possible I don't know where to start. Thanks

    <body>
        <?php
            <ul>
                <li><a href="#" name="link1">link 1</a></li>
                <li><a href="#" name="link2">link 2</a></li>
                <li><a href="#" name="link3">link 3</a></li>
                <li><a href="#" name="link4">link 4</a></li>    
            </ul>
        ?>

       <div id="mainSection">
            <?php
        if (link1 == true){
             include 'page1.php';
        }
        if (link2 == true){
            include 'page2.php';
        }
        if (link3 == true){
            include 'page3.php';
        }
        if (link4 == true){
            include 'page4.php';
        }
            ?>  
        </div>
    </body>

Best Answer

Here's something you can start with

<body>
            <ul>
                <li><a href="?link=1" name="link1">link 1</a></li>
                <li><a href="?link=2" name="link2">link 2</a></li>
                <li><a href="?link=3" name="link3">link 3</a></li>
                <li><a href="?link=4" name="link4">link 4</a></li>    
            </ul>

       <div id="mainSection">
            <?php
        $link=$_GET['link'];
        if ($link == '1'){
             include 'page1.php';
        }
        if ($link == '2'){
            include 'page2.php';
        }
        if ($link == '3'){
            include 'page3.php';
        }
        if ($link == '4'){
            include 'page4.php';
        }
            ?>  
        </div>
    </body>