Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,567 members, 7,820,045 topics. Date: Tuesday, 07 May 2024 at 09:00 AM

Home Page Logout On Page Refresh - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Home Page Logout On Page Refresh (3371 Views)

Design A New Home Page For Us And Win Some Cash And More Work / Commenting System Refresh / Show Me The Script To Automatically Refresh A Webpage (2) (3) (4)

(1) (Reply) (Go Down)

Home Page Logout On Page Refresh by jeebz: 10:33am On Feb 07, 2012
Help, i working on the authentication of my web app, but if I refresh the home page, the page logs out .
<?php
header("Cache-control: must-revalidate,post-check=0,pre-check=0"wink;
header("Cahe-Control:private"wink;
session_start();
if(isset($_SESSION['username'])){
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Home</title>
<link rel="stylesheet" type="text/css" href="main.css"/>
</head>
<body>
<?php
require_once('db.php');
require_once('functions.php');
$sql = "SELECT * FROM cds";
$result = mysql_query($sql);
//while ($row = mysql_fetch_assoc($results)) {
?>
<div id="you"><span>Logged in as:</span> <?php echo $_SESSION['username']?>
<a href="<?php do_logout()?>">Logout</a>
</div>
<div id="details">
<table border="1">
<th>ID</th>
<th>Thumbnail</th>
<th>Artist</th>
<th>AlbumName</th>
<th>No of Tracks</th>
<th>Date added</th>
<th>Genre</th>
<?php
while ($row = mysql_fetch_assoc($result)) {
echo "<tr>\n";
foreach($row as $value) {
echo "<td>\n";
echo $value;
echo "</td>\n";
}
echo "</tr>\n";
}
?>
</table>
</div>
</body>
</html>
<?php
}
else{
header('Location:index.php');
}
?>
Re: Home Page Logout On Page Refresh by delomos(m): 12:42pm On Feb 07, 2012
try switch up the logic:

session_start();
$_SESSION['username'] = $username //I"m assuming you name this somewhere?
if(!isset($_SESSION['username']) {
header('Location:index.php');
//
}
//continue what you want everyone with cookie to see here
,

(or if you don't want to store anything, just check if a session ID is set)
session_start();

if(!defined('SID') {
header('Location:index.php');
//
}
//continue what you want everyone with cookie to see here
Re: Home Page Logout On Page Refresh by jeebz: 1:20pm On Feb 07, 2012
Thank You, I 'll try ur solution grin
Re: Home Page Logout On Page Refresh by bakenda(m): 5:39pm On Feb 07, 2012
The home page is supposed to be index.php, right?
The code for that, i think, you should paste here.
Re: Home Page Logout On Page Refresh by hobyner(m): 11:07pm On Feb 17, 2012
Definitely your homepage must be index.php/html/asp/aspx/htm or default.php/asp/html/aspx. You can name your homepage either index or default. on my website this the code i use for my session:

<?php
include "http.php";
session_start();
if (!isset($_SESSION['userName'])) redirect('index.php');
if (isset($_SESSION['userName']))
{
include("header.php"wink;
}
?>

http.php is another separate code i use so that my redirect statement works well.
The code works well. you can sign up on my website: www.droparena.com
Re: Home Page Logout On Page Refresh by Nobody: 10:22am On Feb 18, 2012
passing by. . .

(1) (Reply)

What Do You Do For A Living? Someone Is Desperate To Patronize You. #getconnecte / Lambda School X Paystack Bootcamp / Which Udemy Course Do You Need ?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 13
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.