Hello I am really new to coding in general but I got the basics of what I need.
I have my index.html that contains this:
<!-- Navigation -->
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li class="hidden">
<a href="#page-top"></a>
</li>
<li class="page-scroll">
<a href="#portfolio">Portfolio</a>
</li>
<li id="navbutone" class="page-scroll">
<a href="login.php">Login</a>
</li>
<li id="navbuttwo" class="page-scroll">
<a href="register.php">Register</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
keep in mind I got this from a website template that I am editing so I didn't come up with this layout
and I have a php file that has some html in it to try and replace the contents of the list when this part of the code is run:
<?php
if($login_ok)
{
?>
<script type="text/javascript">
function logedin() {
document.getElementById("one").innerHTML = "<a href="logout.php">Logout</a>";
}
</script>
<script type="text/javascript">
logedin();
</script>
<?php
header("Location: index.html");
die("Redirecting to: private.php");
}
?>
This doesn't work and I have no idea if this is even close or not. Thanks in advance for the help. also I might add that they link to login.php where they login through an html form at the bottom of the php.
?>
<h1>Login</h1>
<form action="login.php" method="post">
Username:<br />
<input type="text" name="username" value="<?php echo $submitted_username; ?>" />
<br /><br />
Password:<br />
<input type="password" name="password" value="" />
<br /><br />
<input type="submit" value="Login" />
</form>
<a href="register.php">Register</a>
<script src="index.html"></script>
</html>
Update: I found what I needed instead of messing with the php file i just put this into my index.html were the links will change out:
<?php
require("common.php");
if(empty($_SESSION['user']))
{
?>
<li class="page-scroll">
<a href="login.php">Login</a>
</li>
<li class="page-scroll">
<a href="register.php">Register</a>
</li>
<?php
}
else
{
?>
<li class="page-scroll">
<a href="logout.php">Logout</a>
</li>
<li class="page-scroll">
<a href="private.php">Members Page</a>
</li>
<?php
}
?>
were common.php just connects to my database.
header("Location: index.html")) after outputting anything (including the Javascript before it). It would be better for you to read some PHP tutorials (like the one @floor mentioned) and learn, first of all, how this stuff works. Resuming: 1) PHP processes data (for example, login data) and outputs HTML (usually) according to it. 2) HTML and Javascript get to the user's browser. 3) The Javascript is executed locally in the user's browser (there's no server processing at this point, including session check).