When I use session_start() in my code i have the session setup properly and when I run the code and log in it keeps me logged in and everything works properly, but when I add HTML underneath the PHP code located at the top of the page and refresh it (while logged in) it logged me out?
My Code Without HTML
Core file
ob_start();
session_start();
function loggedin() {
if(isset($_SESSION['user_id'])&&!empty($_SESSION['user_id'])) {
return true;
} else {
return false;
}
}
require 'connect.inc.php';
require 'core.php';
include 'main_login.inc.php';
if (loggedin()) {
$dir = $user_name;
if($handle = #opendir($dir)) {
if($handle2 = #opendir($dir.'/docs')){
//If Logged In And Users File Exists: Load Page
}
} else {
// If Users File Does Not Exist: Create User File
#mkdir($user_name, 0755, true);
// Create Docs
#mkdir($user_name.'/docs', 0755, true);
}
} else {
// If User Is Not Logged: Redirect To Jamie Co Home
#header('Location: http://www.jamieco.ca');
}
?>
My code with HTML (Non-working code)
<?php
require_once 'connect.inc.php';
require_once 'core.php';
include 'main_login.inc.php';
if (loggedin()) {
$dir = $user_name;
if($handle = #opendir($dir)) {
if($handle2 = #opendir($dir.'/docs')){
//If Logged In And Users File Exists: Load Page
}
} else {
// If Users File Does Not Exist: Create User File
#mkdir($user_name, 0755, true);
// Create Docs
#mkdir($user_name.'/docs', 0755, true);
}
} else {
// If User Is Not Logged: Redirect To Jamie Co Home
#header('Location: #');
}
?>
<!DOCTYPE html>
<html>
<body>
<header>
<nav>
<ul>
<li>Home</li>
<li>Clients</li>
<li>Sign In</li>
<li>Contact</li>
</ul>
</nav>
</header>
<div id = "clear" />
<div id = "big_wrapper">
<div id = "wrapper">
<br><br>
<!-- Logged In Stuff Goes Here -->
<div id = "user_options">
<ul>
<li><?php echo 'Welcome, '.$first_name.' '.$last_name.'<br><br>'; ?></li>
<li>Logout</li>
</ul>
</div>
<?php echo 'Welcome Back '.$first_name; ?>
<br><br>
<table border = "1" cellspacing = "5" id = "files">
<tr><td colspan = "7">File Handling</td></tr>
<tr>
<td>File Name:</td>
<td>File Size:</td>
<td>File Type:</td>
<td>Security Level:</td>
<td colspan = "3">Actions:</td>
</tr>
<?php
$dir = $user_name.'/docs/';
if($handle = #opendir($dir)) {
while($file = #readdir($handle)) {
if($file!='.'&&$file!='..') {
echo '<tr><td>'.$file.'</td>';
$name = $dir.$file;
$size = filesize($dir.$file);
$type = substr($name, strrpos($name, '.')+1);
echo '<td>'.$size.' Bytes'.'</td>';
echo '<td>'.$type.'</td>';
echo '<td>'.$file_grade.'</td>';
echo '<td>'.'Download'.'</td>';
echo '<td>'.'Rename'.'</td>';
echo '<td>'.'Delete'.'</td>';
}
}
}
?>
</tr>
</table>
<br><br>
<!-- Stuff Here -->
<br><br>
</div>
</div>
</body>
</html>
Problem Solved. I changed the session to a token, not sure why this works but it does!
Related
UPDATED: I have a variable in PHP mailuid that I want to show in my HTML. It displays the error the value of mailuid is undefined on the webpage. How can I show the value of height to html page?
index.php
<?php
require "header.php";
?>
<main>
<link rel="stylesheet" type="text/css" href="styl.css">
<div class="wrapper-main">
<section class="section-default">
<h2><?php echo "$mailuid" ?></h2>
<?php
?>
</section>
</div>
</main>
<?php
require "footer.php";
?>
loginbackend.php
<?php
if(isset($_POST['login-submit'])) {
require 'db.php';
$mailuid = $_POST['mailuid'];
$password = $_POST['pwd'];
if (empty($mailuid) || empty($password)) {
header("Location: ./index.php?error=emptyfields");
exit();
} else {
$sql = "SELECT * FROM users WHERE uidUsers=? OR emailUsers=?;";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: ./index.php?error=sqlerror");
exit();
} else {
mysqli_stmt_bind_param($stmt, "ss", $mailuid, $mailuid);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if ($row = mysqli_fetch_assoc($result)) {
$pwdCheck = password_verify($password, $row['pwdUsers']);
if($pwdCheck == false) {
header("Location: ./index.php?error=wrongpwd");
exit();
} else if ($pwdCheck == true) {
session_start();
$_SESSION['userId'] = $row['idUsers'];
$_SESSION['userUid'] = $row['uidUsers'];
$username = substr($mailuid, 0, strpos($mailuid, "#"));
header("Location: ./index.php?login=success".$username);
exit();
} else {
header("Location: ./index.php?error=wrongpwd");
exit();
}
} else {
header("Location: ./index.php?error=nouser");
exit();
}
}
}
} else {
header("Location: ./signup.php");
exit();
}
As per your latest comment:
To get the mailuid from the URL (GET parameters) add the following code to your index.php
<?PHP
require "header.php";
$mailuid = !empty($_GET['mailuid']) ? $_GET['mailuid'] : null;
// You can also specify the default value to be used instead of `null` if the `mailuid` is not specified in the URL.
?>
<main>
<link rel="stylesheet" type="text/css" href="styl.css">
<div class="wrapper-main">
<section class="section-default">
<h2><?php echo "$mailuid"?></h2>
</section>
</div>
</main>
<?php
require "footer.php";
?>
From PHP7 you can use
$mailuid = $_GET['mailuid'] ?? null;
instead of
$mailuid = !empty($_GET['mailuid']) ? $_GET['mailuid'] : null;
The mistake you've made:
I think you're confusing forms and file including with how post works.
Let me explain:
A form sends data to the server, which is then pushed into the $_POST global variable. You can read this data and use this data easily by echoing or dumping it.
This is what you should do:
In this case, your data value will be empty as you're not passing anything to it.
You can solve this by creating a form and passing it to your PHP file.
You can also just require your php script.
Normally you would put data.php in your action, but since you wish to use the variable before you entered the form, you have to include it first.
index.html
<?php require 'data.php'; ?>
<form method="POST" action="">
<h1>Height: <?=$height?></h1>
<input type="text" placeholder="Enter the height..." name="height">
<input type="submit" name="submit" value="Submit">
</form>
data.php
<?php
if (!empty($_POST)) {
$height = $_POST['height'];
} else {
$height = 0; //Default height
}
My apologies if i didn't get your question properly.
===========================================
Option B, if this is what you mean, is just doing this:
index.html
<body>
<div class="container">
<?php
require 'data.php'; //Get the data.php file so we can use the contents
?>
<h1><?php echo $height; ?></h1>
</div>
</body>
data.php
<?php
$height = 100; //Height variable
Edit: Forgot to mention none of the SQL works at all when it fails.
I seriously need help figuring this out. It has been about a month since the issue has arrived. I have rewrote the page a couple times and have tried removing some unneeded items in case it was a speed issue (had sidebar that auto scrolled and loaded in two social media widgets which was kinda slow on bad internet) and so far nothing. I really do not know why this happens at all.
Here is the kicker. It only happens to random people. Never breaks for me but breaks nearly every time for a customer on certain pc's. Another issue that person is running into is the cart cookie won't clear for that person either(just them).
I am Using Auth.net's DPM method which takes them offsite momentarily then to my Order_receipt page(the one in question). When arriving at that page you are given 2 $_GET properties example (order_receipt.php?response_code=1&transaction_id=136434353) which is coming in properly even when it fails.
Customer that has issue is using win 10, and has tried it with both chrome and edge running kaspersky antivirus (no issues on my end from either browser)
I'm going to include all code loaded and included in that page below, starting with the order_receipt itself.
** = redacted info
Order_receipt.php:
<?php
require_once 'system/init.php';
include 'includes/head.php';
include 'includes/navigation.php';
include 'includes/headerpartial.php';
?>
<div id="maincontent" class="col-md-12">
<?php
ini_set('error_reporting', -1); ini_set('display_errors', 'on');
ini_set('log_errors', 1);
ini_set('error_log', 'system/error_logs.log');
$error_code = uniqid(mt_rand(), true);
if ($_GET['response_code'] == 1)
{
$trans_id = $_GET['transaction_id'];
if (isset($cart_id)){
$db->query("UPDATE transactions SET charge_id = '$trans_id' WHERE cart_id = '$cart_id'");
$tsql = $db->query("SELECT * FROM transactions WHERE cart_id = '$cart_id' ");
$tran = mysqli_fetch_assoc($tsql);
?>
<h1 id="reciept">Thank you for your support!</h1><hr>
<p id="reciept">
On behalf of ** <?=$tran['full_name']?> we thank you for your purchase and hope you enjoy it!
</p>
<p id="reciept">
You have selected <b>"<?=$tran['pickup-location']?>"</b> as your pickup point.
</p>
<table id="nav-button" class="table table-bordered table-auto">
<tbody>
<tr>
<td>Transaction ID : <?=$tran['charge_id']?></td>
</tr>
<?php
$a = 1;
$it = 1;
$string = $tran['items'];
$itemar = explode(',', $string);
$num = 1;
$istr = $tran['inventory'];
$stri = explode(',', $istr);
if ($tran['status'] != "Complete") {
foreach (array_slice($stri, $num) as $inve ){
$exploded = explode('.', $inve);
$itname = $exploded['0'];
$itquan = $exploded['1'];
$db->query("UPDATE products SET `quantity` = `quantity` - '$itquan' WHERE title = '$itname'");
$db->query("UPDATE products SET `Sold` = `Sold` + '$itquan' WHERE title = '$itname'");
$it++;
}
$compl = "Complete";
$db->query("UPDATE transactions SET `status` = '$compl' WHERE cart_id = '$cart_id'");
}
foreach (array_slice($itemar, $num) as $itemr ){
?>
<tr>
<td><?=$itemr?></td>
</tr>
<?php
$a++;
} ?>
<tr>
<td>
Total: <?=money($tran['grand_total']);?>
</td>
</tr>
</tbody>
</table>
<?php
$domain = '.'.$_SERVER['HTTP_HOST'];
setcookie(CART_COOKIE,'',1,"/",$domain,false);
}else{echo "Cart Id not Set";}
}else
{
echo "Sorry, an error occurred: ".htmlentities($_GET['response_reason_text']);
}?>
</div>
<?php
include 'includes/footer.php';
?>
Init.php:
<?php
$db = mysqli_connect("**","**","**","**");
if(mysqli_connect_errno()){
echo 'Database connection failed with following errors: '. mysqli_connect_error();
die();
}
session_start();
require_once $_SERVER['DOCUMENT_ROOT'].'/config.php';
require_once BASEURL.'helpers/helpers.php';
$cart_id = '';
if(isset($_COOKIE[CART_COOKIE])){
$cart_id = sanitize($_COOKIE[CART_COOKIE]);
}
if (isset($_SESSION['LHUser'])) {
$user_id = $_SESSION['LHUser'];
$query = $db->query("SELECT * FROM users WHERE id = '$user_id'");
$user_data = mysqli_fetch_assoc($query);
$fn = explode(' ', $user_data['full_name']);
$user_data['first'] = $fn[0];
$user_data['last'] = $fn[1];
}
if (isset($_SESSION['success_flash'])) {
echo '<div class="bg-success"><p class="text-success text-center">'.$_SESSION['success_flash'].'</p></div>';
unset($_SESSION['success_flash']);
}
if (isset($_SESSION['error_flash'])) {
echo '<div class="bg-danger"><p class="text-danger text-center">'.$_SESSION['error_flash'].'</p></div>';
unset($_SESSION['error_flash']);
}
?>
config.php:
<?php
define('BASEURL', $_SERVER['DOCUMENT_ROOT'].'/');
define('CART_COOKIE','Sd4CqdgRt6J3gd3F7');
define('CART_COOKIE_EXPIRE', time() + (86400 * 30));
?>
helpers.php:
<?php
ob_start();
function display_errors($errors){
$display = '<ul class="bg-danger">';
foreach ($errors as $error) {
$display .= '<li class="text-danger">'.$error.'</li>';
}
$display .= '</ul>';
return $display;
}
function sanitize($dirty){
return htmlentities($dirty,ENT_QUOTES,"UTF-8");
}
function money($number){
return '$'.number_format($number,2);
}
function login($user_id){
$_SESSION['LHUser'] = $user_id;
global $db;
$date = date("Y-m-d H:i:s");
$db->query("UPDATE users SET last_login = '$date' WHERE id = '$user_id'");
$_SESSION['success_flash'] = 'You are now logged in!';
header('Location: index.php');
}
function is_logged_in(){
if (isset($_SESSION['LHUser']) && $_SESSION['LHUser'] > 0) {
return true;
}
return false;
}
function login_error_redirect($url = 'login.php'){
$_SESSION['error_flash'] = 'You must be logged in to access that page';
header('Location:'.$url);
}
function permission_error_redirect($url = 'login.php'){
$_SESSION['error_flash'] = 'You don\'t have permission to access that page';
header('Location:'.$url);
}
function has_permission($permission = 'admin'){
global $user_data;
$permissions = explode(',', $user_data['permissions']);
if (in_array($permission,$permissions,true)) {
return true;
}
return false;
}
function get_category($child_id){
global $db;
$id = sanitize($child_id);
$sql = "SELECT p.id AS 'pid', p.category AS 'parent', c.id AS 'cid', c.category AS 'child'
FROM categories c
INNER JOIN categories p
ON c.parent = p.id
WHERE c.id = '$id'";
$query = $db->query($sql);
$category = mysqli_fetch_assoc($query);
return $category;
}
head.php:
<!DOCTYPE html>
<html>
<head>
<title>LettuceHeads</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/main.css">
<link rel="icon" href="../images/header/logoicon.png">
<meta name="Viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script SRC="js/bootstrap.min.js"></script>
</head>
<body>
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.6";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
navigation.php:
<?php
$sql = "SELECT * FROM navigation ORDER BY `navigation`.`sort` ASC";
$pquery = $db->query($sql);
?>
<nav id="navbar" class="navbar navbar-default navbar-fixed-top" role="navigation">
<div id="navtext" class="containter">
<a id="navborder" href="index.php" class="navbar-brand">**</a>
<ul class="nav navbar-nav">
<?php while($parent = mysqli_fetch_assoc($pquery)) : ?>
<li id="navborder"><?=$parent['name'];?></li>
<?php endwhile; ?>
</li>
</ul>
<ul id="navright" class="nav navbar-nav navbar-right" >
<li id="navborder2"><span class = "glyphicon glyphicon-shopping-cart"></span> My Cart</li>
<?php if(has_permission('admin')): ?>
<li id="navborder">Staff</li>
<?php endif; ?>
</ul>
</div>
</nav>
headerpartial.php:
<div id="partialHeaderWrapper">
<div id="partialbackitem"></div>
<div id="partiallogotext"></div>
<div id="partialfore-item"></div>
</div>
<div class="container-fluid">
footer.php:
I uploaded my php application using Filezilla and when I checked it online, all of the images are missing and total site get break. I don't understand this because everything works fine offline but when I check through after publishing it online, all the images disapear. I also checked all my links and they're fine.
Here is my code
<html>
<head>
<title> Vatsal Technosoft Messanger </title>
<script type="text/javascript" src="../JavaScript/frmvalidation.js"></script>
<link href="../Stylesheet/style.css" media="all" type="text/css" rel="stylesheet" />
</head>
<body>
<?php include 'connect.php' ?>
<?php include 'functions.php' ?>
<?php include 'header.php' ?>
<div id="outer" style="margin-top:0px;">
<div class="container" style="color:#00C; z-index:1;">
<div class="subcontainer" >
<?php
if(loggedin())
{
?>
<a href='' onclick='addcontact();' id='noti' style='text- decoration:none;margin-bottom:0px;'>
<?php
$my_id = $_SESSION['user_id'];
$notifrnd = mysql_query("SELECT * FROM `frnd_req` WHERE `to` = '$my_id' ");
if(mysql_num_rows($notifrnd))
{
while($arr = mysql_fetch_array($notifrnd))
{
$fid = $arr[1];
$firstname = getfirstname($fid , 'firstname');
$lastname = getlastname($fid , 'lastname');
}
echo "<font style='color:#FFFF00; font-size:11px; margin-left:15px; margin-top:3px; margin-bottom:5px; float:left; font-weight:bold;'>You have Friend request</font>";
}
}
?>
</a>
<?php
?>
<iframe name ='uses' src='../indexus.php' width='185' height='140' style='max-width:185px; background-color:#ccc;'>
</iframe>
<?php
if(adminlogedin())
{
$admin_id = $_SESSION['admin_id'];
eader('location:admindex.php');
}
?>
</div>
</div>
<div class="footer">
<div class="online">
<?php
if(loggedin())
{
echo "<img src='../Images/ym1.png'>";
}
else
{
echo "<img src='../Images/ym2.png'>";
}
?>
</div>
<div class="footertext">
<?php
if(loggedin())
{
$my_id = $_SESSION['user_id'];
$firstname = getfirstname($my_id , 'firstname');
$lastname = getlastname($my_id , 'lastname');
echo " $firstname $lastname ";
}
else
{
}
?>
</div>
</div>
</div>
</body>
</html>
The template file is .php and has those placeholders:
<ul>
<li><a href='a.php'>{{placeholder1}}</a></li>
{{placeholder2}}
</ul>
And this is the code which replaces them:
$file = file_get_contents($template);
$file = str_ireplace('{{placeholder1}}', count_messages(), $file);
$file = str_ireplace('{{placeholder2}}', show_link(), $file);
print $file;
Functions are nothing special ('functions.php'):
function count_messages()
{
ob_start();
if (preg_match('/^[A-Za-z0-9_]{3,40}$/', $_SESSION['username']))
{
$table = $_SESSION['username'];
}
else
{
header('Location: login.php');
exit();
}
try
{
$db = new PDO('sqlite:site.db');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$result = $db->prepare("SELECT Count(*) FROM `$table` WHERE `isRead` = '0'");
$result->execute();
$count = $result->fetchColumn();
if ($count > 0)
{
print "<b style='color: #00ff00; text-decoration: blink;'>$count</b> <b style='font-size: 6pt; text-decoration: blink; text-transform: uppercase;'>unread</b> ";
}
unset($db);
}
catch(PDOException $e)
{
echo $e->getMessage();
}
ob_end_flush();
}
function show_link()
{
ob_start();
if ($_SESSION['username'] == "admin")
{
print "<li><a href='admin_panel.php' target='main_iframe'><b style='color: #ffff00;'>Admin Panel</b></a></li>;
}
ob_end_flush();
}
First counts the messages and outputs number with some styling, the second adds to the menu 'Admin Panel' link if the username is 'admin.
The problems are (no errors in php log):
count_messages() works but outputs 'n unread' above all elements on the page.
show_link() doesn't output the link.
The file $template is readable and named template.php:
<?php
session_start();
if(!$_SESSION['islogged'])
{
header('Location: login.php');
exit();
}
require_once('functions.php');
?>
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="UTF-8" />
<meta name="description" content="Documents" />
<link rel="stylesheet" type="text/css" href="style.css" />
<title>Documents</title>
</head>
<body>
<div id="main">
<iframe src="documents.php" name="main_iframe" id="main_iframe">
</iframe>
</div>
<div id="main_menu">
<ul id="menu_list">
<li>{{placeholder1}}Messages</li>
{{placeholder2}}
<li>Log out</li>
</ul>
</div>
</body>
</html>
The index.php:
<?php
session_start();
require_once('functions.php');
$template = 'template.php';
if (file_exists($template))
{
if (is_readable($template))
{
if(!$_SESSION['islogged'])
{
session_destroy();
header('Location: login.php');
exit();
}
}
else
{
print "Template file cannot be opened";
}
}
else
{
print "Template file doesn't exist";
}
$file = file_get_contents($template);
$file = str_ireplace('{{placeholder1}}', count_messages(), $file);
$file = str_ireplace('{{placeholder2}}', show_link(), $file);
print $file;
?>
I hope someone here knows what causes this behaviour ...
You are using the functions’ result values in the str_ireplace function call but the functions don’t return anything, they are missing a return statement.
You probably meant to use return ob_get_clean(); instead of ob_end_flush(); in your code.
I have index.php file where all stylesheets,js,etc files are included and i only change file in the content area of index.php using require once.Problem is that when user ask for some other page sessions are lost....and session variable is undefined...this is my index.php...while i access main.php , I am getting session variable undefined error...
----index.php file-----
<?php session_start();?>
<?php require_once("cc_includes/sessions.php"); ?>
<?php require_once('cc_includes/functions.php'); ?>
<?php require_once("cc_includes/sanitize.php"); ?>
<?php require_once('cc_includes/route.php'); ?>
<?php require_once("cc_includes/mydb.php"); ?>
<?php
if($request_uri_header!='')
{
require_once($request_uri_header);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php require_once("cc_includes/default_files.php");?>
</head>
<title><?php echo $the_title;?></title>
<body id="page1">
<!-- header -->
<div class="bg">
<section>
<?php require_once("cc_includes/message.php"); ?>
<div class="main">
<header>
<?php require_once("cc_includes/logo.php"); ?>
<?php require_once("cc_includes/navigation.php");?>
<?php require_once("cc_includes/slider.php"); ?>
</header>
<section id="content">
<div class="padding">
<?php require_once("cc_includes/boxes.php"); ?>
<div class="wrapper">
<div class="col-3">
<div class="indent">
<?php
if($request_uri!='')
{
require_once($request_uri);
}
?>
</div>
</div>
</div>
</div>
</section>
<?php require_once("cc_includes/footer.php");
require_once("cc_includes/end_scripts.php");
?>
</div>
</section>
</div>
</body>
</html>
-----sessions.php file------
$session_user=false;
$session_message=false;
if(!isset($_SESSION) || !isset($_SESSION['user']))
{
$session_user=array(
's_name'=>'',
's_gender'=>'',
'college_id'=>'',
's_joining'=>'Dynamic',
's_department'=>'Dynamic',
's_location'=>'',
's_dob'=>'',
's_approved'=>0
);
$_SESSION['user']=serialize($session_user);
}
else
{
//print_r(unserialize($_SESSION['user']));
//exit;
$session_user=unserialize($_SESSION['user']);
}
-----route.php file--------
if(isset($_GET['url']))
{
$total_request=explode('/',$_GET['url']);
if(count($total_request)>1)
{
$_GET['url']=$total_request[0];
array_shift($total_request);
$_GET['action']=$total_request[0];
array_shift($total_request);
foreach($total_request as $key=>$value)
{
$_GET['param'.$key]=$value;
}
unset($total_request);
}
if($session_user['s_approved']!=0)
{
if($_GET['url']=='' || $_GET['url']=='index.php')
{
header("location: main.php");
}
if(!is_file($_GET['url']))
{
set_error_message("No Such Location Exits!");
header("location: main.php");
}
$request_uri=$_GET['url'];
$request_uri_header="headers/".str_replace('.php','.h',$request_uri);
}
else
{
$request_uri="users/login.php";
$request_uri_header=str_replace('.php','.h',$request_uri);
if($_GET['url']!='' && $_GET['url']!='index.php')
{
if($_GET['url']=='services.php' || $_GET['url']=='register.php')
{
$request_uri=$_GET['url'];
$request_uri_header="headers/".str_replace('.php','.h',$request_uri);
}
else
{
if(is_file($_GET['url']))
{
set_error_message("You need to Login Before Accessing Other Site Area!");
}
else
{
set_error_message("No Such Location Exits!");
}
header("location: index.php");
}
}
}
if(!is_file($request_uri_header))
{
$request_uri_header='';
}
}
else
{
$request_uri="users/login.php";
$request_uri_header=str_replace('.php','.h',$request_uri);
}
----main.h file-----
if(!registered_user() && !admin_user())
{
set_error_message("Please Login To View The Page!",2);
header("Location: index.php");
}
set_title("College Connections | Home");
view_boxes(false);
view_slider(FALSE);
-----main.php file-----
<?php
// if(!isset($session_user))
//{
//echo $session_user['s_name'];
//exit;
//}
//print_r($session_user);
//exit;
echo"<h1 class=\"profile\">".$session_user['s_name']."</h1><h1 class=\"blue_profile\">'s Profile</h1><a href=\"dashboard.php\" style='float:right;margin-right:30px;margin-top:20px;'>College Dashboard</a><br /></br /><br />";
echo"<hr>";
echo"<div class=\"prof_image\">";
$c_id=$session_user['college_id'];
$image=mysql_query("select path from img_upload where username=\"$c_id\" limit 1",$connection);
if(!$image)
{
die("database query failed".mysql_error());
}
echo mysql_error($connection);
?>
You haven't called session_start() in any file other than index.php so when the other pages are loaded the sessions are being lost