Jump to content

[SOLVED] Adding a logout function to an existing blog script??


Recommended Posts

Hi Guys,

 

Ive implemented a simple blog script and am using it as a news system for a client of mine.  But for some reason there isnt a logout button and script in place and was wondering how i could add this into the script.

 

the script is at http://tinyurl.com/mtal5s and the login page is at http://tinyurl.com/knqs99

 

then use Username - admin and Password - password to login.

 

if you need any source code let me know.

 

cheers

 

Craig

This is my login.php

 

<?php	
//include the global settings
require_once('../settings.php');


//hold the target url
$_refURL = $_SERVER['QUERY_STRING'];
//if the query string is empty, use chooseTable
if(empty($_refURL)){$_refURL = 'chooseTable.php';}


if(isset($_POST['submit'])){

//reset the target url
if(isset($_POST['ref'])){$_refURL = $_POST['ref'];}

//init the errors
$err = "the following errors occurred:\n";


if(!empty($_POST['user'])){
$_un = $_POST['user']; 
}else{
$err .= "Username was not set.\n";
}

if(!empty($_POST['pwd'])){
$_pw = $_POST['pwd'];
}else{
$err .= "Password was not set.\n";
}

//check for match
if(array_key_exists($_un, $users_login)){
if($users_login[$_un] == $_pw){
	session_register('passed');
	header("Location: $_refURL");
}else{
	$error= 'The password was not correct. Please try again.';
}
}else{
	$error= 'The username and/or password was not correct. Please try again.';

}


}


?>

<!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>
<title><?=$pageTitle?></title>
	<style type="text/css" media="all">@import "../blogStyles.css";</style>
    <style type="text/css" media="all">@import "http://www.tktest.co.uk/clinigen/news_articles/cms/css/screen.css";</style>
    <style type="text/css" media="all">@import "http://www.tktest.co.uk/clinigen/stylesheet.css";</style>
<script type="text/javascript" src="js/inits.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<!--******* Wrapper *******-->
<div id="wrap">

<!--******* Header *******-->
<div id="logo">
	<a href="../../biopharmaceutical_partnering.php" target="_self">CLINIGEN</a></div>

<div id="bullets">
	<p>Management and supply of unlicensed and specialist medicines<br />
        Structured implementation of named patient programmes<br />
        Partnership approach to Global Market Access Planning<br />
        Patient Access and Product Life Cycle support
        </p>
</div>

<div id="slogan">
	<h1>UNLICENSED WITHOUT UNCERTAINTY</h1>
</div>
<!--******* END - Header - END *******-->


<!--******* Top Image *******-->
<div id="topimg">
	<h1>Unlicensed and Specialist Medicine Management and Supply</h1>
</div>
<!--******* END - Top Image - END *******-->

<!--******* Navigation *******-->
<div id="nav">
	<ul id="navbut">
        		<li><a href="../../biopharmaceutical_partnering.php">Home Page</a></li>
                <li><img src="../images/dot.png" alt="" /></li>
                <li><a href="../../about_clinigen.php">About Clinigen</a></li>
                <li><img src="../images/dot.png" alt="" /></li>
                <li><a href="../../global_named_patient_distribution.php">Global Named Patient Distribution</a></li>
                <li><img src="../images/dot.png" alt="" /></li>
                <li><a href="../../patient_access_and_product_life_cycle_support.php">Patient Access & Product Life Cycle Support</a></li>
                <li><img src="../images/dot.png" alt="" /></li>
                <li><a href="../../market_access_planning.php">Market Access Planning</a></li><br />
                <li><a href="../../our_people.php">Our People</a></li>
                <li><img src="../images/dot.png" alt="" /></li>
                <li><a href="../../case_studies.php">Case Studies</a></li>
                <li><img src="../images/dot.png" alt="" /></li>
                <li><a href="../../management_and_supply.php">Management & Supply</a></li>
                <li><img src="../images/dot.png" alt="" /></li>
                <li><a href="../../partnerships.php">Partnerships</a></li>
                <li><img src="../images/dot.png" alt="" /></li>
                <li><a href="../../stakeholders.php">Stakeholders</a></li>
                <li><img src="../images/dot.png" alt="" /></li>
                <li><a href="../../regulatory.php">Regulatory</a></li>
                <li><img src="../images/dot.png" alt="" /></li>
                <li><a href="../news_articles/">News/Articles</a></li>
                <li><img src="../images/dot.png" alt="" /></li>
                <li><a href="../../contact_us.php">Contact Us</a></li>
         </ul>
