NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming > CODE
Reload this Page FullyFunctional Member System: Login/Logout, Admin Panel, Sessions, Self-Installation

CODE This forum is for posting code snippets and example scripts that aren't quite tutorials, but could be useful for others. You may post code snippets and/or completed scripts that you've written and want to share here.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 08-29-2005, 01:45 PM THREAD STARTER               #26 (permalink)
DNOA Member
Join Date: May 2004
Posts: 5,040
mholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant future
 


Autism Marrow Donor Program 9/11/01 :: Never Forget Multiple Sclerosis Adoption Alzheimer's Lou Gehrig's Disease (ALS)
That means that a PHP script has write, edit, and read permissions for that file.

Sorry that you have to make your own DB Most servers don't allow PHP to do that But it makes the table (the long and boring part) for you.

EDIT: Sorry noswad, missed a few last posts.

Make sure you edit your config.php file to match the user data for that database that you setup in CPanel. If it still doesn't work, I'd be happy to HELP you configure it further via IM. (AIM or YIM)


MAKE SURE YOU UPDATE YOUR SCRIPT!
(Update #2, listed near the bottom on the main topic post)
Last edited by compuXP; 08-29-2005 at 03:26 PM.
mholt is offline  
Old 09-01-2005, 06:04 PM THREAD STARTER               #27 (permalink)
DNOA Member
Join Date: May 2004
Posts: 5,040
mholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant future
 


Autism Marrow Donor Program 9/11/01 :: Never Forget Multiple Sclerosis Adoption Alzheimer's Lou Gehrig's Disease (ALS)
Another bug has been fixed, just check out how to remedy it on the first page, bottom of my topic.
mholt is offline  
Old 09-12-2005, 04:37 PM   #28 (permalink)
Senior Member
Join Date: Apr 2005
Location: Joliet, Illinois
Posts: 1,177
RageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to behold
 


Child Abuse
Nice work I fiddled & added some of my own stuff in there... Mind if I post like a 'news' section for people? It will ADD News, admins can edit/delete as well!

-RageD
RageD is offline  
Old 09-12-2005, 04:51 PM THREAD STARTER               #29 (permalink)
DNOA Member
Join Date: May 2004
Posts: 5,040
mholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant future
 


Autism Marrow Donor Program 9/11/01 :: Never Forget Multiple Sclerosis Adoption Alzheimer's Lou Gehrig's Disease (ALS)
Ah, go ahead. You can post it if you want, but save your coding for Crestin
mholt is offline  
Old 09-12-2005, 05:24 PM   #30 (permalink)
Senior Member
Join Date: Apr 2005
Location: Joliet, Illinois
Posts: 1,177
RageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to behold
 


Child Abuse
ok

Make this in a seperate file... something like installsql.php

Code:
<?php

/*
Install, because it is easier for me! :-D
*/

if (!isset($go))
{

?>
<html>
<head>
<title>Members Database Installation</title>
</head>
<body>
<center><h1>Begin Installation</h1></center>
<BR>
Welcome to the installation process.
<BR><BR>
<b>Before beginning installation, please make sure that:</b>
<ul>
<li>You have a database set up, and a user for it with permissions to at least SELECT, INSERT, DELETE, and UPDATE.</li>
<li>You have all files uploaded and config.php CHMOD'ed at 777.</li>
<li>The database you made is empty.</li>
</ul>
<BR>
<form method="post" action="?go=true">
<big><b><font color="gray">DATABASE DETAILS</font></b></big>
<BR><BR>
Please type the FULL database name (including pre- and suffixes that your web host<BR>
may add. This is usually a prefix of "YourUsername_"): <input type="text" name="dbname">
<BR><BR>
Database username (include pre- and suffixes, which are generally the same as the ones<BR>
added for the database): <input type="text" name="dbuser">
<BR><BR>
User password: <input type="password" name="dbpwd1">
<BR>
Type again: <input type="password" name="dbpwd2">
<BR><BR>
Path of config.php: <input type="text" name="path"><small><BR>
Example: If the file is at www.domain.com/members/config.php, type "members".<BR>
<font color="maroon">Do NOT add trailing or leading slashes.</font></small>
<BR><BR>
<BR><BR>
When ready to install, just press the button below.
<BR><BR>
<center><input type="submit" value="         Install         "></center>
</form>
</body>
</html>
<?php
}

if (isset($go))
{	
	
	$errstatus = 0;
	
	if (!$dbname || !$dbuser || !$dbpwd1 || !$dbpwd2 || !$path)
	{
		echo '<font color="red">You must fill out all the required fields. <a href="javascript:history.back(1)">Back</a>';
		exit;
		$errstatus = 1;
	}
	
	if ($dbpwd1 != $dbpwd2)
	{
		echo '<font color="red">The passwords do not match. <a href="javascript:history.back(1)">Back</a>';
		exit;
		$errstatus = 1;
	}
	
	@ $fp = fopen("config.php", 'w');
	
	if (!$fp)
	{
		echo '<font color="red">There was an error opening the config.php file. Make sure its CHMOD is 777 and is in the same directory as install.php. <a href="javascript:history.back(1)">Back</a>';
		exit;
		$errstatus = 1;
	}
	
	$write = "<?php
\$dbname = \"".$dbname."\";
\$dbuser = \"".$dbuser."\";
\$dbpwd = \"".$dbpwd2."\";
?>";
	//$write = $dbname.'\n'.$dbuser.'\n'.$dbpwd2;
	
	@ $go = fwrite($fp, $write);
	
	if (!$go)
	{
		echo '<font color="red">There was an error writing the config.php file. Make sure its CHMOD is 777. <a href="javascript:history.back(1)">Back</a>';
		exit;
		$errstatus = 1;
	}
	
	fclose($fp);
	
	@ $conn = mysql_connect('localhost', $dbuser, $dbpwd1);
	@ $db = mysql_select_db($dbname);
	
	if (!$db || !$conn)
	{
		echo '<font color="red">Could not connect to database. Either the DB doesn\'t exist, or the username/pwd combo supplied was invalid. <a href="javascript:history.back(1)">Back</a>';
		exit;
		$errstatus = 1;
	}
// Create News Table
	$sql = "CREATE TABLE `news` (
`id` BIGINT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
`title` VARCHAR( 30 ) NOT NULL ,
`post` VARCHAR( 30 ) NOT NULL ,
`poster` VARCHAR( 32 ) NOT NULL ,
`date` DATE NOT NULL ,
PRIMARY KEY ( `id` )
) TYPE = MYISAM COMMENT = 'Stores all the news.';";

	@ $result = mysql_query($sql);
	
	if (!$result)
	{
		echo '<font color="red">Error adding table and columns to the database. Error returned is: '.mysql_error().' <a href="javascript:history.back(1)">Back</a>';
		exit;
		$errstatus = 1;
	}
	

?>
<html>
<head>
<title>News Database Installation</title>
</head>
<body>
<center><h1>Installation Results</h1></center>
<BR>
<?php if ($errstatus == 1) { ?><font color="red"><b>There was an error during installation.</b></font><?php } else { ?>
<font color="green"><b>Installation successful!</b></font>

<BR><BR>

SQL for News Installed!
<BR><BR>
<a href="index.html">Login</a> to manage add news, etc!
<?php } ?>
</body>
</html>
<?php
}
?>
Replace admin_home.php with this:
????: NamePros.com http://www.namepros.com/code/113786-fullyfunctional-member-system-login-logout-admin.html
Code:
<?php

