PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
nickman013
Forum Regular
Posts: 764 Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York
Post
by nickman013 » Mon Jan 30, 2006 11:27 am
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
jayshields
DevNet Resident
Posts: 1912 Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England
Post
by jayshields » Mon Jan 30, 2006 12:06 pm
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.
nickman013
Forum Regular
Posts: 764 Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York
Post
by nickman013 » Mon Jan 30, 2006 12:20 pm
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!
nickman013
Forum Regular
Posts: 764 Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York
Post
by nickman013 » Tue Jan 31, 2006 8:29 pm
anyone???
thanks
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Tue Jan 31, 2006 9:52 pm
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
Last edited by
Christopher on Wed Feb 01, 2006 10:59 am, edited 1 time in total.
(#10850)
raghavan20
DevNet Resident
Posts: 1451 Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:
Post
by raghavan20 » Wed Feb 01, 2006 9:07 am
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
}
?>
nickman013
Forum Regular
Posts: 764 Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York
Post
by nickman013 » Wed Feb 01, 2006 3:19 pm
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>
<?
}
?>