Search
Left Quote    I think there is a world market for maybe five computers.
- Thomas Watson, Chairman of IBM 1943    
Right Quote
 
[login] | [Register]
Forum Index » PHP and mySQL » Viewing Topic and Replies
Post Reply


        Viewing Topic: Complete Member System Sample
  This user is offline  anteater
  Subject: "Complete Member System Sample" Posted: @ 9:36 am on Jun 08 2007   
Member #: 335
Rank: User - (3)
Since: 06/08/07
Posts: 3

I was just wondering if anyone had a sample of this I could look at. I've been trying to use it, but as easy as it is, I seem to be having problems. I learn best by seeing a working version and just copying and editting accordingly. So if anyone could show me each of their files or something that would be really nice. I basically ended up with index.php, db_connect.php, login.php, logout.php, reg.php, and members.php

Thanks in advance


    Viewed: 34,404 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: Complete Member System Sample" Posted: @ 11:47 am on Jun 08 2007    

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

In case if nobody can provide you with their version of the files, what specific problems are you encountering?




-bs0d | AllSyntax.com

    Viewed: 33,308 Times | Reply to This | To top
  This user is offline  anteater
  Subject: "re: Complete Member System Sample" Posted: @ 11:10 pm on Jun 08 2007    
Member #: 335
Rank: User - (3)
Since: 06/08/07
Posts: 3

  bs0d said...

< i> In case if nobody can provide you with their version of the files, what specific problems are you encountering?

I keep getting this error when I try to logout:

Warning: session_destroy () [function.sessi on-destroy]: Trying to destroy uninitialized session in /public_html/te st/logout.php on line 6

Warning: Cannot modify header information - headers already sent by (output started at /public_html/te st/logout.php:6 ) in /public_html/te st/logout.php on line 7/b]




    Viewed: 33,298 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: Complete Member System Sample" Posted: @ 1:25 am on Jun 09 2007    

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

Make sure your session variable names match between login.php and logout.php? Also, using ob_start() as the first line of code on the page that you experience the error on will get rid of the error.




-bs0d | AllSyntax.com

    Viewed: 33,291 Times | Reply to This | To top
  This user is offline  gravy
  Subject: "re: Complete Member System Sample" Posted: @ 9:25 pm on Jun 09 2007    

Member #: 294
Rank: User - (63)
Since: 03/07/07
Posts: 66
From: MN

  bs0d said...

< i> Make sure your session variable names match between login.php and logout.php? Also, using ob_start() as the first line of code on the page that you experience the error on will get rid of the error.

Hey maybe I can help if he is still having problems. I used this in my script at gravy-media.com and you are welcome to go download my BETA version. Also i use this member system at imagerabbit.com

Do not visit these unless you are doing so for educational purposes! I dont want to be some SPAM fool.




Photo Hosting Scripts? It's what I do....

    Viewed: 33,276 Times | Reply to This | To top
  This user is offline  anteater
  Subject: "re: Complete Member System Sample" Posted: @ 8:05 am on Jun 10 2007    
Member #: 335
Rank: User - (3)
Since: 06/08/07
Posts: 3

thanks for all the help. i am going to try this again and ill come back with any problems.




    Viewed: 33,267 Times | Reply to This | To top
  This user is offline  drewage
  Subject: "re: Complete Member System Sample" Posted: @ 11:00 pm on Jun 11 2007    
Member #: 338
Rank: User - (3)
Since: 06/11/07
Posts: 3

hi guys i'm having the same exact problem but can't figure it out. I'm thinking I have the page_header.php in the wrong place. Could someone shed some light?
I've started with a simple logged_in.php page that will be accessible once logged in. It contains a logout link which I expect should logout but I get the session_destroy errors as mentioned above. I left the cookie names as default(www.you rsite.com and yoursite.com) so that shouldn't be a problem..?

Thanks all in advance,

I have the following code:

login.php


Code:

