I'm trying to make an "asp.net site.Master" functional page with PHP using URL params to show or hide content in the page but it looks like only one of the params is working.
Code here:
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>System</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark sticky-top">
<a runat="server" class="navbar-brand" href="~/Default">LOGO</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarText">
<ul class="nav navbar-nav">
<li><a class="nav-link" href="index.php?index=one">one</a></li>
<li><a class="nav-link" href="index.php?index=two">two</a></li>
</ul>
</div>
</nav>
<?php $mypage = isset($_GET['index']);
switch ($mypage) {
case "one":
@include("./one.php");
break;
case "two":
@include("./two.php");
break;
}
?>
</body>
</html>
Doesn't matter which option I click on the navbar because it always shows me the "one" option.
Pages "one" and "two" are just an empty html with "one" and "two"
I'm sorry if I'm not as descriptive as it should, it's my first time asking here.
Thx!
The issue is here:
$mypage = isset($_GET['index']);
You just check if $_GET
contains a field "index".
$mypage = isset($_GET["index"]) ? $_GET["index"] : "one";
This will use the given site and fall back to page one when the index is not given in the GET parameter.
Further, try to avoid the error control operator @
.
$mypage = isset($_GET['index']) ? $_GET["index"] : "one";
switch($mypage)
{
case "one":
include("./one.php");
break;
case "two":
include("./two.php");
break;
}