//Start the session

session_start();

include("dbconn.php");
//Make sure the user is logged in.
include("checklogin.php");
//Now make sure they're an admin.
include("checkadmin.php");

//Get number of users.

$q = "SELECT * FROM users";
$s = "SELECT * FROM news";
$r = mysql_query($q);
$t = mysql_query($s);

?>
<HTML>
<TITLE>Administrator Page</TITLE>
<BODY>
This is the Administration page!  Only Administrators here! :) <a href="admin_postnews.php">Post News</a>
<BR><BR>
<b>Number of news items: <?php echo(mysql_num_rows($t)) ?></b>
<BR><BR>
<b><big>List</big></b>
<BR><BR>
<b>ID | Title | Date | Poster | Options</b>
<BR>
<hr>
<?php

while ($row = mysql_fetch_array($t))
{
	//Stripslashes takes away extra escape characters \ from the string.
        $id = stripslashes($row['id']);
	$title = stripslashes($row['title']);
        $post = stripslashes($row['post']);
	$date = stripslashes($row['date']);
	$poster = stripslashes($row['poster']);
?>
<?php echo($id) ?> | <?php echo($title) ?> | <?php echo($date) ?> | <?php echo($poster) ?> | <a href="admin_editnews.php?id=<?php echo($id) ?>">Edit Post</a> -- <a href="admin_delete.php?id=<?php echo($id) ?>">Delete</a><BR>
<hr>
<?php
}
?><br><br>
<b>Number of users: <?php echo(mysql_num_rows($r)) ?></b>
<BR><BR>
<b><big>List</big></b>
<BR><BR>
<b>Name | Username | Number of Logins | Permissions | Options</b>
<BR>
<hr>
<?php

