After lots of home work I came here for support and help.
Please see the siteClick Here on home page I have menu Computer Science and sub menu XI which open XICS.php on this page threr are few links. From those links few must work if user already logged in like (Upload, Solved Materials, Forum) else move to login page or show a message "Login Required". Here are code with which I am fighting since 2 days.
Problem is I don't want to hide entire page without login but some specific links should not work. And if come in with login then all links will work.
Right Now with following code if I try to access directly entering the url of page XICS.php Half page is displayed warnings, notices, and finally Fatal Error
Notice: Use of undefined constant HOST - assumed 'HOST' in C:\xampp\htdocs\secure\XICS.php on line 2
Notice: Use of undefined constant USER - assumed 'USER' in C:\xampp\htdocs\secure\XICS.php on line 2
Notice: Use of undefined constant PASSWORD - assumed 'PASSWORD' in C:\xampp\htdocs\secure\XICS.php on line 2
Notice: Use of undefined constant DATABASE - assumed 'DATABASE' in C:\xampp\htdocs\secure\XICS.php on line 2
Warning: mysqli::mysqli() [mysqli.mysqli]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp\htdocs\secure\XICS.php on line 2
Warning: mysqli::mysqli() [mysqli.mysqli]: [2002] php_network_getaddresses: getaddrinfo failed: No such host is known. (trying to connect via tcp://HOST:3306) in C:\xampp\htdocs\secure\XICS.php on line 2
Warning: mysqli::mysqli() [mysqli.mysqli]: (HY000/2002): php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp\htdocs\secure\XICS.php on line 2
Fatal error: Call to undefined function sec_session_start() in C:\xampp\htdocs\secure\XICS.php on line 94
XICS.PHP
<?php
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
sec_session_start(); ?>
some other HTML code lines.....
if(login_check($mysqli) == true){ ?>
<div id="nav" class="image002-03">
<span id="smalltext" style="bottom: 0px; margin-bottom: 0px; padding-bottom: 0px; font-family: Calibri; font-size: large; text-align: center;">Service Menu</span>
<ul id="ul1" class="serviceul">
<li class="serviceli"><a href="unsolvedCSQPXI.php">Unsolved Question Papers</a></li>
<li class="serviceli"><a href="unsolvedCSSPXI.php">Unsolved Sample Paper</a></li>
<li class="serviceli"><a href="#">Notes</a></li>
<li class="serviceli"><a href="prosamCSXI.php">Projects Samples</a></li>
<li class="serviceli"><a href="#">Presentations</a></li>
<li class="serviceli"><a href="#">Uploads</a></li>
<li class="serviceli"><a href="downloads.php">Solved Materials</a></li>
<li class="serviceli"><a href="forum.php">Forum</a></li>
<li class="serviceli"><a href="#">Live Chat</a></li> </ul>
</div>
<?php
}
else{ ?>
<div id="nav" class="image002-03">
<span id="smalltext"
style="bottom: 0px; margin-bottom: 0px; padding-bottom: 0px; font-family: Calibri; font-size: large; text-align: center;">Service Menu</span>
<ul id="ul1" class="serviceul">
<li class="serviceli"><a href="unsolvedCSQPXI.php">Unsolved Question Papers</a></li>
<li class="serviceli"><a href="unsolvedCSSPXI.php">Unsolved Sample Paper</a></li>
<li class="serviceli"><a href="#">Notes</a></li>
<li class="serviceli"><a href="prosamCSXI.php">Projects Samples</a></li>
<li class="serviceli"><a href="#">Presentations</a></li>
<li class="serviceli"><a href="login.php">Uploads</a></li>
<li class="serviceli"><a href="login.php">Solved Materials</a></li>
<li class="serviceli"><a href="login.php">Forum</a></li>
<li class="serviceli"><a href="#">Live Chat</a></li> </ul>
</div>
<?php } ?>
process_login.php
<?php
define("HOST", "localhost"); // The host you want to connect to.
define("USER", "root"); // The database username.
define("PASSWORD", ""); // The database password.
define("DATABASE", "check1"); // The database name.
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
echo "Process Login";
include 'functions.php';
sec_session_start(); // Our custom secure way of starting a php session.
if(isset($_POST['email'], $_POST['p'])) {
$email = $_POST['email'];
$password = $_POST['p']; // The hashed password.
if(login($email, $password, $mysqli) == true)
{
// Login success
include("XICS.php");
} else {
// Login failed
header('Location: ./login.php?error=1');
}
} else {
// The correct POST variables were not sent to this page.
echo 'Invalid Request';
}
?>