Page 1 of 1

If logged in display this.

Posted: Mon Jan 30, 2006 11:27 am
by nickman013
Hello,

I have a very basic login with sessions setup.

To secure a page I put

Code: Select all

<?
session_start(); 
if (empty($_SESSION['log'])) 
header('Location:/pages/login.php');
include('/home/muot/public_html/pages/includes/regpage.php');
?>
that at the top of the page.

I want to put somthing into all of the pages, that if the user is logged in. It will display a logout link in the upper right hand corner.

if the user is not logged in, i dont want it to display it, I dont want it to do anytihng.


Thank You

Posted: Mon Jan 30, 2006 12:06 pm
by jayshields

Code: Select all

<?php 
session_start();  
if (empty($_SESSION['log'])) {
header('Location:/pages/login.php');
exit();
} else {
//display whatever
}
include('/home/muot/public_html/pages/includes/regpage.php');
?>
By the way, it's bad practice to use short tags (<? and ?>) and to not use absolute URL's in Location:xxx.

Posted: Mon Jan 30, 2006 12:20 pm
by nickman013
I just want to add

Code: Select all

include("/root/usr/whatever/iflogged.php")
in every page.

and in the iflogged.php file I want it to do the following

1. If they are not logged in, do nothing.
2. If they are logged in display a logout link.


Thats it.

Thank You!

Posted: Tue Jan 31, 2006 8:29 pm
by nickman013
anyone???

thanks

Posted: Tue Jan 31, 2006 9:52 pm
by Christopher
I can't see where you actually asked a question so I will guess:

File iflogged.php:

Code: Select all

<?php
session_start(); 
if (isset($_SESSION['loggedin'])) {
    header('Location:/pages/login.php');
    exit();
}
?>
Pages:

Code: Select all

include 'iflogged.php';
// contents of page

Posted: Wed Feb 01, 2006 9:07 am
by raghavan20
Now you can include this page...
iflogged.php

Code: Select all

<?php 
session_start();  
if (isset($_SESSION['loggedin']) === FALSE) { 
    header('Location:/pages/login.php'); 
}else{
?>
	<div style = 'text-align:right'>
		<a href = 'login.php?action=logout'>Log Out</a>
	<div>
<?php	
}
?>

Posted: Wed Feb 01, 2006 3:19 pm
by nickman013
Parse error: parse error, unexpected T_STRING in /home/muot/public_html/pages/includes/iflogged.php on line 3

Code: Select all

<?php
session_start();   
if (isset($_SESSION['loggedin']) === FALSE) {  echo "" 
}else{ 
?> 
<div style = 'text-align:right'> 
<a href = '/pages/login/logout.php'>Log Out</a> 
<div> 
<?    
} 
?>