Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,195,089 members, 7,957,080 topics. Date: Tuesday, 24 September 2024 at 06:39 AM |
Nairaland Forum / Science/Technology / Programming / Home Page Logout On Page Refresh (3398 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)
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" header("Cahe-Control:private" 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 |
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" } ?> 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)
Biometric Data Capture Application / 2017 Generation Of Programmers - What Languages Are You Using? / Programming Challenge : Obfuscated Code!
(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. 15 |