//Now, this is a practical example of looping
//while the results are retrieved.
//Check it out!

while ($row = mysql_fetch_array($r))
{
	//Stripslashes takes away extra escape characters \ from the string.
	$name = stripslashes($row['name']);
	$uname = stripslashes($row['username']);
	$numlogins = stripslashes($row['num_logins']);
	$per = stripslashes($row['permissions']);
	$id = $row['id'];
?>
<?php echo($name) ?> | <?php echo($uname) ?> | <?php echo($numlogins) ?> | <?php echo($per) ?> | <a href="admin_edit.php?id=<?php echo($id) ?>">Edit User</a> -- <a href="admin_delete.php?id=<?php echo($id) ?>">Delete</a><BR>
<hr>
<?php
}
?>


<BR>
<a href="main.php">Main</a>
</body>
</html>
add two more pages:
????: NamePros.com http://www.namepros.com/showthread.php?t=113786

news.php:
Code:
<?php
/* News Addon by RageD 
© TeamXero 2005
*/
include_once("dbconn.php");
?>
<a href=admin_postnews.php>Add News Item</a><br><br>
<?php
$s = "SELECT * FROM news";
$t = mysql_query($s);
echo "There are ";
echo(mysql_num_rows($t));
echo " news items!";

while ($row = mysql_fetch_array($t))
{
	//Stripslashes takes away extra escape characters \ from the string.
        $id = stripslashes($row['id']);
	$title = stripslashes($row['title']);
        $post = stripslashes($row['post']);
	$date = stripslashes($row['date']);
	$poster = stripslashes($row['poster']);
?>

<HTML>
<TITLE>News</TITLE>
<BODY><br><br>
<b><?php echo($title) ?></b> Posted By - <?php echo($poster) ?> on <?php echo($date) ?><br><br> <?php echo($post) ?><br><br>
</BODY>
</HTML>
<?php
}
?>
-and-

admin_postnews.php:
Code:
<?php
session_start();
include("checklogin.php");
include("checkadmin.php");

/* CMS Made by RageD for TeamXero DevTeam Website
© Copyright 2005 TeamXero
*/

if (!isset($go))
{
?>

<html>
<head>
<title>Member Registration</title>
</head>
<body>
<center><h1>Register</h1></center>
<BR>

All fields required unless marked.
<BR><BR>
<form method="post" action="?go=true">
Title: <input type="text" name="title">
<BR><BR>
Message: <input type="text" name="post">
<BR><BR>
<input type="submit" value="Submit">
</form>
<BR><BR>
<a href="index.html">Back to Home</a>
</body>
</html>
<?php
}

if (isset($go))
{
	
	//connect to database.
	
	include("dbconn.php");
	

	//Current date...
	$date = date("m-d-Y");

       //Poster is Username
       $poster= $_SESSION['username'];
	
	//Insert!
	
	
	$q = "INSERT INTO news VALUES(NULL, '$title', '$post', '$date', '$poster')";
	@ $result = mysql_query($q);
	
	if (!$result)
	{
		do_error('Could not insert into database. Error returned is '.mysql_error());
	}
	
	
?>
<html>
<head>
<title>Post Successful!</title>
</head>
<body>
<center><h1>Successful</h1></center>
<BR>

You have successfully posted!

<BR><BR>
<a href="news.php">Go to News</a><br>
<a href="admin_home.php">Back to Admin Page</a>
</body>
</html>
<?php
}
?>
-and-

admin_editnews.php:
Code:
<?php

/* CMS Made by RageD for TeamXero DevTeam Website
© Copyright 2005 TeamXero
*/

//Start the session

session_start();

include("dbconn.php");
//Make sure the user is logged in.
include("checklogin.php");
//Now make sure they're an admin.
include("checkadmin.php");

if (!$id)
{
	echo("ERROR > No POST ID found.");
	exit;
}

