[SOLVED] PHP Logout Message when redirect

This is a discussion on "[SOLVED] PHP Logout Message when redirect" within the PHP Forum section. This forum, and the thread "[SOLVED] PHP Logout Message when redirect are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Nov 18th, 2007, 21:41
Reputable Member
Join Date: Jul 2006
Location: Baldock
Age: 20
Posts: 447
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Aaron1988 Send a message via Yahoo to Aaron1988
[SOLVED] PHP Logout Message when redirect

Hi everyone was womdering i have a logout page and when it logs out it redirects to the index.php but when it redirects to index.php i want it to say "Logged out Successfully.

hope some1 can help.

Thanks
Aadon

Last edited by Aaron1988; Nov 18th, 2007 at 21:43. Reason: corrected spelling and grammer
Reply With Quote

  #2 (permalink)  
Old Nov 18th, 2007, 21:46
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,772
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: PHP Logout Message when redirect

Okay tell the redirect to go to: /?logout

This is a GET query. So where you want the message to appear put the following code:
PHP: Select all

if (isset($_GET['logout'])) {
echo 
"You have logged out";

This basically says "If logout came in the URL succeeding a question mark then say this".
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #3 (permalink)  
Old Nov 18th, 2007, 21:50
Reputable Member
Join Date: Jul 2006
Location: Baldock
Age: 20
Posts: 447
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Aaron1988 Send a message via Yahoo to Aaron1988
Re: PHP Logout Message when redirect

ok this is my logout page code

Code: Select all
<?
session_start();
session_destroy();
header ("Location: http://www.qwhosting.co.uk/index.php");
?>
and this is my index page so you could assist me more lol as i dotn know where to put the if issset code.

Code: Select all
<?php 
session_start();
?>
<!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" xml:lang="en" lang="en">
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
 <title>Music Shop</title>
 <link rel="stylesheet" href="style.css" type="text/css" charset="utf-8" />
 
</head>
<body>
  <div id="wrapper">
    <h1><em>MUSIC</em> SHOP</h1>
    <div id="nav">
      <ul>
        <li><a href="<A href="http://www.qwhosting.co.uk/aboutshop.php"><span>01</span">http://www.qwhosting.co.uk/aboutshop.php"><span>01</span> About Shop</a></li>
        <li><a href="<A href="http://www.qwhosting.co.uk/gallery.php"><span>02</span">http://www.qwhosting.co.uk/gallery.php"><span>02</span> Gallery</a></li>
        <li><a href="<A href="http://www.qwhosting.co.uk/freemusic.php"><span>03</span">http://www.qwhosting.co.uk/freemusic.php"><span>03</span> Free Music</a></li>
        <li><a href="<A href="http://www.qwhosting.co.uk/artist.php"><span>04</span">http://www.qwhosting.co.uk/artist.php"><span>04</span> Artist</a></li>
        <li><a href="<A href="http://www.qwhosting.co.uk/contact.php"><span>05</span">http://www.qwhosting.co.uk/contact.php"><span>05</span> Contact</a></li>
        <li><a href="<A href="http://www.qwhosting.co.uk/login/login.php"><span>06</span">http://www.qwhosting.co.uk/login/login.php"><span>06</span> Login</a></li>
        <li><a href="<A href="http://www.qwhosting.co.uk/login/logout.php"><span>07</span">http://www.qwhosting.co.uk/login/logout.php"><span>07</span> Logout</a></li>
        <li><a href="<A href="http://www.qwhosting.co.uk/login/members.php"><span>07</span">http://www.qwhosting.co.uk/login/members.php"><span>07</span> Admin</a></li>
      </ul>
    </div>
    <br>
    <br>
    <font color="#FFFFFF">
Welcome <? echo $_SESSION['username']; ?>
If (isset($_GET['logout'])) {echo "You have logged out";} 
    </br>
    </font>
    <div id="topcon">
      <div id="topcon-inner">
        <h2>Welcome to Music Shop</h2>
        <p></p>
       
      </div>
    </div>
    <div id="content">
      <div id="body">
        <div class="box" id="news">
          <div class="box-t"><div class="box-r"><div class="box-b"><div class="box-l">
          <div class="box-tr"><div class="box-br"><div class="box-bl"><div class="box-tl">
            <h2>NEWS &amp; EVENTS</h2>
            <h3>05.03.2007</h3>
             <p></p>
            <div class="hr-yellow"> </div>
            <h3>05.03.2007</h3>
            <p></p>
          </div></div></div></div>
          </div></div></div></div>
        </div>
        <div class="box" id="hits">
          <div class="box-t"><div class="box-r"><div class="box-b"><div class="box-l">
          <div class="box-tr"><div class="box-br"><div class="box-bl"><div class="box-tl">
            <h2>HIT'S LIST</h2>
            <h3>movie hits</h3>
                        
            <div class="hr-yellow"> </div>
            
            <h3>album hist</h3>
                        
          </div></div></div></div>
          </div></div></div></div>
        </div>
        <div class="box" id="new">
          <div class="box-t"><div class="box-r"><div class="box-b"><div class="box-l">
          <div class="box-tr"><div class="box-br"><div class="box-bl"><div class="box-tl">
            <h2>NEW RELEASES</h2>
            
                        
          </div></div></div></div>
          </div></div></div></div>
        </div>
        <div class="clear"> </div>
      </div>
      <div id="footer">
        <ul>
          <li><a href="<A href="http://www.qwhosting.co.uk/pictures.php">PICTURE</a">http://www.qwhosting.co.uk/pictures.php">PICTURE</a> | </li>
          <li><a href="<A href="http://www.qwhosting.co.uk/gallery.php">GALLERY</a">http://www.qwhosting.co.uk/gallery.php">GALLERY</a> | </li>
          <li><a href="<A href="http://www.qwhosting.co.uk/freemusic.php">FREE">http://www.qwhosting.co.uk/freemusic.php">FREE MUSIC</a> | </li>
          <li><a href="<A href="http://www.qwhosting.co.uk/features.php">FEATURES</a">http://www.qwhosting.co.uk/features.php">FEATURES</a> | </li>
          <li><a href="<A href="http://www.qwhosting.co.uk/contacts.php">CONTACTS</a">http://www.qwhosting.co.uk/contacts.php">CONTACTS</a> | </li>
        </ul>
        <p>&copy; qwhosting.co.uk <a href="<A href="http://www.qwhosting.co.uk">Privacy">http://www.qwhosting.co.uk">Privacy Policy</a> | <a href="<A href="http://www.qwhosting.co.uk/terms.php">Terms">http://www.qwhosting.co.uk/terms.php">Terms of Use</a>.</p>
      </div>
    </div>
  </div>
</body>
</html>
sorry lol but i am kinda still a beginner at this.

Thanks
Aaron
Reply With Quote
  #4 (permalink)  
Old Nov 18th, 2007, 21:56
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,772
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: PHP Logout Message when redirect

PHP: Select all

<?
session_start
();
session_destroy();
header ("Location: http://www.qwhosting.co.uk/?logout");
?>
You should never link to the name of the index page (index.html or index.php) you should only link to the root (just a /)/

And this part:
PHP: Select all

Welcome <? echo $_SESSION['username']; ?>
If (isset($_GET['logout'])) {echo "You have logged out";}
Change to :
PHP: Select all

<?php if (isset($_SESSION['username'])) {
echo 
"welcome ".$_SESSION['username'];
}
if (
iiset($_GET['logout'])) {
echo 
"you have logged out";
}
?>
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #5 (permalink)  
Old Nov 18th, 2007, 22:02
Reputable Member
Join Date: Jul 2006
Location: Baldock
Age: 20
Posts: 447
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Aaron1988 Send a message via Yahoo to Aaron1988
Smile Re: PHP Logout Message when redirect

cheers mate it worked also you put "iiset" lol so had to change it to "isset"

but anyway thanks for your help it works also how can i have it so it says you have "logged out successfully" then it shows there $username?

Thanks
Aaron
Reply With Quote
  #6 (permalink)  
Old Nov 18th, 2007, 22:42
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,772
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: PHP Logout Message when redirect

Well you destroyed the session in the log out script that held the username so you'd have to go to a lot of bother for that.
It's not really worth it.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #7 (permalink)  
Old Nov 18th, 2007, 22:52
Reputable Member
Join Date: Jul 2006
Location: Baldock
Age: 20
Posts: 447
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Aaron1988 Send a message via Yahoo to Aaron1988
Smile Re: PHP Logout Message when redirect

ok mate,

so just keep it as it is then all i got to do now lol is put the protected page lol on all the pages i want protected.

Cheers
Aaron
Reply With Quote
  #8 (permalink)  
Old Nov 19th, 2007, 06:43
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,772
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: PHP Logout Message when redirect

Do you know how to do that?
would be something like this at the top of every page you want protected:
PHP: Select all

 <?php 
// NOTHING ABOVE HERE (not even opening <html> tag or Doctype
if (!isset($_SESSION['username'])) {
header("Location: / "); // if they are not logged in, go to the index page)
}
// By here put the actual page
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #9 (permalink)  
Old Nov 19th, 2007, 10:44
Reputable Member
Join Date: Jul 2006
Location: Baldock
Age: 20
Posts: 447
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Aaron1988 Send a message via Yahoo to Aaron1988
Re: PHP Logout Message when redirect

Hey mate thanks for that i did already know how to do that lol, cause had one already that used the checklogin function lol,

Only thing i wanted with the restrict access, was when it restircts say a "You have entered a restricted error <a href="/login/register.php"

Thanks
Aaron
Reply With Quote
  #10 (permalink)  
Old Nov 19th, 2007, 15:10
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,772
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: [SOLVED] PHP Logout Message when redirect

Ahh right:
PHP: Select all

if (!isset($_SESSION['username'])) {
echo 
"You are not logged in";
exit(); 
// stops anymore code running so will be end of the page for not logged in user
}
//page here 
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)

Last edited by alexgeek; Nov 19th, 2007 at 15:58.
Reply With Quote
  #11 (permalink)  
Old Nov 19th, 2007, 15:56
Reputable Member
Join Date: Jul 2006
Location: Baldock
Age: 20
Posts: 447
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Aaron1988 Send a message via Yahoo to Aaron1988
Re: [SOLVED] PHP Logout Message when redirect

mate i know you put this as solved but it not lmao cause when i use the 2nd code you give me i get this error

Fatal error: Call to undefined function: eit() in /home/greatmaste/domains/qwhosting.co.uk/public_html/aboutshop.php on line 5
Reply With Quote
  #12 (permalink)  
Old Nov 19th, 2007, 15:58
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,772
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: [SOLVED] PHP Logout Message when redirect

Sorry typo. it's exit()
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #13 (permalink)  
Old Nov 19th, 2007, 16:01
Reputable Member
Join Date: Jul 2006
Location: Baldock
Age: 20
Posts: 447
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Aaron1988 Send a message via Yahoo to Aaron1988
Re: [SOLVED] PHP Logout Message when redirect

ok mate lol, also i dont want the message ti display on a white page lol i want it to be displayed on the index.php page cause then itbe eaiser and will look more professional

Thanks
Aaron
Reply With Quote
  #14 (permalink)  
Old Nov 19th, 2007, 16:07
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,772
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: [SOLVED] PHP Logout Message when redirect

Oh okay.
Do the same as the first example but change it to redirect to /?login
then put this wherever you want the text to appear:
PHP: Select all

<?php 
if (iiset($_GET['login'])) {
echo 
"you are not logged in";
}
?>
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #15 (permalink)  
Old Nov 19th, 2007, 16:21
Reputable Member
Join Date: Jul 2006
Location: Baldock
Age: 20
Posts: 447
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Aaron1988 Send a message via Yahoo to Aaron1988
Smile Re: [SOLVED] PHP Logout Message when redirect

hi i have put this on my page i want protected

Code: Select all
<?php // NOTHING ABOVE HERE (not even opening <html> tag or Doctype
if (!isset($_SESSION['username'])) 
{
header("Location: / "); // if they are not logged in, go to the index page)
}
// By here put the actual page
?>
and this code on the index.php page where i want it to show

Code: Select all
<?php 
if (isset($_SESSION['username'])) 
{
echo "welcome ".$_SESSION['username']; 
}
if (isset($_GET['logout'])) 
{
echo "You have Logged Out";
}
if (isset($_GET['login'])) 
{
echo "you are not logged in";
}
?>
hope this is enough information to help me mate
Reply With Quote
  #16 (permalink)  
Old Nov 19th, 2007, 16:24
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,772
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: [SOLVED] PHP Logout Message when redirect

Yes should be! Glad it works now mate.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #17 (permalink)  
Old Nov 19th, 2007, 16:27
Reputable Member
Join Date: Jul 2006
Location: Baldock
Age: 20
Posts: 447
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Aaron1988 Send a message via Yahoo to Aaron1988
Re: [SOLVED] PHP Logout Message when redirect

it doesnt lol cause when i click the page which is protected it doesnt say the messge "you are not logged in"

so i dont know what i am doing wrong

Thanks
Aaron
Reply With Quote
  #18 (permalink)  
Old Nov 19th, 2007, 16:34
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,772
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: [SOLVED] PHP Logout Message when redirect

Just glanced over your code. you didn't send the ?login like i said:
PHP: Select all

<?php // NOTHING ABOVE HERE (not even opening <html> tag or Doctype
if (!isset($_SESSION['username'])) 
{
header("Location: /login "); // if they are not logged in, go to the index page)
}
// By here put the actual page
?>
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #19 (permalink)  
Old Nov 19th, 2007, 17:18
Reputable Member
Join Date: Jul 2006
Location: Baldock
Age: 20
Posts: 447
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Aaron1988 Send a message via Yahoo to Aaron1988
Smile Re: [SOLVED] PHP Logout Message when redirect

cheers mate you forgot to put the ? next to /login lol so i corrected it and now it works like a charm.

Cheers for your help mate most appreciated.

P.S if i need anymore help with my site i will post another thread lol

Thanks
Aaron
Reply With Quote
  #20 (permalink)  
Old Nov 19th, 2007, 17:23
Reputable Member
Join Date: Jul 2006
Location: Baldock
Age: 20
Posts: 447
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Aaron1988 Send a message via Yahoo to Aaron1988
Re: [SOLVED] PHP Logout Message when redirect

also it says welcome admin and right next to it it says you are logged it so how can i make it go on to a new line please

and also when i login and click the protected page lol it still says
"Welcome Admin then the mesage i set which is "you need to login to view content"

i have fixed the bit which says welcome admin when i click the protected page it was cause i started the session lol but didnt destroy it but now when i login and click the protected page it still says "you need to login to view content"

Cheers
Aaron

Last edited by Aaron1988; Nov 19th, 2007 at 17:32. Reason: added more content
Reply With Quote
Reply

Thread Tools