</div>
<!--******* END - Navigation - END *******-->

<!--******* Content *******-->
<div id="content">
<div id="contact">
<form action="<?=$_SERVER['PHP_SELF']?>" method="POST" >

<h1>LOGIN</h1>
<input type="hidden" name="ref" value="<?=$_refURL ?>" />
<br />
<label for=phone accesskey=P>USERNAME:</label>
<input type="text" name="user" />
<br />
<label for=phone accesskey=P>PASSWORD:</label>
<input type="password" name="pwd" />
<br />
<input type="submit" name="submit" value="Submit" id="contactus" class="submit" /><br />
<?=$error ?>
</form>
</div>
</div>
<!--******* END - Content - END *******-->

<!--******* Footer *******-->
<div id="footer">
	<hr />
        <p class="copyright">© 2009 Clinigen Online</p>
        <a href="http://www.tolputtkeeton.co.uk" target="_blank" class="tolputt">Designed by Tolputt Keeton</a>
        <div id="nav">
        		<ul id="navbutbot">
        		<li><a href="../../biopharmaceutical_partnering.php">Home Page</a></li>
                <li><img src="../images/greydot.png" alt="" /></li>
                <li><a href="../../about_clinigen.php">About Clinigen</a></li>
                <li><img src="../images/greydot.png" alt="" /></li>
                <li><a href="../../global_named_patient_distribution.php">Global Named Patient Distribution</a></li>
                <li><img src="../images/greydot.png" alt="" /></li>
                <li><a href="../../patient_access_and_product_life_cycle_support.php">Patient Access & Product Life Cycle Support</a></li>
                <li><img src="../images/greydot.png" alt="" /></li>
                <li><a href="../../market_access_planning.php">Market Access Planning</a></li><br />
                <li><a href="../../our_people.php">Our People</a></li>
                <li><img src="../images/greydot.png" alt="" /></li>
                <li><a href="../../case_studies.php">Case Studies</a></li>
                <li><img src="../images/greydot.png" alt="" /></li>
                <li><a href="../../management_and_supply.php">Management & Supply</a></li>
                <li><img src="../images/greydot.png" alt="" /></li>
                <li><a href="../../partnerships.php">Partnerships</a></li>
                <li><img src="../images/greydot.png" alt="" /></li>
                <li><a href="../../stakeholders.php">Stakeholders</a></li>
                <li><img src="../images/greydot.png" alt="" /></li>
                <li><a href="../../regulatory.php">Regulatory</a></li>
                <li><img src="../images/greydot.png" alt="" /></li>
                <li><a href="../news_articles/">News/Articles</a></li>
                <li><img src="../images/greydot.png" alt="" /></li>
                <li><a href="../../contact_us.php">Contact Us</a></li>
         </ul>
        </div>
</div>
<!--******* END - Footer - END *******-->

</div>
<!--******* END - Wrapper - END *******-->
</body>
</html>

@MrAdam - You can't work with sessions until you initialise the session function.

 

@craigtolputt:

 

Use an if statement to detect if ?act=logout was sent to the page and then delete the session.

 

<?php   
//include the global settings
require_once('../settings.php');


//hold the target url
$_refURL = $_SERVER['QUERY_STRING'];
//if the query string is empty, use chooseTable
if(empty($_refURL)){$_refURL = 'chooseTable.php';}

$_GET['act'] = strip_tags($_GET['act']); // Filter out any html found in the get variable.