<?
ob_start();
require_once(' ../common/mysql _connect.php') ;
session_start() ;
if(isset($_SESS ION['username ']) && isset($_SESSION ['password']) ) {
//REDIRECT TO USERS PROFILE...
header("L ocation: http://www.eart hclans.com/new/ logged_in.php& quot;);
} //end if logged in

//IF SUBMIT BUTTON PRESSED
if(isset($_POST ['submit'])) {

if(!$_POST['us ername']) die("Erro r: You must enter your username before logging in.");
if(!$_POST['pa ssword']) die("Erro r: You must enter your password before logging in.");

//set cookie if checked
if(!empty($_POS T['stay_in']) ) {
$joined =''.$_POST[' username'].'[ ]'.md5($_POST[ 'password']). '';
setcookie('log in_cookie', $joined, 2147483647, '/', '.www.yoursite .com');
} //end if

//verify user...
$get_user = mysql_query(&q uot;SELECT * FROM `members` WHERE username = '".$_POS T['username'] ."' AND

user_password = '".md5($ _POST['passwor d'])."' ");
$q = mysql_fetch_obj ect($get_user);
if(!$q) die("Logi n Failure: An error occured, please verify your username and password are correct." );

//set session variables
$_SESSION['log ged_in'] = 1;
$_SESSION['use rname'] = $_POST['userna me'];
$_SESSION['pas sword'] = $_POST['passwo rd'];
session_write_c lose();

header("L ocation: http://www.eart hclans.com/new/ logged_in.php& quot;);

} else {
//show login form
?>
<form name="log in" method="p ost" action="& lt;? $_SERVER['PHP_ SELF']; ?>"> ;
<table> <tr>
<td>Usern ame:<input type="tex t" id="usern ame" name="use rname"> ;</td>
</tr>
<tr>
<td>Passw ord:<input type="pas sword" id="passw ord" name="pas sword"> ;</td>
</tr>
<tr>
<td>Submi t: <input type="sub mit" value="Su bmit" name="sub mit" id="submi t">< ;/td>
</tr>
<tr>
<td>Remem ber? <input type="che ckbox" name="sta y_in[]" checked=" yes">& lt;/td>
</tr>
</table>< br /> </form> <?
}//end else
?>



logged_in.php

Code:
<?
include('page_ header.php'); ?>

<!DOCTYPE html PUBLIC "-//W3C// DTD XHTML 1.0 Transitional//E N" "http://w ww.w3.org/TR/xh tml1/DTD/xhtml1 -transitional.d td"> <html xmlns="ht tp://www.w3.org /1999/xhtml&qu ot;>
<head>
<meta http-equiv=&qu ot;Content-Type " content=" text/html; charset=utf-8& quot; />
<title>Un titled Document</ti tle>
</head>
<body>

<p>You'r e logged in!</p> <p>&n bsp;</p>< br /> <p><a href="log out.php"& gt;logout</a > </p>
</body> </html>



page_header.php


Code:
<?
ob_start();
session_start() ;
//echo $_SESSION['log ged_in'];
require_once(' ../common/mysql _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;;
//header(" ;Location: http://www.eart hclans.com/new/ login.php" ;);
}
echo $user;
?>




logout.php

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

setcookie('log in_cookie', "", time() - 60, '/', '.yoursite.com ');

session_destroy ();
header("L ocation: http://www.your site.com" );
?>




    Viewed: 33,243 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: Complete Member System Sample" Posted: @ 11:55 pm on Jun 11 2007    

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

every one of your pages you listed should have the page header.php - page header contains the code that you want to recognize members on, so it must be on every page you want to recognize a member.

and on your cookies, change www.yoursite.co m to www.earthclans. com if thats your site.




-bs0d | AllSyntax.com

    Viewed: 33,238 Times | Reply to This | To top
  This user is offline  gravy
  Subject: "re: Complete Member System Sample" Posted: @ 11:57 pm on Jun 11 2007    

Member #: 294
Rank: User - (63)
Since: 03/07/07
Posts: 66
From: MN

  drewage said...

< i> hi guys i'm having the same exact problem but can't figure it out. I'm thinking I have the page_header.php in the wrong place. Could someone shed some light?
I've started with a simple logged_in.php page that will be accessible once logged in. It contains a logout link which I expect should logout but I get the session_destroy errors as mentioned above. I left the cookie names as default(www.you rsite.com and yoursite.com) so that shouldn't be a problem..?

Thanks all in advance,

I have the following code:

login.php

<BR><f ont size=1><u >Code:</u ><BR>& lt;div name="div _box" class="di vCode"> ;<?
ob_start();
require_once(' ../common/mysql _connect.php') ;
session_start() ;
if(isset($_SESS ION['username ']) && isset($_SESSION ['password']) ) {
//REDIRECT TO USERS PROFILE...
header("L ocation: http://www.eart hclans.com/new/ logged_in.php& quot;
} //end if logged in

//IF SUBMIT BUTTON PRESSED
if(isset($_POST ['submit'])) {

if(!$_POST['us ername']) die("Erro r: You must enter your username before logging in.";
if(!$_POST['pa ssword']) die("Erro r: You must enter your password before logging in.";

//set cookie if checked
if(!empty($_POS T['stay_in']) ) {
$joined =''.$_POST[' username'].'[ ]'.md5($_POST[ 'password']). '';
setcookie('log in_cookie', $joined, 2147483647, '/', '.www.yoursite .com');
} //end if

//verify user...
$get_user = mysql_query(&q uot;SELECT * FROM `members` WHERE username = '".$_POS T['username'] ."' AND

user_password = '".md5($ _POST['passwor d'])."' ";
$q = mysql_fetch_obj ect($get_user);
if(!$q) die("Logi n Failure: An error occured, please verify your username and password are correct."< img src=http://www. allsyntax.com/f orums/images/sm ilies/wink.gif border=0>;

//set session variables
$_SESSION['log ged_in'] = 1;
$_SESSION['use rname'] = $_POST['userna me'];
$_SESSION['pas sword'] = $_POST['passwo rd'];
session_write_c lose();

header("L ocation: http://www.eart hclans.com/new/ logged_in.php& quot;

} else {
//show login form
?>
<form name="log in" method="p ost" action="& lt;? $_SERVER['PHP_ SELF']; ?>"> ;
<table>
<tr>
<td>Usern ame:<input type="tex t" id="usern ame" name="use rname"> ;</td>
</tr>
<tr>
<td>Passw ord:<input type="pas sword" id="passw ord" name="pas sword"> ;</td>
</tr>
<tr>
<td>Submi t: <input type="sub mit" value="Su bmit" name="sub mit" id="submi t">< ;/td>
</tr>
<tr>
<td>Remem ber? <input type="che ckbox" name="sta y_in[]" checked=" yes">& lt;/td>
</tr>
</table>
</form>
<?
}//end else
?>



logged_in.php


Code:

include('page_ header.php'); ?>

<!DOCTYPE html PUBLIC "-//W3C// DTD XHTML 1.0 Transitional//E N" "http://w ww.w3.org/TR/xh tml1/DTD/xhtml1 -transitional.d td">
<html xmlns="ht tp://www.w3.org /1999/xhtml&qu ot;>
<head>
<meta http-equiv=&qu ot;Content-Type " content=" text/html; charset=utf-8& quot; />
<title>Un titled Document</ti tle>
</head>

<body>

<p>You'r e logged in!</p>
<p>&n bsp;</p>
<p><a href="log out.php"& gt;logout</a > </p>
</body>
</html>



page_header.php

<BR><f ont size=1><u >Code:</u ><BR>& lt;div name="div _box" class="di vCode"> ;<?
ob_start();
session_start() ;
//echo $_SESSION['log ged_in'];
require_once(' ../common/mysql _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;;
//header(" ;Location: http://www.eart hclans.com/new/ login.php" ;
}
echo $user;
?>




logout.php


Code:

<?
$_SESSION['log ged_in'] = 0;

setcookie('log in_cookie', "", time() - 60, '/', '.yoursite.com ');

session_destroy ();
header("L ocation: http://www.your site.com"< img src=http://www. allsyntax.com/f orums/images/sm ilies/wink.gif border=0>;
?>




well on the logout header locations I would put in something like index.php instead of a site that doesn't exist. That way people have a place to go after the logout.

Here is my login.php code:

Code:

<?
include "header.p hp";

if(isset($_SESS ION['username ']) && isset($_SESSION ['password']) ) {
//REDIRECT TO USERS PROFILE...
header("L ocation: main.php"< img src=http://www. allsyntax.com/f orums/images/sm ilies/wink.gif border=0>;
} //end if logged in

//IF SUBMIT BUTTON PRESSED
if(isset($_POST ['submit'])) {

if(!$_POST['us ername']) die("Erro r: You must enter your username before logging in.";
if(!$_POST['pa ssword']) die("Erro r: You must enter your password before logging in.";


//set cookie if checked
if(!empty($_POS T['stay_in']) ) {
$joined =''.$_POST[' username'].'[ ]'.md5($_POST[ 'password']). '';
setcookie('log in_cookie', $joined, time()+3600, '/', 'main.php');
} //end if

//verify user...
$get_user = mysql_query(&q uot;SELECT * FROM `members` WHERE username = '".$_POS T['username'] ."' AND

user_password = '".md5($ _POST['passwor d'])."' ";
$q = mysql_fetch_obj ect($get_user);
if(!$q) die("< font size='2' face='verdana '><b>L ogin Failure: An error occured, please verify your username and password are correct."< img src=http://www. allsyntax.com/f orums/images/sm ilies/wink.gif border=0>;

//set session variables
$_SESSION['log ged_in'] = 1;
$_SESSION['use rname'] = $_POST['userna me'];
$_SESSION['pas sword'] = $_POST['passwo rd'];
session_write_c lose();

header("L ocation: main.php"< img src=http://www. allsyntax.com/f orums/images/sm ilies/wink.gif border=0>;

} else {
//show login form
?>
<form name="log in" method="p ost" action="& lt;? $_SERVER['PHP_ SELF']; ?>"> ;
<table width="10 0%" align="ce nter" cellpadding=&q uot;3" cellspacing=&q uot;3" border="1 " bgcolor=" <? echo$_CONFIG[' td1']; ?>" bordercolor=&q uot;<? echo$_CONFIG[' border']; ?>" style="bo rder-collapse: collapse" >
<tr>
<tr>
<td align="ce nter" colspan=" 2" bgcolor=" <? echo$_CONFIG[' td1']; ?>"> ;
<font size="2& quot; face="ver dana"> <b>Login to your Account
</td>
</tr>
<td width="25 %,*" align="ri ght" bgcolor=" <? echo$_CONFIG[' td3']; ?>"> ;
<font size="2& quot; face="ver dana"> <b>Userna me:
</td>
<td bgcolor=" <? echo$_CONFIG[' td2']; ?>"> ;
<input type="tex t" id="usern ame" name="use rname"> ;
</td>
</tr>
<tr>
<td align="ri ght" bgcolor=" <? echo$_CONFIG[' td3']; ?>"> ;
<font size="2& quot; face="ver dana"> <b>Passwo rd:
</td>
<td bgcolor=" <? echo$_CONFIG[' td2']; ?>"> ;
<input type="pas sword" id="passw ord" name="pas sword"> ;
</td>
</tr>
<tr>
<td align="ri ght" bgcolor=" <? echo$_CONFIG[' td3']; ?>"> ;
<font size="2& quot; face="ver dana"> <b>Submit :
</td>
<td bgcolor=" <? echo$_CONFIG[' td2']; ?>"> ;
<input type="sub mit" value="Su bmit" name="sub mit" id="submi t">
</td>
</tr>
</table>
</form>
<?
}//end else
include "footer.p hp";
?>



That should give you an idea what to do with Locations: hope it helps ya out.



Edited at 03:45:54 am on 06/12/07


Photo Hosting Scripts? It's what I do....

    Viewed: 33,237 Times | Reply to This | To top
  This user is offline  drewage
  Subject: "re: Complete Member System Sample" Posted: @ 1:25 am on Jun 12 2007    
Member #: 338
Rank: User - (3)
Since: 06/11/07
Posts: 3

thanks, yes i know about that part - i left those sections vanilla since i wanted to show which parts i've touched and which I haven't. Anyway, the location: is a separate issue from the actual problem I have which is the logout and destroying of the session.. any further input is appreciated!




    Viewed: 33,233 Times | Reply to This | To top
  This user is offline  drewage
  Subject: "re: Complete Member System Sample" Posted: @ 1:47 am on Jun 12 2007    
Member #: 338
Rank: User - (3)
Since: 06/11/07
Posts: 3

oops i missed your post bsod, i'll look into your suggestions.

gravy where on your site can i get your beta code if you've posted?

thx all




    Viewed: 33,227 Times | Reply to This | To top
  This user is offline  duece
  Subject: "re: Complete Member System Sample ?..." Posted: @ 6:20 am on Jun 15 2007    
Member #: 341
Rank: User - (14)
Since: 06/12/07
Posts: 14

I want to say thanks for the great tut on this topic as well as all the help in getting started.

I have ran through it and run into a few problems as well as have a couple of questions.

In reference to the db_connect example

Code:

<?php
$database[dbser ver]="web site.com" ;
$database[dbuse r]="user ";
$database[dbnam e]="datab ase_1"; $database[dbpas s]="passw ord";
$table ="table1 ";

$connect = mysql_connect($ database['dbse rver'], $database['dbu ser'], $database['dbp ass']);

$select= mysql_select_db ($database['db name']);
?>

What is the function of $table="t able1";

Also I have followed the tutorial as laid out with minor changes. I can create a new member no problem. However when the go to log in it will not work. Shows the following error

Login Failure: An error occured, please verify your username and password are correct.

My login.php
Code:
<?php
ob_start();
require_once(' ../www/connect. php');

if(isset($_SESS ION['username ']) && isset($_SESSION ['password']) ) {
//REDIRECT TO USERS PROFILE...
header("L ocation: ../www/temp.htm l";
} //end if logged in

//IF SUBMIT BUTTON PRESSED
if(isset($_POST ['submit'])) {

if(!$_POST['us ername']) die("Erro r: You must enter your username before logging in.";
if(!$_POST['pa ssword']) die("Erro r: You must enter your password before logging in.";


//set cookie if checked
if(!empty($_POS T['stay_in']) ) {
$joined =''.$_POST[' username'].'[ ]'.md5($_POST[ 'password']). '';
setcookie('log in_cookie', $joined, 2147483647, '/', 'www.yoursite. com');
} //end if



//verify user...
$get_user = mysql_query(&q uot;SELECT * FROM `familymembers` WHERE username = '".$_POS T['username'] ."' AND
password = '".md5($ _POST['passwor d'])."' ";
$q = mysql_fetch_obj ect($get_user);
if(!$q) die("Logi n Failure: An error occured, please verify your username and password are correct."< img src=http://www. allsyntax.com/f orums/images/sm ilies/wink.gif border=0>;

//set session variables
$_SESSION['log ged_in'] = 1;
$_SESSION['use rname'] = $_POST['userna me'];
$_SESSION['pas sword'] = $_POST['passwo rd'];
session_write_c lose();

header(". ./www/mypage.ph p";

} else {
//show login form
?>
<form name="log in" method="p ost" action="& lt;?php $_SERVER['PHP_ SELF']; ?>"> ;
<table> <tr>
<td>Usern ame:<input type="tex t" id="usern ame" name="use rname"> ;</td>
</tr>
<tr>
<td>Passw ord:<input type="pas sword" id="passw ord" name="pas sword"> ;</td>
</tr>
<tr>
<td>Submi t: <input type="sub mit" value="Su bmit" name="sub mit" id="submi t">< ;/td>
</tr>
<tr>
<td>Remem ber? <input type="che ckbox" name="sta y_in[]" checked=" yes">& lt;/td>
</tr>
</table>< br /> </form> <?php
}//end else
?>



I have looked at the contents of the table and the pass word is not what I entered in my registration.ph p . It is something else, which looks like it is changed due to the .md5 present in '".md5($ _POST['passwor d'])."' portion of the INSERT call.

Thanks for the help.
D



    Viewed: 33,140 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: Complete Member System Sample" Posted: @ 3:46 pm on Jun 15 2007    

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

the $table variable points to a table if you so choose. You can delete that line.

Yes, the password is encryped by the md5 function. Leave that in the database as it is. Also, the passwords will be case sensitive. Im not seeing anything in the code so far...

You need to change the "yoursite .com" to the URL of your website. I see it in the login code where you set a cookie.




-bs0d | AllSyntax.com

    Viewed: 33,132 Times | Reply to This | To top
  This user is offline  Finest
  Subject: "re: Complete Member System Sample" Posted: @ 4:17 pm on Jun 23 2007    
Member #: 354
Rank: User - (1)
Since: 06/22/07
Posts: 1

Ok i belive that i have the correct format for the logout.php script. At first i had the same 2 similar problems as duece and corrected based on your advice. The problem is not that when i hit the logout link i dont think that it logs out instead im am redirected to my home page which is not my index page. i also set a part of my page to echo the $user but that is blank.. before i loged in i said welcome guest but now i cant tell if its still working dut to the logout problem. please advise.. this is the code for the whole logout page.


Code:


<?
ob_start();
session_start( );
require_once($_ SERVER['DOCUME NT_ROOT'].'/d b_connect.php' );
require_once(' db_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;;
}
?>

<?php



/**

* Page which logs a user out of the system. They are then redirected

* back to the forum listing page.

*

* @package freeBulletin

*/




$_SESSION['log ged_in'] = 0;

setcookie('log in_cookie', "", time() - 60, '/', '.erotiqgarden .com');

session_destroy ();
header("L ocation: http://www.erot iqgarden.com&q uot;
?>


Adding the ob_start does fis the other errors but it seem that no one ever logs out. i have also added the users online script to my home page and it always shows that there is one memeber logged on which is also funny because when i first encountered this problem yesterday before i logged in i said hello guest and after it logged in it just says hello. this morning it said hello guest on the home page then i just said let me hit logout and see what happens. well it seems that there is still 1 user logged in with out me having to login. can anyone please stear me in the direction of what can be wrong. Thanks. Also MANY many thanks to your tutorial it has been very helpful. i will soon be rebuilding my site using seperate files for easy site management



Edited at 05:54:30 pm on 06/23/07


New is easy when i learn it. :-)

    Viewed: 32,927 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: Complete Member System Sample" Posted: @ 5:54 pm on Jun 23 2007    

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

Maybe thats the problem? Are you using the header code on every page of your site? This allows users to be recognized.

Login to phpMyAdmin and see who is in the users_online table. Also, you shouldn't even display a logout link, unless they are logged in.

Make sure you are consistent with variables to identify users. The users online script may have used $user, but to identify a person online, like: "Hello, Finest" that would use $_SESSION['use rname'] based on the Complete Members System article.




-bs0d | AllSyntax.com

    Viewed: 32,919 Times | Reply to This | To top
  This user is offline  WintersDance
  Subject: "re: Complete Member System Sample" Posted: @ 3:36 pm on Jun 24 2007    

Member #: 353
Rank: User - (27)
Since: 06/19/07
Posts: 36
From: California

Maybe i missed it being said, but if you wanted to logout the user AND remove them from the users_online table, try something like this:

Code:


<?php
ob_start();
require_once(' db_connect.php ');
session_start() ;


$_SESSION['log ged_in'] = 0;
$user = $_SESSION['use rname'];

$delete_old = mysql_query(&q uot;DELETE FROM `users_online` WHERE name = '$user'" ;); //Simple enough, remove them users_online table.

setcookie('log in_cookie', "", time() - 60, '/', 'www.your-webs ite-domain.com '); //change your-website-do main to the name of yours. Must match the same one you used in setting the cooikes.

session_destroy (); //Destroy the users session and redirect to the page of your choice below.
header("L ocation: login.php" ;); // Change login.php to what ever page you wish.
?>



Note, I did setup the script to only log registered members and display who is online. If they're not registered, it displays "No Registered Members online". It can also display the name of each registered member too.

Hope this helps.




wintersdance |     Viewed: 32,900 Times | Reply to This | To top
  This user is offline  gravy
  Subject: "re: Complete Member System Sample" Posted: @ 12:55 am on Jun 25 2007    

Member #: 294
Rank: User - (63)
Since: 03/07/07
Posts: 66
From: MN

  WintersDance said...

< i> Maybe i missed it being said, but if you wanted to logout the user AND remove them from the users_online table, try something like this:
<BR><f ont size=1><u >Code:</u ><BR>& lt;div name="div _box" class="di vCode"> ;
<?php
ob_start();
require_once(' db_connect.php ');
session_start() ;


$_SESSION['log ged_in'] = 0;
$user = $_SESSION['use rname'];

$delete_old = mysql_query(&q uot;DELETE FROM `users_online` WHERE name = '$user'" ; //Simple enough, remove them users_online table.

setcookie('log in_cookie', "", time() - 60, '/', 'www.your-webs ite-domain.com '); //change your-website-do main to the name of yours. Must match the same one you used in setting the cooikes.

session_destroy (); //Destroy the users session and redirect to the page of your choice below.
header("L ocation: login.php" ; // Change login.php to what ever page you wish.
?>



Note, I did setup the script to only log registered members and display who is online. If they're not registered, it displays "No Registered Members online". It can also display the name of each registered member too.

Hope this helps.


So you made the users online reflect the names of the actual users online instead of a number.....? I WANT THAT! Can you share the code involved for that, if not thats cool I will write it out.




Photo Hosting Scripts? It's what I do....

    Viewed: 32,886 Times | Reply to This | To top
  This user is offline  retarded
  Subject: "re: Complete Member System Sample" Posted: @ 4:40 am on Jun 26 2007    
Member #: 357
Rank: User - (18)
Since: 06/26/07
Posts: 22

hmm.. im still having one major problem..
i can register an account.. but im having problems with the actual login...
here are the errors..
Warning: Cannot modify header information - headers already sent by (output started at /home/gamereli/ public_html/log in.php:8) in /home/gamereli/ public_html/log in.php on line 25

Warning: Cannot modify header information - headers already sent by (output started at /home/gamereli/ public_html/log in.php:8) in /home/gamereli/ public_html/log in.php on line 39
=============== =============== =============== ===============
Here is the code to my login script.. please help me if you can.


Code:

<!DOCTYPE html PUBLIC "-//W3C// DTD XHTML 1.0 Transitional//E N" "http://w ww.w3.org/TR/xh tml1/DTD/xhtml1 -transitional.d td">
<html xmlns="ht tp://www.w3.org /1999/xhtml&qu ot;>
<head>
<meta http-equiv=&qu ot;Content-Type " content=" text/html; charset=utf-8& quot; />
<title>Ga merElites.com/L ogin</title& gt;
</head>

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

if(isset($_SESS ION['username ']) && isset($_SESSION ['password']) ) {
//REDIRECT TO USERS PROFILE...
header("L ocation: http://www.game relites.com/&q uot;
} //end if logged in
//IF SUBMIT BUTTON PRESSED
if(isset($_POST ['submit'])) {

if(!$_POST['us ername']) die("Erro r: You must enter your username before logging in.";
if(!$_POST['pa ssword']) die("Erro r: You must enter your password before logging in.";

//set cookie if checked
if(!empty($_POS T['stay_in']) ) {
$joined =''.$_POST[' username'].'[ ]'.md5($_POST[ 'password']). '';
setcookie('log in_cookie', $joined, 2147483647, '/', 'http://www.ga merelites.com' );
} //end if
//verify user...
$get_user = mysql_query(&q uot;SELECT * FROM `members` WHERE username = '".$_POS T['username'] ."' AND

user_password = '".md5($ _POST['passwor d'])."' ";
$q = mysql_fetch_obj ect($get_user);
if(!$q) die("Logi n Failure: An error occured, please verify that your username and password are correct."< img src=http://www. allsyntax.com/f orums/images/sm ilies/wink.gif border=0>;
//set session variables
$_SESSION['log ged_in'] = 1;
$_SESSION['use rname'] = $_POST['userna me'];
$_SESSION['pas sword'] = $_POST['passwo rd'];
session_write_c lose();

header("L ocation: http://www.game relites.com&qu ot;
} else {
//show login form
?>
<form name="log in" method="p ost" action="& lt;? $_SERVER['PHP_ SELF']; ?>"> ;
<table>
<tr>
<td>Usern ame:<input type="tex t" id="usern ame" name="use rname"> ;</td>
</tr>
<tr>
<td>Passw ord:<input type="pas sword" id="passw ord" name="pas sword"> ;</td>
</tr>
<tr>
<td>Submi t: <input type="sub mit" value="Su bmit" name="sub mit" id="submi t">< ;/td>
</tr>
<tr>
<td>Remem ber? <input type="che ckbox" name="sta y_in[]" checked=" yes">& lt;/td>
</tr>
</table>
</form>
<?
}//end else
?>



</body>
</html>


Im verry curious about this line 2147483647, '/', 'http://www.ga merelites.com' ); where does that number come from 2147483647
=============== =============== =============== =============== ====
i apreciate any feedback that i get



Edited at 05:45:56 am on 06/26/07


    Viewed: 32,855 Times | Reply to This | To top
  This user is offline  retarded
  Subject: "re: Complete Member System Sample" Posted: @ 5:18 am on Jun 26 2007    
Member #: 357
Rank: User - (18)
Since: 06/26/07
Posts: 22

ok... now i know why people charge like crazy to do PHP. lol



Edited at 05:44:36 am on 06/26/07


    Viewed: 32,852 Times | Reply to This | To top
  This user is offline  WintersDance
  Subject: "re: Complete Member System Sample" Posted: @ 6:20 am on Jun 26 2007    

Member #: 353
Rank: User - (27)
Since: 06/19/07
Posts: 36
From: California

For Gravy:
The first thing you need to do is add an column in the users_online table called 'username' and make it NOT_NULL. Then when your member logs in to the site, the following code needs to be on the login.php page:


Code:


//set session variables
$_SESSION['log ged_in'] = 1;
$_SESSION['use rname'] = $_POST['userna me'];
$_SESSION['pas sword'] = $_POST['passwo rd'];
session_write_c lose();

$user = $_SESSION['use rname']; //We will add username once they login.
$ip = $_SERVER['REMO TE_ADDR'];
$time = time();

$ip_check = 'SELECT ip FROM `users_online` WHERE ip = \''.$_SERVER ['REMOTE_ADDR '].'\'';
$ip_query = mysql_query($ip _check);
$num_rows = mysql_num_rows( $ip_query);

if(!$num_rows) { //if no rows, meaning no ip's in db matched theirs, we will add them.
$insert_new = mysql_query(&q uot;INSERT INTO `users_online` (ip, time, name) VALUES ('$ip', '$time', '$user')&quo t;
} //end if NOT THERE



Then when I want to display the name, the DB will only pull up records if the username was entered in the field.


Code:

//show the number of people online now....
$id_query = @mysql_query(& quot;SELECT * FROM `users_online` ";
$users_online = mysql_num_rows( $id_query);
if($users_onlin e != '0') {
echo("&l t;BR>Number of members online: $users_online&l t;BR>"< img src=http://www. allsyntax.com/f orums/images/sm ilies/wink.gif border=0>;
}

echo("< ;BR>Who's online: ";
if ($users_online > 0) {
while($row = mysql_fetch_arr ay($id_query)) {
if($users_onlin e <= '1') {
echo ucfirst($row[' name']); //I like to use uppercase on the first letter of each name.
}
else {
echo ucfirst($row[' name'])." ;, "; }
}//end while
}
else {
echo "There are no registered members online.";
}



That's what I use for my site and it works fine ^_^



Edited at 06:43:50 am on 06/26/07


wintersdance |     Viewed: 32,842 Times | Reply to This | To top
  This user is offline  WintersDance
  Subject: "re: Complete Member System Sample" Posted: @ 6:35 am on Jun 26 2007    

Member #: 353
Rank: User - (27)
Since: 06/19/07
Posts: 36
From: California

For retarded (nice name :P )
Move the folowing to the very top of the page before any HTML is outputed:


Code:


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



then execute your HTML after it.

So it should look like this:

Code:

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

<!DOCTYPE html PUBLIC "-//W3C// DTD XHTML 1.0 Transitional//E N" "http://w ww.w3.org/TR/xh tml1/DTD/xhtml1 -transitional.d td">
<html xmlns="ht tp://www.w3.org /1999/xhtml&qu ot;>
<head>
<meta http-equiv=&qu ot;Content-Type " content=" text/html; charset=utf-8& quot; />
<title>Ga merElites.com/L ogin</title& gt;
</head>

<body>
<?php

if(isset($_SESS ION['username ']) && isset($_SESSION ['password']) ) {
//REDIRECT TO USERS PROFILE...
header("L ocation: http://www.game relites.com/&q uot;;
} //end if logged in
//IF SUBMIT BUTTON PRESSED
if(isset($_POST ['submit'])) {

if(!$_POST['us ername']) die("Erro r: You must enter your username before logging in.";
if(!$_POST['pa ssword']) die("Erro r: You must enter your password before logging in.";

//set cookie if checked
if(!empty($_POS T['stay_in']) ) {
$joined =''.$_POST[' username'].'[ ]'.md5($_POST[ 'password']). '';
setcookie('log in_cookie', $joined, 2147483647, '/', 'http://www.ga merelites.com' );
} //end if
//verify user...
$get_user = mysql_query(&q uot;SELECT * FROM `members` WHERE username = '".$_POS T['username'] ."' AND

user_password = '".md5($ _POST['passwor d'])."' ";
$q = mysql_fetch_obj ect($get_user);
if(!$q) die("Logi n Failure: An error occured, please verify that your username and password are correct." ;
//set session variables
$_SESSION['log ged_in'] = 1;
$_SESSION['use rname'] = $_POST['userna me'];
$_SESSION['pas sword'] = $_POST['passwo rd'];
session_write_c lose();

header("L ocation: http://www.game relites.com&qu ot;;
} else {
//show login form
?>
<form name="log in" method="p ost" action="& lt;? $_SERVER['PHP_ SELF']; ?>"> ;
<table>
<tr>
<td>Usern ame:<input type="tex t" id="usern ame" name="use rname"> ;</td>
</tr>
<tr>
<td>Passw ord:<input type="pas sword" id="passw ord" name="pas sword"> ;</td>
</tr>
<tr>
<td>Submi t: <input type="sub mit" value="Su bmit" name="sub mit" id="submi t">< ;/td>
</tr>
<tr>
<td>Remem ber? <input type="che ckbox" name="sta y_in[]" checked=" yes">& lt;/td>
</tr>
</table>
</form>
<?php
}//end else
?>

</body>
</html>



try that



Edited at 06:45:29 am on 06/26/07


wintersdance |     Viewed: 32,840 Times | Reply to This | To top
Viewing Page: 1 of 2


1 | 2 |
Next »





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