if (!isset($go))
{
	
	$q = "SELECT * FROM users WHERE id='$id' LIMIT 1";
	$r = mysql_query($q);
	
	while ($row = mysql_fetch_array($r))
	{
                $id = stripslashes($row['id']);
		$title = stripslashes($row['title']);
		$poster = stripslashes($row['poster']);
		$post = stripslashes($row['post']);
		$age = $row['date'];
	}


?>
<html>
<head>
<title>Admin Panel</title>
</head>
<body>
<center><h1>Editing <?php echo "$title"; ?></h1></center>
<BR>
<form method="post" action="?go=true&id=<?php echo($id) ?>">

ID: <input type="text" name="name" value="<?php echo($id) ?>">
<BR><BR>
Title: <input type="text" name="title" value="<?php echo($title) ?>">
<BR><BR>
Date: <input type="text" name="date" value="<?php echo($date) ?>" size="75">
<BR><BR>
Post: <input type="text" name="post" value="<?php echo($post) ?>">
<BR><BR>
Poster: <input type="text" name="poster" value="<?php echo($poster) ?>">
<BR><BR>
<input type="submit" value="Append Changes">
</form>
<BR><BR>

<a href="admin_home.php">Cancel</a>
</body>
</html>
<?php
}

if (isset($go))
{
	if (!$title || !$post || !$id)
	{
		echo("You have to fill out a username and select the permission, or missing ID.");
		exit;
	}
	
	//Begin updates.
	
	mysql_query("UPDATE news SET ID='$id',title='$title',date='$date',post='$post',poster='$poster' WHERE id='$id' LIMIT 1");
	
	}

?>

<html>
<head>
<title>Admin Panel</title>
</head>
<body>
<center><h1>Post Edited</h1></center>
<BR>
News has been successfully edited.

<a href="admin_home.php">Back</a>
</body>
</html>
-RageD
RageD is offline  
Old 09-15-2005, 06:39 PM THREAD STARTER               #31 (permalink)
DNOA Member
Join Date: May 2004
Posts: 5,040
mholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant future
 


Autism Marrow Donor Program 9/11/01 :: Never Forget Multiple Sclerosis Adoption Alzheimer's Lou Gehrig's Disease (ALS)
Thanks for that addition, RageD!
mholt is offline  
Old 09-29-2005, 04:22 PM   #32 (permalink)
NamePros Regular
Join Date: Mar 2005
Posts: 442
paaaaaaaaaa is a jewel in the roughpaaaaaaaaaa is a jewel in the roughpaaaaaaaaaa is a jewel in the rough
 



Originally Posted by Zubair1
Q-) Do you know how i can know when a user closes their browser
as i am having a lot of trouble with and also researched on it alot too, though i still didn't get any good results, what i am wanting to do is put the sessions data on the database i check for and retrieve all the session information from the database
like when a person clicks the logout link, they logout their sessions are ended, (destroyed) but what if the user never logs out, they're sessions are lost some where in the database, so i want to know when that happens (I.E When the user closes their browser), so i can tell the database to delete all the session information about that person, (got any solutiions for this bro)?
????: NamePros.com http://www.namepros.com/showthread.php?t=113786

thanks in advance :d
Im not sure how most people go about this but I would would do it like this:

When a person enters a page logged in or not, I would record their ip address, user info and the time in a table in my database. The ip address would be so they dont double log. Then when the next person visits they spark the script up which searches the database for who was online over the past 15 minutes and display these as online on your page. The rest get deleted.
__________________
Please add to my rep points if i was helpful. Thanks.

Content management system and online shop software
paaaaaaaaaa is offline  
Old 11-16-2005, 10:48 AM THREAD STARTER               #33 (permalink)
DNOA Member
Join Date: May 2004
Posts: 5,040
mholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant future
 


Autism Marrow Donor Program 9/11/01 :: Never Forget Multiple Sclerosis Adoption Alzheimer's Lou Gehrig's Disease (ALS)
Would anybody want a live demo of this script again?
mholt is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
May Script Installation Special--Chance for free webhosting iidavidii Scripts For Sale 0 05-04-2004 12:44 PM
PPC scripts for sale morpheus666 Scripts For Sale 1 03-20-2004 11:15 AM
2 PPC sites with design morpheus666 Web Development Wanted 1 02-28-2004 04:40 AM
2 PPC scripts for sale morpheus666 Scripts For Sale 2 02-28-2004 04:39 AM

 
All times are GMT -7. The time now is 04:33 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger