Search
Left Quote    By failing to prepare, you are preparing to fail.
- Benjamin Franklin    
Right Quote
 
[login] | [Register]
Forum Index » PHP and mySQL » Viewing Topic and Replies
Post Reply


        Viewing Topic: Newbie Stupidity on MY behalf!
  This user is offline  aussiefly
  Subject: "Newbie Stupidity on MY behalf!" Posted: @ 7:03 am on Dec 30 2007   
Member #: 528
Rank: User - (2)
Since: 12/30/07
Posts: 2

Okay,

Firstly, i'm exceedingly new to PHP and still finding my feet with the syntax. I've read the fantastic tutorial on the membership system and for the most part i've got it working fairly well.

The 2 errors that I have are probably fairly minor and due to my inexperience so i'd appreciate any help anyone can give.

Error 1:
After logging in using the form I have it set to go to a members page where it basically echos "welcome to the members page and then the name of the user. by using the Session[usernam e] variable it sort of my way to checking that the login worked etc.

So that works fine but the problem is that when i access logout.php it doesnt actually clear the session or cookie...I have to manually clear it etc. I was getting the headers already sent error and used the obstart hack which worked well to clear it but seemingly its now not logging my user out.

Here is my logout.php code:


Code:
<?
ob_start();
$_SESSION['logg ed_in'] = 0;

setcookie('logi n_cookie', "", time() - 60, '/', '.rowlandbooks. info');

session_destroy ();
header("Lo cation: http://www.rowl andbooks.info/d emo");
?>



Error 2:

Even though I have my members page set with an include statement calling my page_header file its still not requiring a user to login. For some reason if i access the member page directly...even with cookies cleared...it will still display the page even though its including the page header file.

Here is the code for my members page:

Code:
<?
include('../pag e_header.php');

echo "Welcome to the members homepage " . $_SESSION['user name'];
?>



And this is the code to my page_header.php file


Code:
<?php
ob_start();
session_start() ;
require_once($_ SERVER['DOCUMEN T_ROOT'].'/db_c onnect.php');
//check cookie
if ($_SESSION['log ged_in'] != 1 && isset($_COOKIE[ 'login_cookie'] )) {
list($user, $pass) = explode('[]', $_COOKIE['login _cookie']);
$qu = mysql_query(&qu ot;SELECT `user_password` FROM `members` WHERE `username` = '".addslas hes($user).&quo t;'");
if (mysql_num_rows ($qu) == 1) {
$passw = mysql_fetch_obj ect($qu);
if ($passw->use r_password == $pass) {
$_SESSION['logg ed_in'] = 1;
$_SESSION['user name'] = $user;
$_SESSION['pass word'] = $pass;
}
}
}

if(!isset($_SES SION['username' ]) && !isset($_SESSIO N['password'])) {
$_SESSION['logg ed_in'] = 0;
$user = "Guest&quo t;;
}
?>



So any ideas on what I can do to solve those two issues??

Cheers from a complete php loser :) :)


    Viewed: 5,717 Times | Reply to This | To top
  This user is offline  aussiefly
  Subject: "re: Newbie Stupidity on MY behalf!" Posted: @ 7:49 am on Dec 30 2007    
Member #: 528
Rank: User - (2)
Since: 12/30/07
Posts: 2

YAY!

I've fixed error #2 by inserting the following code under the not logged in conditional:

// redirect user to login form
header("L ocation: http://www.rowl andbooks.info/d emo/login.php& quot;

It actually wasnt an error, just me not telling it what to do in the event they are not logged in

Anyway, i'm still not able to effect a logout for some reason...it doesnt appear to be destroying the session or the cookie...any ideas??



  aussiefly said...

< i> Okay,

Firstly, i'm exceedingly new to PHP and still finding my feet with the syntax. I've read the fantastic tutorial on the membership system and for the most part i've got it working fairly well.

The 2 errors that I have are probably fairly minor and due to my inexperience so i'd appreciate any help anyone can give.

Error 1:
After logging in using the form I have it set to go to a members page where it basically echos "welcome to the members page and then the name of the user. by using the Session[usernam e] variable it sort of my way to checking that the login worked etc.

So that works fine but the problem is that when i access logout.php it doesnt actually clear the session or cookie...I have to manually clear it etc. I was getting the headers already sent error and used the obstart hack which worked well to clear it but seemingly its now not logging my user out.

Here is my logout.php code:


Code:
<?
ob_start();
$_SESSION['log ged_in'] = 0;

setcookie('log in_cookie', "", time() - 60, '/', '.rowlandbooks .info');

session_destroy ();
header("L ocation: http://www.rowl andbooks.info/d emo";
?>



Error 2:

Even though I have my members page set with an include statement calling my page_header file its still not requiring a user to login. For some reason if i access the member page directly...even with cookies cleared...it will still display the page even though its including the page header file.

Here is the code for my members page:

Code:
<?
include('../pa ge_header.php' );

echo "Welcome to the members homepage " . $_SESSION['use rname'];
?>



And this is the code to my page_header.php file


Code:
<?php
ob_start();
session_start() ;
require_once($_ SERVER['DOCUME NT_ROOT'].'/d b_connect.php' );

//check cookie
if ($_SESSION['lo gged_in'] != 1 && isset($_COOKIE[ 'login_cookie '])) {
list($user, $pass) = explode('[]', $_COOKIE['logi n_cookie']);
$qu = mysql_query(&q uot;SELECT `user_password` FROM `members` WHERE `username` = '".addsl ashes($user).& quot;'";
if (mysql_num_rows ($qu) == 1) {
$passw = mysql_fetch_obj ect($qu);
if ($passw->use r_password == $pass) {
$_SESSION['log ged_in'] = 1;
$_SESSION['use rname'] = $user;
$_SESSION['pas sword'] = $pass;
}
}
}

if(!isset($_SES SION['username ']) && !isset($_SESSIO N['password'] )) {
$_SESSION['log ged_in'] = 0;
$user = "Guest&q uot;;
}
?>



So any ideas on what I can do to solve those two issues??

Cheers from a complete php loser




    Viewed: 5,711 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: Newbie Stupidity on MY behalf!" Posted: @ 10:58 pm on Dec 30 2007    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

In your logout code, try setting the session variables to defaults (logged in = 0, username = guest, and so forth).




-bs0d | AllSyntax.com

    Viewed: 5,687 Times | Reply to This | To top
Viewing Page: 1 of 1


1 |

You must be logged in to post on the forums. Login or Register








"AllSyntax.com" Copyright © 2002-2018; All rights lefted, all lefts righted.
Privacy Policy  |  Internet Rank