PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
akslayde
Forum Newbie
Posts: 2 Joined: Tue Mar 03, 2015 9:35 pm
Post
by akslayde » Tue Mar 03, 2015 9:42 pm
Allright, so, I am trying to develop a login system for a site I want to launch. However, I keep having issues. The code I am having an issue with, is:
Code: Select all
<?php
session_start();
$toplinks = "";
if (isset($_SESSION['id'])) {
$userid = $_SESSION['id'];
$username = $_SESSION['username'];
$toplinks = '<a href="member_profile.php?id=' . $userid . '">' . $username . '</a> •
<a href="member_account.php">Account</a> •
<a href="logout.php">Log Out</a>';
} else {
$toplinks = '<a href="join_form.php">Register</a> • <a href="login.php">Login</a>';
}
?>
When I load the page, it spits this out:
. $username . ' • Account' • Log Out'; } else { $toplinks = 'Register • Login'; } ?>
Im not sure what to do.
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Wed Mar 04, 2015 6:21 am
I don't see anything wrong with that code in and of itself -- it's working fine for me -- but I also don't see where you're echoing it out.
akslayde
Forum Newbie
Posts: 2 Joined: Tue Mar 03, 2015 9:35 pm
Post
by akslayde » Wed Mar 04, 2015 9:18 am
Ah my apologies, here is the entire segment containing that php script as well as where its echoed.
Code: Select all
<?php
session_start();
$toplinks = "";
if (isset($_SESSION['id'])) {
// Put stored session variables into local php variable
$userid = $_SESSION['id'];
$username = $_SESSION['username'];
$toplinks = '<a href="member_profile.php?id=' . $userid . '">' . $username . '</a> •
<a href="member_account.php">Account</a> •
<a href="logout.php">Log Out</a>';
} else {
$toplinks = '<a href="join_form.php">Register</a> • <a href="login.php">Login</a>';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Nightsky Test Template</title>
<meta name="description"
content="free website template">
<meta name="keywords"
content="enter your keywords here">
<meta http-equiv="content-type"
content="text/html; charset=utf-8">
<link rel="stylesheet"
type="text/css" href="css/style.css">
<script type="text/javascript"
src="js/jquery.min.js"></script>
<script type="text/javascript"
src="js/jquery.easing.min.js"></script>
<script type="text/javascript"
src="js/jquery.nivo.slider.pack.js"></script>
<script type="text/javascript">
$(window).load(function() {
$('#slider').nivoSlider();
});
</script>
</head>
<body>
<table
style="background-color: rgb(204, 204, 204);" border="0"
cellpadding="12" width="100%">
<tbody>
<tr>
<td width="78%">
<h1>My
Logo Image</h1>
</td>
<td width="22%"><?php echo $toplinks; ?></td>
</tr>
</tbody>
</table>