if(isset($_GET['act']) && $_GET['act'] == "logout") // If there is an action set and it is equal to logout...
{
session_start();
unset $_SESSION['passed']; // Unset the session.
// we won't destroy the session as any other sessions linked to this site will be lost too.
}

if(isset($_POST['submit'])){

//reset the target url
if(isset($_POST['ref'])){$_refURL = $_POST['ref'];}

//init the errors
$err = "the following errors occurred:\n";

   
if(!empty($_POST['user'])){
$_un = $_POST['user']; 
}else{
$err .= "Username was not set.\n";
}

if(!empty($_POST['pwd'])){
$_pw = $_POST['pwd'];
}else{
$err .= "Password was not set.\n";
}

//check for match
if(array_key_exists($_un, $users_login)){
   if($users_login[$_un] == $_pw){
      session_register('passed');
      header("Location: $_refURL");
   }else{
      $error= 'The password was not correct. Please try again.';
   }
}else{
      $error= 'The username and/or password was not correct. Please try again.';

}


}


?>

<!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>
<title><?=$pageTitle?></title>
    <style type="text/css" media="all">@import "../blogStyles.css";</style>
    <style type="text/css" media="all">@import "http://www.tktest.co.uk/clinigen/news_articles/cms/css/screen.css";</style>
    <style type="text/css" media="all">@import "http://www.tktest.co.uk/clinigen/stylesheet.css";</style>
   <script type="text/javascript" src="js/inits.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<!--******* Wrapper *******-->
<div id="wrap">

<!--******* Header *******-->
<div id="logo">
      <a href="../../biopharmaceutical_partnering.php" target="_self">CLINIGEN</a></div>

<div id="bullets">
      <p>Management and supply of unlicensed and specialist medicines<br />
        Structured implementation of named patient programmes<br />
        Partnership approach to Global Market Access Planning<br />
        Patient Access and Product Life Cycle support
        </p>
</div>

<div id="slogan">
      <h1>UNLICENSED WITHOUT UNCERTAINTY</h1>
</div>
<!--******* END - Header - END *******-->


<!--******* Top Image *******-->
<div id="topimg">
      <h1>Unlicensed and Specialist Medicine Management and Supply</h1>
</div>
<!--******* END - Top Image - END *******-->

<!--******* Navigation *******-->
<div id="nav">
      <ul id="navbut">
              <li><a href="../../biopharmaceutical_partnering.php">Home Page</a></li>
                <li><img src="../images/dot.png" alt="" /></li>
                <li><a href="../../about_clinigen.php">About Clinigen</a></li>
                <li><img src="../images/dot.png" alt="" /></li>
                <li><a href="../../global_named_patient_distribution.php">Global Named Patient Distribution</a></li>
                <li><img src="../images/dot.png" alt="" /></li>
                <li><a href="../../patient_access_and_product_life_cycle_support.php">Patient Access & Product Life Cycle Support</a></li>
                <li><img src="../images/dot.png" alt="" /></li>
                <li><a href="../../market_access_planning.php">Market Access Planning</a></li><br />
                <li><a href="../../our_people.php">Our People</a></li>
                <li><img src="../images/dot.png" alt="" /></li>
                <li><a href="../../case_studies.php">Case Studies</a></li>
                <li><img src="../images/dot.png" alt="" /></li>
                <li><a href="../../management_and_supply.php">Management & Supply</a></li>
                <li><img src="../images/dot.png" alt="" /></li>
                <li><a href="../../partnerships.php">Partnerships</a></li>
                <li><img src="../images/dot.png" alt="" /></li>
                <li><a href="../../stakeholders.php">Stakeholders</a></li>
                <li><img src="../images/dot.png" alt="" /></li>
                <li><a href="../../regulatory.php">Regulatory</a></li>
                <li><img src="../images/dot.png" alt="" /></li>
                <li><a href="../news_articles/">News/Articles</a></li>
                <li><img src="../images/dot.png" alt="" /></li>
                <li><a href="../../contact_us.php">Contact Us</a></li>
         </ul>
</div>
<!--******* END - Navigation - END *******-->

<!--******* Content *******-->
<div id="content">
<div id="contact">
<form action="<?=$_SERVER['PHP_SELF']?>" method="POST" >

<h1>LOGIN</h1>
<input type="hidden" name="ref" value="<?=$_refURL ?>" />
<br />
<label for=phone accesskey=P>USERNAME:</label>
<input type="text" name="user" />
<br />
<label for=phone accesskey=P>PASSWORD:</label>
<input type="password" name="pwd" />
<br />
<input type="submit" name="submit" value="Submit" id="contactus" class="submit" /><br />
<?=$error ?>
</form>
</div>
</div>
<!--******* END - Content - END *******-->

<!--******* Footer *******-->
<div id="footer">
      <hr />
        <p class="copyright">© 2009 Clinigen Online</p>
        <a href="http://www.tolputtkeeton.co.uk" target="_blank" class="tolputt">Designed by Tolputt Keeton</a>
        <div id="nav">
              <ul id="navbutbot">
              <li><a href="../../biopharmaceutical_partnering.php">Home Page</a></li>
                <li><img src="../images/greydot.png" alt="" /></li>
                <li><a href="../../about_clinigen.php">About Clinigen</a></li>
                <li><img src="../images/greydot.png" alt="" /></li>
                <li><a href="../../global_named_patient_distribution.php">Global Named Patient Distribution</a></li>
                <li><img src="../images/greydot.png" alt="" /></li>
                <li><a href="../../patient_access_and_product_life_cycle_support.php">Patient Access & Product Life Cycle Support</a></li>
                <li><img src="../images/greydot.png" alt="" /></li>
                <li><a href="../../market_access_planning.php">Market Access Planning</a></li><br />
                <li><a href="../../our_people.php">Our People</a></li>
                <li><img src="../images/greydot.png" alt="" /></li>
                <li><a href="../../case_studies.php">Case Studies</a></li>
                <li><img src="../images/greydot.png" alt="" /></li>
                <li><a href="../../management_and_supply.php">Management & Supply</a></li>
                <li><img src="../images/greydot.png" alt="" /></li>
                <li><a href="../../partnerships.php">Partnerships</a></li>
                <li><img src="../images/greydot.png" alt="" /></li>
                <li><a href="../../stakeholders.php">Stakeholders</a></li>
                <li><img src="../images/greydot.png" alt="" /></li>
                <li><a href="../../regulatory.php">Regulatory</a></li>
                <li><img src="../images/greydot.png" alt="" /></li>
                <li><a href="../news_articles/">News/Articles</a></li>
                <li><img src="../images/greydot.png" alt="" /></li>
                <li><a href="../../contact_us.php">Contact Us</a></li>
         </ul>
        </div>
</div>
<!--******* END - Footer - END *******-->

</div>
<!--******* END - Wrapper - END *******-->
</body>
</html>

 

Shove this anywhere in your site (obviously in the logged in areas)

 

<a href="login.php?act=logout" alt="Log out">Log Out</a>

 

Hope this helps.

session_register('passed');

 

You can try doing this instead too:

 

session_start(); // PHP will tell you if its already been set in an error. if so, delete this line
$_SESSION['passed'] = true;

 

Would i need this script at the top of every page within the cms section or just at the top of the login.php?

 

You would only put it in login.php as that's the page that will destroy the session (obviously, you could in essence put it in every page, but in pages locked to members only, the session would be destroyed and they would be greeted with a blank page. By only having it in login.php it simply shows them the login screen after they've logged out.

I'm surprised mine didn't work, so long as you define the session with:

session_start();

$_SESSION['bob'] = "storeanythingyoulike";

 

you can call it any time on that website

 

echo $_SESSION['bob']

 

and 1 the session returns true and 2 it stores "storeanythingyouilke" which is useful if you wanna call a username or match a user id against a database in order to refer to that user in something they post.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.