Page 1 of 1

How can stop some link working on a page if user click witho

Posted: Sun Aug 26, 2012 3:57 am
by vishalonne
After lots of home work I came here for support and help.
http://www.cbsecsnip.in 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

Code: Select all

<?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

Code: Select all

<?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';
}
?>

Re: How can stop some link working on a page if user click w

Posted: Sun Aug 26, 2012 11:04 am
by social_experiment

Code: Select all

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
The notices you are receiving is because HOST, USER, PASSWORD, DATABASE aren't defined anywhere, or if they are they cannot be accessed by your page. Where do you define these values?

Code: Select all

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
This is because of the incorrect login details.

Code: Select all

Fatal error: Call to undefined function sec_session_start() in C:\xampp\htdocs\secure\XICS.php on line 94
The function is called but isn't defined.

Re: How can stop some link working on a page if user click w

Posted: Sun Aug 26, 2012 10:59 pm
by califdon
You have defined those constants in process_login.php, but unless that script is included in XICS.PHP, those constants will be unknown in other scripts. You should also be careful about using uppercase letters in filenames because Linux is case-sensitive and you are apt to forget when something should be uppercase or lowercase.

Re: How can stop some link working on a page if user click w

Posted: Sat Feb 09, 2013 10:35 am
by amrizkhan
Because you didn't include your functions.php in your page.