[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
  #21 (permalink)  
Old Nov 19th, 2007, 17:40
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
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

Not to sure what you mean, perhaps a line break(<br> or <br />)
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #22 (permalink)  
Old Nov 19th, 2007, 17:55
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

hello well when i login to my account and press the "about us" link which is protected it still says "you need to login to view this content"
Reply With Quote
  #23 (permalink)  
Old Nov 19th, 2007, 18:02
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
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

Well if it is protected then it would say that wouldn't it?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #24 (permalink)  
Old Nov 19th, 2007, 18:15
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

what even if i am Logged in?.
Reply With Quote
  #25 (permalink)  
Old Nov 19th, 2007, 18:20
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
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 strange. Umm have you get session_start() somewhere on your page above that code?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #26 (permalink)  
Old Nov 19th, 2007, 18:28
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

Yes i have

<?php
session_start();
?>

before any html code and php code so right at the top of the page, and when i click the about us page when logged in it doesnt go to the page just goes to the index.php page again and just says "you need to login to view content"

so do you want to see the whole of the index.php page and the aboutus.php page to help you more.

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

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
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

Can I see your login script aswell as those two please?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #28 (permalink)  
Old Nov 19th, 2007, 18:35
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 so you want to see the login.php page as well yes
Reply With Quote
  #29 (permalink)  
Old Nov 19th, 2007, 18:46
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

here is the login.php, aboutusshop.php and the index.php attached to this document.

login.php

PHP: Select all

<?php
require_once ( 'settings.php);
if ( 
array_key_exists '_submit_check'$_POST ) )
{
if ( 
$_POST['username'] != '' && $_POST['password'] != '' )
{
$query 'SELECT ID, Username, Active, Password FROM ' DBPREFIX 'users WHERE Username = ' $db->qstr $_POST['username'] ) . ' AND Password = ' $db->qstr md5 $_POST['password'] ) );
if ( 
$db->RecordCount $query ) == )
{
$row $db->getRow $query );
if ( 
$row->Active == )
{
set_login_sessions $row->ID$row->Password, ( $_POST['remember'] ) ? TRUE FALSE );
$_SESSION['username'] = $username;
header "Location: " REDIRECT_AFTER_LOGIN );
}
elseif ( 
$row->Active == ) {
$error 'Your membership was not activated. Please open the email that we sent and click on the activation link.';
}
elseif ( 
$row->Active == ) {
$error 'You are suspended!';
}
}
else { 
$error 'Login failed!'
}

}
else {
$error 'Please use both your username and password to access your account';
}
}
?>
<!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>
<title>roScripts.com - PHP Login System With Admin Features</title>
<link href="css/styles.css" rel="stylesheet" type="text/css" />
<!--
____ __
/\ _`\ __ /\ \__
_ __ ___\ \,\L\_\ ___ _ __ /\_\ _____\ \ ,_\ ____
/\`'__\/ __`\/_\__ \ /'___\/\`'__\/\ \/\ '__`\ \ \/ /',__\
\ \ \//\ \L\ \/\ \L\ \/\ \__/\ \ \/ \ \ \ \ \L\ \ \ \_/\__, `\
\ \_\ \____/\ `\____\ \____\ \_\ \ \_\ \ ,__/\ \__\/\____/
\/_/ \/___/ \/_____/\/____/ \/_/ \/_/\ \ \/ \/__/\/___/
\ \_\
\/_/
Making your world easy
-->
</head>
<body>
<div id="log">
<?php if ( isset( $error ) ) { echo ' <p class="error">' $error '</p>' "\n";}?>
</div>
<div id="container" style="width:230px;">
<form class="form" action="<?=$_SERVER['PHP_SELF']?>" method="post">
<input type="hidden" name="_submit_check" value="1"/> 

<div style="margin-top:12px; margin-bottom:10px">
<img src="images/username.gif" alt="username" border="0" />
<input class="input" type="text" name="username" id="username" size="25" maxlength="40" value="" />
</div>
<div style="margin-bottom:6px">
<img src="images/password.gif" alt="password" border="0" />
<input class="input" type="password" name="password" id="password" size="25" maxlength="32" />
</div>
<?php if ( ALLOW_REMEMBER_ME ):?>
<div style="margin-bottom:6px">
<input type="checkbox" name="remember" id="remember" />
<label for="remember">Remember me</label>
</div>
<?php endif;?>
<input type="image" name="Login" value="Login" class="submit-btn" src="images/btn.gif" alt="submit" title="submit" />
<br class="clear" />
<a href="register.php">Register</a> / <a href="forgot_password.php">Password recovery?</a>

</form>

<!--
Keeping the link below not only gives respect to the large amount of time given freely by me
but also helps build interest, traffic and use of this script. It's not required but
recommended since it also might affect my support priorities on the forums.

Thank you, Mihalcea Romeo - roScripts.com
// -->
<?=powered_by ()?>

</div>

</body>
</html>
aboutusshop.php

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
?>
<!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/xhtmlxml: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>ABOUT</em></h1>
<div id="nav">
<ul>
<li><a href="http://www.qwhosting.co.uk/aboutshop.php"><span>01</span> About Shop</a></li>
<li><a href="http://www.qwhosting.co.uk/gallery.php"><span>02</span> Gallery</a></li>
<li><a href="http://www.qwhosting.co.uk/freemusic.php"><span>03</span> Free Music</a></li>
<li><a href="http://www.qwhosting.co.uk/artist.php"><span>04</span> Artist</a></li>
<li><a href="http://www.qwhosting.co.uk/contact.php"><span>05</span> Contact</a></li>
<li><a href="http://www.qwhosting.co.uk/login/login.php"><span>06</span> Login</a></li>
<li><a href="http://www.qwhosting.co.uk/login/register.php"><span>07</span> Register</a></li>
<li><a href="http://www.qwhosting.co.uk/login/members.php"><span>07</span> Admin</a></li>
</ul>
</div>
<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="http://www.qwhosting.co.uk/pictures.php">PICTURE</a> | </li>
<li><a href="http://www.qwhosting.co.uk/gallery.php">GALLERY</a> | </li>
<li><a href="http://www.qwhosting.co.uk/freemusic.php">FREE MUSIC</a> | </li>
<li><a href="http://www.qwhosting.co.uk/features.php">FEATURES</a> | </li>
<li><a href="http://www.qwhosting.co.uk/contacts.php">CONTACTS</a> | </li>
</ul>
<p>&copy; qwhosting.co.uk <a href="http://www.qwhosting.co.uk">Privacy Policy</a> | <a href="http://www.qwhosting.co.uk/terms.php">Terms of Use</a>.</p>
</div>
</div>
</div>
</body>
</html>
index.php

PHP: Select all

<?php 
session_start
();
session_destroy();
?>
<!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/xhtmlxml: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="http://www.qwhosting.co.uk/aboutshop.php"><span>01</span> About Shop</a></li>
<li><a href="http://www.qwhosting.co.uk/gallery.php"><span>02</span> Gallery</a></li>
<li><a href="http://www.qwhosting.co.uk/freemusic.php"><span>03</span> Free Music</a></li>
<li><a href="http://www.qwhosting.co.uk/artist.php"><span>04</span> Artist</a></li>
<li><a href="http://www.qwhosting.co.uk/contact.php"><span>05</span> Contact</a></li>
<li><a href="http://www.qwhosting.co.uk/login/login.php"><span>06</span> Login</a></li>
<li><a href="http://www.qwhosting.co.uk/login/logout.php"><span>07</span> Logout</a></li>
<li><a href="http://www.qwhosting.co.uk/login/members.php"><span>07</span> Admin</a></li>
</ul>
</div>
<br>
<br>
<font color="#FFFFFF" size="3">
<?php 
if (isset($_SESSION['username'])) 
{
echo 
"welcome ".$_SESSION['username']; 
}
if (isset(
$_GET['logout'])) 
{
echo 
"You have Logged Out";
}
if (isset(
$_GET['login'])) 
{
echo 
"you need to login to view content";
}
?>
</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="http://www.qwhosting.co.uk/pictures.php">PICTURE</a> | </li>
<li><a href="http://www.qwhosting.co.uk/gallery.php">GALLERY</a> | </li>
<li><a href="http://www.qwhosting.co.uk/freemusic.php">FREE MUSIC</a> | </li>
<li><a href="http://www.qwhosting.co.uk/features.php">FEATURES</a> | </li>
<li><a href="http://www.qwhosting.co.uk/contacts.php">CONTACTS</a> | </li>
</ul>
<p>&copy; qwhosting.co.uk <a href="http://www.qwhosting.co.uk">Privacy Policy</a> | <a href="http://www.qwhosting.co.uk/terms.php">Terms of Use</a>.</p>
</div>
</div>
</div>
</body>
</html>
Thanks
Aaron

Last edited by Aaron1988; Nov 19th, 2007 at 18:51.
Reply With Quote
  #30 (permalink)  
Old Nov 19th, 2007, 19:09
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
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

On contact us, you still have to start the session:
PHP: Select all

<?php
session_start
();
 
// 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
  #31 (permalink)  
Old Nov 19th, 2007, 19:24
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

what page lol cause i cant see it on the contact us page. lol
Reply With Quote
  #32 (permalink)  
Old Nov 19th, 2007, 19:33
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

Done mate

i had to add the <?php session_start(); to the aboutusshop.php page lol and then it came up with errors lmao but i fixed that by removing the <?php session_destroy(); lol and also how can you add <br> in a php code cause want to line break where it says welcome admin and you need login to view content

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

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
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

wherever it says welcome admin, just add a <br> to that string.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #34 (permalink)  
Old Nov 19th, 2007, 19:53
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
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

PHP: Select all

echo "welcome ".$_SESSION['username'].'<br>'
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #35 (permalink)  
Old Nov 19th, 2007, 20:00
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, Cheers mate

Thanks for the help.
Reply With Quote
  #36 (permalink)  
Old Nov 19th, 2007, 20:04
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
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

You're welcome! good luck with this!
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #37 (permalink)  
Old Nov 19th, 2007, 23:37
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

Thanks, and cheers also one question how can i have the login box appear on the index.php page cause i think it will look much much better.

Cheers
Aaron
Reply With Quote
  #38 (permalink)  
Old Nov 20th, 2007, 06:37
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
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 copy the form part to the place where you want it to appear on the index.php page, and change the target in the form tag to: target="login.php".
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #39 (permalink)  
Old Nov 20th, 2007, 07:03
Reputable Member