hello guys,
this probably is a easy problem for you guys to solve but i’ve tried for over a week now and tried to find solution via google and youtube but i can’t make it right. it’s a school project where one have to code a website with a login and only logged in users are allowed to comment the contents.
the problem:
Fatal error: Call to undefined function session_is_registered() in /Applications/XAMPP/xamppfiles/htdocs/tastyrecipes/index.php on line 64
i just want the index to show “welcome Guest” if not logged in and "Welcome ‘username’ " if you are logged in.
the index.php
[php]
<?php session_start(); ?><html>
<head>
<title>Tasty Recipes</title>
<link href="css/layout.css" rel="stylesheet">
<link href="css/ddmenu.css" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" type="text/css" href="css/login_style.css"/>
<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript" src="/js/script.js"></script>
<script type="text/javascript" src="comment_insert.js"></script>
<script type="text/javascript" src="ddmenu.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="wrapper">
<nav id="ddmenu">
<ul>
<li class="no-sub"><div class="top-heading">Home</div></li>
<li class="no-sub">
<a class="top-heading" href="calendar.php">Calendar</a>
</li>
<li>
<a class="top-heading">Recipes</a>
<i class="caret"></i>
<div class="dropdown">
<div class="dd-inner">
<div class="column">
<a href="pancakes.php">Pancakes</a>
<a href="meatballs.php">Swedish Meatballs</a>
</div>
</div>
</div>
</li>
<li>
<span class="top-heading">Contact</span>
<i class="caret"></i>
<div class="dropdown right-aligned">
<div class="dd-inner">
<div class="column">
<a href="about_us.php">About Us</a>
<a href="contact_us.php">Contact Us</a>
</div>
</div>
</div>
</li>
</ul>
</nav>
<div class ="page">
<div class="big-image">
<img src="images/Chicken.jpg" alt="Chicken" class="image"/>
</div>
<div>
<h2 class="page-title">
TASTY RECIPES
</h2>
</div>
<div class="page-data">
<div id="main-wrapper">
<center>
<?php
if(!session_is_registered(myusername)) {
echo 'welcome guest';
}
else {
echo 'welcome $myusername';
}
?>
</center>
<div id="login-wrapper">
<form>
<ul>
<li class="buttons">
<input type="button" name="login" value="Log In" onclick="location.href = 'login.php'"/>
<br><a href="register.php" title="register">register</a>
</li>
</ul>
</form>
</div>
</div>
</div>
</div>
<div class="footer">
Designed by Taiyou La | W3C Validated
</div>
</div>
</body>
[/php]
and the login.php code:
[php]<?php
$host = “localhost”; // Host name
$username = “root”; // Mysql username
$password = “”; // Mysql password
$db_name = “testing”; // Database name
$tbl_name = “members”; // Table name
// Connect to server and select databse.
mysql_connect("$host", “$username”, “$password”) or die(“cannot connect”);
mysql_select_db("$db_name") or die(“cannot select DB”);
// username and password sent from form
$myusername = $_POST[‘myusername’];
$mypassword = $_POST[‘mypassword’];
// To protect MySQL injection
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql = “SELECT * FROM $tbl_name WHERE username = ‘$myusername’ and password = ‘$mypassword’”;
$result = mysql_query($sql);
// Mysql_num_row is counting table row
$count = mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count == 1) {
// Register $myusername, $mypassword and redirect to file “index.php”, i think the problem lies somewhere here.
session_register(“myusername”);
session_register(“mypassword”);
echo ’';
}
echo ’';
?>[/php]