Web Hosting Deals Holiday Logo Design Webcam Chat Website Header Templates Register domain Search Engine Optimisation Web Hosting
Go Back   Talk Mania Forum > Tutorials > PHP / Perl / Java / JavaScript / CGI Tutorials

PHP / Perl / Java / JavaScript / CGI Tutorials PHP / Perl / Java / JavaScript / CGI Tutorials Please do not use this Forum to advertise your site or to link to tutorials.

 Image
Buy Sell Downloads

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-16-2007, 06:51 PM
Senior Member
 
Join Date: May 2007
Posts: 181
Blog Entries: 1
skyfe is on a distinguished road
[BETA]Simple toplist site

Hello,
I've made a simple toplist system(BETA yet), I'll post here the codes (free open source), tell me what you think about it ^^. Enjoy!
tell me if you found any bugs, or have any comments/tips And it's a BETA version yet so... I posted it in more posts caus 1 post may not be longer than 10000 chars

directory toplist:
index.php
in.php
out.php
installer.php
directory toplist\modules:
idx.php
config.php
login.php
vote.php
add.php
last.php
contact.php
profile.php
lost.php
forum.php
directory css:
hyperlinks.css
directory images
all images... see below page

directory: toplist

index.php
Quote:
<?php
session_start();
?>
<html>
<head>
<style type="text/css">
<!--
.box {
background-color: #BABABA;
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
border: 1px solid #BABABA;
}
-->
</style>
</head>
<body>
<?php
include("modules/config.php");
if(isset($_GET['act']) && !empty($_GET['act'])) {
$id = $_GET['act'];
}else{
$id = "idx";
}
?>
<table border='0' width='90%' align='center'>
<tr>
<td width='100%' bgcolor='#000000'> <img src='images/header.jpg' width='100%'> </td>
</tr>
<tr>
<td align='center'> <a href='index.php'>home</a> | <a href='index.php?act=add'>join toplist</a> | <a href='index.php?act=login'><?php if(isset($_SESSION['logged']) && !empty($_SESSION['logged'])) { ?> logout <?php }else{ ?>login <?php } ?></a> | <?php if(isset($_SESSION['logged']) && !empty($_SESSION['logged'])) { ?> <a href='index.php?act=profile'>profile</a> | <?php }else{ } ?> <a href='index.php?act=vote'>vote</a> | <a href='index.php?act=last'>last submited</a> | <a href='index.php?act=forum'>forum</a> | <a href='index.php?act=contact'>contact</a> | </td>
</tr>
</table>
<p><br>
<?php
include("modules/".$id.".php");
?>
</body>
</html>
this will include the page which was giving in the url ( index.php?act=page )
and will set a header above it.

in.php
Quote:
<?php
include("modules/config.php");
if(isset($_GET['site']) && !empty($_GET['site'])) {
$ip = $_SERVER['REMOTE_ADDR'];
if(mysql_num_rows(mysql_query("SELECT id FROM votes WHERE ip = '".$ip."' && site = '".$_GET['site']."' ")) > 0) {
$site_name= mysql_query("
SELECT
name
FROM
sites
WHERE
id = '".$_GET['site']."'
");
while($rs = mysql_fetch_assoc($site_name)) {
$site_n = $rs['name'];
}
echo "<table align='center'>You succesfully voted for <b>".$site_n."</b></table>";
}else{
$add_in = mysql_query("
UPDATE
sites
SET
votes = votes + 1
WHERE
id = '".$_GET['site']."'
")or die(mysql_error());
$add_vote = mysql_query("
INSERT INTO
votes(
site,ip
)VALUES(
'".$_GET['site']."',
'".$ip."'
)
")or die(mysql_error());
$site_name= mysql_query("
SELECT
name
FROM
sites
WHERE
id = '".$_GET['site']."'
");
while($rs = mysql_fetch_assoc($site_name)) {
$site_n = $rs['name'];
}
echo "<table align='center'>You succesfully voted for <b>".$site_n."</b></table>";
}
}
This system lets users vote for sites, and is anti-cheat (will check the users ip first (if that ip wasn't found in votes for that site, then add the vote, else denied)).

out.php
Quote:
<?php
include("modules/config.php");
$site_id = $_GET['id'];
$query = mysql_query("
UPDATE
sites
SET
hits = hits + 1
WHERE
id = '$site_id'
")or die(mysql_error());
$site1 = mysql_query("
SELECT
url
FROM
sites
WHERE
id = '$site_id'
")or die(mysql_error());
while($row = mysql_fetch_assoc($site1)) {
?>
<meta content='0; URL=<?php echo $row['url']; ?>' http-equiv='Refresh' />
<?php
}
?>
This system checks which site is clicked one/puted into the url and loads it, also it adds a "out" count to the database.

installer.php
Quote:
<?php
//* This will install the database(toplist), please first configurate the config,php in the directory modules *//
include("modules/config.php");
if(isset($_POST['submit'])) {
echo "<b>Creating tables...</b><p>";
$create_table1 = "CREATE TABLE sites (
id int(250) NOT NULL auto_increment,
name varchar(100) NOT NULL,
url varchar(250) NOT NULL,
banner varchar(250) NOT NULL,
description varchar(250) NOT NULL,
author varchar(75) NOT NULL,
votes int(250) NOT NULL,
hits int(250) NOT NULL,
password varchar(25) NOT NULL,
ip varchar(25) NOT NULL,
email varchar(150) NOT NULL,
PRIMARY KEY (id)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
$create_table2 = "CREATE TABLE votes (
id int(250) NOT NULL auto_increment,
site varchar(100) NOT NULL,
ip varchar(20) NOT NULL,
PRIMARY KEY (id)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2";
$query_table1 = mysql_query($create_table1)or die('<font color=red>ERROR: coud not create</font>');
echo '<font color=green>Table sites succesfully created!<br>';
$query_table2 = mysql_query($create_table2)or die('<font color=red>ERROR: could not create table 2</font>');
echo '<font color=green>Table votes succesfully created!<br>';
}else{
?>
<form method='POST' action='installer.php'>
<input type='submit' name='submit' value='create database'>
</form>
<?php
}
?>
Run this file once you configurated the config.php, it will create those tables you need.


Last edited by skyfe; 06-24-2007 at 09:23 AM.
Reply With Quote
  #2 (permalink)  
Old 05-16-2007, 06:54 PM
Senior Member
 
Join Date: May 2007
Posts: 181
Blog Entries: 1
skyfe is on a distinguished road
directory: toplist\modules

idx.php

Quote:
<table style='border:1px solid #BABABA;' width='90%' cellspacing='0' cellpadding='4' align='center'>
<tr>
<td background='images/b1.jpg' style='border-bottom:1px solid #BABABA;' width='5%'><font color='#FFFFFF'> # </font></td>
<td background='images/b1.jpg' style='border-bottom:1px solid #BABABA;' width='80%' height='29' align='center'><font color='#FFFFFF'> Site </font> </td>
<td background='images/b1.jpg' style='border-bottom:1px solid #BABABA;' width='7.5%'> <font color='#FFFFFF'> IN </font> </td>
<td background='images/b1.jpg' style='border-bottom:1px solid #BABABA;' width='7.5%'> <font color='#FFFFFF'> OUT </font> </td>
</tr>
<?php
$top_sites = mysql_query("
SELECT
*
FROM
sites
ORDER BY
'votes'
DESC LIMIT
0,10
") or die(mysql_error());
$site_rank = 0;
while($top_site = mysql_fetch_assoc($top_sites)) {
$site_rank++;
if($light == 0) {
$light = 1;
$bgcolor = "#D8D8D8";
}else{
$light = 0;
$bgcolor = "#BCBCBC";
}
?>
<tr>
<td bgcolor='<?php echo $bgcolor; ?>' width='5%' style='border-bottom:1px solid #BABABA;'> <?php echo $site_rank; ?> </td>
<td bgcolor='<?php echo $bgcolor; ?>' width='80%' style='border-bottom:1px solid #BABABA;'> <?php if(mysql_num_rows(mysql_query("SELECT banner FROM sites WHERE name = '".$top_site['name']."'")) > 0 && isset($top_site['banner']) && !empty($top_site['banner'])) { ?><img src='<?php echo $top_site['banner']; ?>'><br><?php } ?><a href='out.php?id=<?php echo $top_site['id']; ?>' target='_BLANK'><b> <?php echo $top_site['name']; ?></b></a><br> <?php echo $top_site['description']; ?> </td>
<td bgcolor='<?php echo $bgcolor; ?>' width='7.5%' style='border-bottom:1px solid #BABABA;'> <?php echo $top_site['votes']; ?> </td>
<td bgcolor='<?php echo $bgcolor; ?>' width='7.5%' style='border-bottom:1px solid #BABABA;'> <?php echo $top_site['hits']; ?> </td>
</tr>
<?php
}
$sites = mysql_query("
SELECT
*
FROM
sites
ORDER BY
'votes'
DESC LIMIT
10,50
") or die(mysql_error());
while($site = mysql_fetch_assoc($sites)) {
?>
<tr>
<td> # </td>
<td> <b> <?php echo $site['name'];?> </b> </td>
<td> <?php echo $site['votes']; ?> </td>
<td> <?php echo $site['out']; ?> </td>
</tr>
<?php
}
?>
</table>
This is the default page which will load when you go to index.php. (will show all submited sites from 1-50)

config.php

Quote:
<?php
### your database info ###
mysql_connect("localhost", "root", "password"); //localhost, your db username, your db password
mysql_select_db("toplist"); //your database name
## your email ##
$email = "bergjasper@zonnet.nl"; //set to your email
## site ##
$site['name'] = "TOPLIST"; //set this to your site name
$site['url'] = "http://62.59.224.206/programs/toplist/"; //manage this to the url to your toplist site
?>
Please configurate this correct! Do this BEFOR you launch the installer.php.

vote.php

Quote:
<?php
if(isset($_GET['site']) && !empty($_GET['site'])) {
$ip = $_SERVER['REMOTE_ADDR'];
if(mysql_num_rows(mysql_query("SELECT id FROM votes WHERE ip = '".$ip."' && site = '".$_GET['site']."' ")) > 0) {
$site_name= mysql_query("
SELECT
name
FROM
sites
WHERE
id = '".$_GET['site']."'
");
while($rs = mysql_fetch_assoc($site_name)) {
$site_n = $rs['name'];
}
echo "<table align='center'>You succesfully voted for <b>".$site_n."</b></table>";
}else{
$add_in = mysql_query("
UPDATE
sites
SET
votes = votes + 1
WHERE
id = '".$_GET['site']."'
")or die(mysql_error());
$add_vote = mysql_query("
INSERT INTO
votes(
site,ip
)VALUES(
'".$_GET['site']."',
'".$ip."'
)
")or die(mysql_error());
$site_name= mysql_query("
SELECT
name
FROM
sites
WHERE
id = '".$_GET['site']."'
");
while($rs = mysql_fetch_assoc($site_name)) {
$site_n = $rs['name'];
}
echo "<table align='center'>You succesfully voted for ".$site_n."</table>";
}
}else{
?>
<table align='center'>
<b>I'd like to vote for:</b> <SELECT name='site' onchange='javascript: location=this.value;'>
<option value=''> select a site </option>
<?php
$site_query = mysql_query("
SELECT
*
FROM
sites
ORDER BY
id
DESC
") or die(mysql_error());
while($row = mysql_fetch_assoc($site_query)) {
?>
<option value='index.php?act=vote&&site=<?php echo $row['id']; ?>'><?php echo $row['name']; ?></option>
<?php
}
?>
</SELECT>
</table>
<table align='center'>
Only unique votes count! So please don't try to cheat!
</table>
<?php
}
?>
Vote system, lets you choose a site to vote for, only unique votes count.

add.php

Quote:
<?php
include("modules/config.php");
if(isset($_POST['submit']) && !empty($_POST['submit'])) {
if(!isset($_POST['site_name']) || empty($_POST['site_name']) ||
!isset($_POST['password']) || empty($_POST['password']) ||
!isset($_POST['site_url']) || empty($_POST['site_url'])) {
?><script language='javascript'> { alert(" *Please fill in all required fields "); } </script> <?php
}else{
if(mysql_num_rows(mysql_query("SELECT id FROM sites WHERE ip = '".$_SERVER['REMOTE_ADDR']."' ")) > 0) {
echo "<table align='center'>You can only sign up ONE site.</table>";
}else{
if($_POST['site_banner'] == 'http://' || empty($_POST['site_banner'])) {
$banner = '';
}
$query = mysql_query("
INSERT INTO
sites(
name,
url,
banner,
description,
password,
ip,
email
)VALUES(
'".$_POST['site_name']."',
'".$_POST['site_url']."',
'".$banner."',
'".$_POST['description']."',
'".$_POST['password']."',
'".$_SERVER['REMOTE_ADDR']."',
'".$_POST['email']."'
)
") or die(mysql_error());
echo "<table align='center'>Your site have succesfully been signed up!<br>
Your HTML code to vote for your site is: <br>";
$site_id = mysql_query("
SELECT
id
FROM
sites
WHERE
name = '".$_POST['site_name']."'
&&url = '".$_POST['site_url']."'
&&ip = '".$_SERVER['REMOTE_ADDR']."'
&&password = '".$_POST['password']."'
");
while($get = mysql_fetch_assoc($site_id)) {
$_SESSION['site_id'] = $get['id'];
}
?>
<textarea cols='60' rows='6' align='left'><!-- Toplist voting --><?php echo "\n"; ?>
<a href='<?php echo $site_url; ?>in.php?site=<?php echo $_SESSION['site_id'];
?>'><img src='<?php echo $site_url; ?>images/icon.jpg' border='0'></a>
<!-- End Toplist voting --></textarea>
<p>
<!-- Toplist voting --><?php echo "\n"; ?>
<a href='<?php echo $site_url; ?>in.php?site=<?php echo $_SESSION['site_id'];
?>'><img src='<?php echo $site_url; ?>images/icon.jpg' border='0'></a>
<!-- End Toplist voting -->
</table>
<?php
}
}
}else{
?>
<table align='center' style='border:1px solid #BABABA;' bgcolor='FCFCFC'><tr><td>
All fields with * are required, these fields you MUST fill in. <br>
Other fields are optional.</td></tr>
</table>
<p>
<table align='center'>
<form method='POST' action='index.php?act=add'>
<b>email* :</b> <input type='text' name='e_mail'><br>
<b>site name*:</b> <input type='text' name='site_name'><br>
<b>site description:</b> <textarea name='description'> </textarea> <br>
<b>password*</b> : <input type='password' name='password'><br>
<b>url*</b> : <input type='text' name='site_url' value='http://'><br>
<b>banner</b> : <input type='text' name='site_banner' value='http://'><br>
<input type='submit' name='submit' value='sign up'>
</form>
</table>
<?php
}
?>
Sign up form, also gives the HTML CODE for the site you signed up.

Last edited by skyfe; 05-16-2007 at 06:59 PM.
Reply With Quote
  #3 (permalink)  
Old 05-16-2007, 06:55 PM
Senior Member
 
Join Date: May 2007
Posts: 181
Blog Entries: 1
skyfe is on a distinguished road
last.php

Quote:
<?php
$last_sites = mysql_query("SELECT * FROM sites ORDER BY id DESC LIMIT 10") or die(mysql_error());
?>
<table style='border:1px solid #BABABA;' width='90%' cellspacing='0' cellpadding='4' align='center'>
<tr>
<td background='images/b1.jpg' style='border-bottom:1px solid #BABABA;' width='80%' height='29' align='center'><font color='#FFFFFF'> Site </font> </td>
<td background='images/b1.jpg' style='border-bottom:1px solid #BABABA;' width='7.5%'> <font color='#FFFFFF'> IN </font> </td>
<td background='images/b1.jpg' style='border-bottom:1px solid #BABABA;' width='7.5%'> <font color='#FFFFFF'> OUT </font> </td>
</tr>
<?php
while($lr = mysql_fetch_assoc($last_sites)) {
if($light == 0) {
$light = 1;
$bgcolor = "#D8D8D8";
}else{
$light = 0;
$bgcolor = "#BCBCBC";
}
?>
<tr>
<td bgcolor='<?php echo $bgcolor; ?>' width='80%' style='border-bottom:1px solid #BABABA;'> <a href='out.php?id=<?php echo $lr['id']; ?>' target='_BLANK'><b> <?php echo $lr['name']; ?></b></a><br> <?php echo $lr['description']; ?> </td>
<td bgcolor='<?php echo $bgcolor; ?>' width='7.5%' style='border-bottom:1px solid #BABABA;'> <?php echo $lr['votes']; ?> </td>
<td bgcolor='<?php echo $bgcolor; ?>' width='7.5%' style='border-bottom:1px solid #BABABA;'> <?php echo $lr['hits']; ?> </td>
</tr>
<?php
}
?>
Checks the last 10 submited sites.

contact.php

Quote:
<?php
if(isset($_POST['submit']) && !empty($_POST['submit'])) {
mail($email, $_POST['subject'], $_POST['message'], "From: ".$_POST['email']);
echo "<table align='center'>Message succesfully sent! We'll help you as soon as possible!</table>";
}else{
?>
<form method='POST' action='index.php?act=contact'>
<table style='border:1px solid #BABABA;' align='center'>
<tr>
<td>name:</td><td> <input type='text' name='name'> </td>
</tr>
<tr>
<td>email:</td> <td> <input type='text' name='email'> </td>
</tr>
<tr>
<td>subject:</td> <td> <input type='text' name='subject'> </td>
</tr>
<tr>
<td>message:</td> <td> <textarea cols='50' rows='6' name='message'> Put your questions/comments or other message here.</textarea></td>
</tr>
<tr>
<td colspan='2'><input type='submit' value='send' name='submit'></td>
</tr>
</table>
</form>
<?php
}
?>
Contact form...
login.php

Quote:
<?php
mysql_connect(localhost,root,2544710);
mysql_select_db(toplist);
?>
<html>
<body>
<?php
if(isset($_POST['logout'])) {
session_destroy();
echo "<table align='center'>You are succesfully logged out! click <a href='index.php'>here</a> to continue.</table>";
echo "<meta content='2; URL=index.php' http-equiv='Refresh' />";
}else{
if(isset($_SESSION['logged']) && !isset($_POST['submit'])) {
echo "<table align='center'>Welcome!";
?>
<form method='POST' action='index.php?act=login'>
<input type='submit' name='logout' value='logout' class='box'>
</form>
</table>
<?php
}else{
if(isset($_POST['submit'])) {

if(mysql_num_rows(mysql_query("SELECT name,password,id FROM sites WHERE name = '".$_POST['site_name']."' AND password = '".$_POST['password']."' ")) != 0) { //if username and password exist
if(mysql_num_rows(mysql_query("SELECT id FROM sites WHERE name = '".$_POST['site_name']."' AND password = '".$_POST['password']."' ")) != 0) { //if password and user are from the same member
$_SESSION['logged'] = "true";
$_SESSION['site'] = $_POST['site_name'];
$_SESSION['password'] = $_POST['password'];
echo "<table align='center'>You're succesfully logged in. Please wait while we redirect you...</table>";
echo "<meta content='2; URL=index.php' http-equiv='Refresh' />";
}else{
echo "<table align='center'><font color='red'>Site or password doesn't exist!</font></table>";
}
}else{
echo "<table align='center'><font color='red'>Site or password doesn't exist!</font></table>";
}
}else{

?>
<form method='POST' action='index.php?act=login'>
<table style='border-right: 1px solid #BABABA;' style='border-left: 1px solid #BABABA;' style='border-top: 1px solid #BABABA;' style='border-bottom: 1px solid #BABABA;' align='center'>
<tr>
<td colspan='2' background='images/b1.jpg' align='center' height='29'> <b><font color='#FFFFFF'> login </b></font> </td>
</tr>
<tr>
<td><b>Site name:</b></td>
<td><input type='text' name='site_name'></td>
</tr>
<tr>
<td><b>password:</b></td>
<td> <input type='password' name='password'></td>
</tr>
<tr>
<td colspan='2' align='center'><input type='submit' name='submit' class='box' value='login'></td>
</tr>
<tr>
<td colspan='2' align='center' style='border-top: 1px solid #BABABA;' background='images/b1.jpg'><font size='1'><b>coppy right © 62.59.224.206 - skyfe</font></b></td>
</tr>
</table>
</form>
<table align='center'>Lost password? Click <a href='index.php?act=lost'>here</a> <br>
New? <a href='index.php?act=add'>sign up!</a> <p></table>
<?php
}
}
}
?>
Login system xD
Reply With Quote
  #4 (permalink)  
Old 05-16-2007, 06:56 PM
Senior Member
 
Join Date: May 2007
Posts: 181
Blog Entries: 1
skyfe is on a distinguished road
profile.php

Quote:
<?php
$get_info = mysql_query("
SELECT
*
FROM
sites
WHERE
name = '".$_SESSION['site']."'
&& password = '".$_SESSION['password']."'
")or die(mysql_error());
while($row_get = mysql_fetch_assoc($get_info)) {
$_SESSION['url'] = $row_get['url'];
$_SESSION['banner'] = $row_get['banner'];
$_SESSION['description'] = $row_get['description'];
$_SESSION['in'] = $row_get['votes'];
$_SESSION['out'] = $row_get['hits'];
$_SESSION['site_id'] = $row_get['id'];
}
if(isset($_POST['submit'])) {

if(!isset($_POST['pass_update']) || empty($_POST['pass_update'])) {
$pass = $_SESSION['password'];
}else{
$pass = $_POST['pass_update'];
}

if(!isset($_POST['site_name']) || empty($_POST['site_name'])) {
$site = $_SESSION['site'];
}else{
$site = $_POST['site_name'];
}

if(!isset($_POST['description']) || empty($_POST['description'])) {
$description = $_SESSION['description'];
}else{
$description = $_POST['description'];
}
if(!isset($_POST['site_url']) || empty($_POST['site_url'])) {
$url = $_SESSION['url'];
}else{
$url = $_POST['site_url'];
}
$update_query = mysql_query("
UPDATE
sites
SET
password = '".$pass."',
name = '".$site."',
description = '".$description."',
url = '".$url."'
WHERE
name = '".$_SESSION['site']."'
&&password = '".$_SESSION['password']."'
")or die(mysql_error());
echo "<table align='center'>Profile succesfully updated!</table>";
$_SESSION['password'] = $pass;
$_SESSION['site'] = $site;
$_SESSION['url'] = $url;
$_SESSION['description'] = $description;
}else{
?>
<form method='POST' action='index.php?act=profile'>
<table align='center'>
<b><font size='6'>PROFILE</b></font><p>
site name: <input type='text' name='site_name' value='<?php echo $_SESSION['site']; ?>'><br>
site url : <input type='text' name='site_url' value='<?php echo $_SESSION['url']; ?>'> <br>
description: <textarea name='description'><?php echo $_SESSION['description']; ?></textarea><br>
password : <input type='text' name='pass_now' value='<?php echo $_SESSION['password']; ?>' disabled='enabled'> <br>
change password: <input type='password' name='pass_update'> <br>
IN: <input type='text' name='votes' value='<?php echo $_SESSION['in']; ?>' disabled='enabled'><br>
OUT: <input type='text' name='hits' value='<?php echo $_SESSION['out']; ?>' disabled='enabled'> <br>
<input type='submit' name='submit' value='update profile' class='box'>
</table>
</form>
<p>

<table align='center'>
<textarea cols='60' rows='6' align='left'><!-- Toplist voting --><?php echo "\n"; ?>
<a href='<?php echo $site['url']; ?>in.php?site=<?php echo $_SESSION['site_id'];
?>'><img src='<?php echo $site['url'] ?>images/icon.jpg' border='0'></a>
<!-- End Toplist voting --></textarea>
<p>
<!-- Toplist voting --><?php echo "\n"; ?>
<a href='<?php echo $site['url']; ?>in.php?site=<?php echo $_SESSION['site_id'];
?>'><img src='<?php echo $site['url']; ?>images/icon.jpg' border='0'></a>
<!-- End Toplist voting -->
</table>

<?php
}
?>
A profile which gives the users the option to change their site name, url, password, etc..


lost.php


Quote:
<?php
session_start();
?>
<html>
<head>
<style type="text/css">
<!--
.box {
background-color: #BABABA;
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
border: 1px solid #BABABA;
}
-->
</style>
</head>
<body>
<?php
if(isset($_POST['submit'])) {
if(!$_POST['mail'] || !$_POST['site_name']) {
echo "<table align='center'><font color='red'>Please fill in all of the fields!</font></table>";
}else{
$query = mysql_query("SELECT password,email FROM sites WHERE name = '".$_POST['site_name']."' && email = '".$_POST['mail']."' ") or die(mysql_error());
if(isset($_POST['mail']) && isset($_POST['site_name'])) {
if(mysql_num_rows(mysql_query("SELECT password FROM sites WHERE name = '".$_POST['site_name']."' && email = '".$_POST['mail']."' ")) == 1) {
while($row = mysql_fetch_assoc($query)) {
$subject = "Your password";
$mail = $row['email'];
$content = "Your password for your site ".$row['name']." is: ".$row['password']." \n Greetings, Toplist Crew";
$from = $email;
mail($mail,$subject,$content, "From: $from\nX-Mailer: PHP/" . phpversion());

echo "<table align='center'>There have been sent an email with your password! If you have any questions feel free to contact us.</table>";
}
}else{
echo "<table align='center'>Username and mail doesn't match!";
echo "<br> <p>Please try again!</p>";
echo "<a href='index.php?act=lost&&m=".$_POST['mail']."&&u=".$_POST['site_name']."'>back</a></table>";
}
}else{
?><script language='javascript'> { alert("Please fill in all fields!"); } </script <?php
}

}
}else{
?>
<table align='center'>
<form method='POST' action='index.php?act=lost'>
Username: <input type='text' name='site_name' value='<?php echo $_GET['u']; ?>'><br>
Email: <input type='text' name='mail' value='<?php echo $_GET['m']; ?>'><br>
<input type='submit' name='submit' value='Send my password!' class='box' >
</form>
</table>
<?php
}
?>
</body>
</html>
Retrieves lost passwords.


forum.php

Quote:
//not created yet...
If you have any comments,tips or questions, feel free to ask/tell me!

Last edited by skyfe; 05-18-2007 at 03:52 PM.
Reply With Quote
  #5 (permalink)  
Old 05-18-2007, 03:47 PM
Junior Member
 
Join Date: Feb 2007
Posts: 6
LegosJedi is on a distinguished road
Good start. Just make sure that you always have the "<?php session_start(); ?>" bit above everything, including HTML. One example is the lost.php page

Your code:
Code:
<html>
<?php
session_start();
?>
<head>
This is going to give you error that the headers have already been sent. To fix this, change it so that the session_start function is above the <html> tag, like this:

Code:
<?php
session_start();
?>
<html>
<head>
Reply With Quote
  #6 (permalink)  
Old 05-18-2007, 03:49 PM
Senior Member
 
Join Date: May 2007
Posts: 181
Blog Entries: 1
skyfe is on a distinguished road
thanks, but it's not a must caus the session_start(); is already set in the first page (index.php), and there will all other pages get included to
I though

Oooh wait, I see what you mean sorry, you're right there, thanks for telling, will change it (but I got no warnings when running so I hadn't seen that )
Reply With Quote
  #7 (permalink)  
Old 05-20-2007, 11:31 AM
Senior Member
 
Join Date: May 2007
Posts: 181
Blog Entries: 1
skyfe is on a distinguished road
no more comments? anyone?
Reply With Quote
  #8 (permalink)  
Old 05-20-2007, 02:17 PM
Junior Member
 
Join Date: Mar 2007
Posts: 20
tere is on a distinguished road
Thanks. Thats what i need. I will give you credits.
Reply With Quote
  #9 (permalink)  
Old 05-20-2007, 02:28 PM
Senior Member
 
Join Date: May 2007
Posts: 181
Blog Entries: 1
skyfe is on a distinguished road
Thumbs up

good!

Soon I'll update this version to a full version !
with in feature(full version) :

- advanced admin panel to remove/edit sites that have been added to your toplist
- will make the toplist unlimited sites on main page, caus now it only works for 50 sites yet (top 50), but will make it able that when if there are more than 50 sites, that there will be links at the bottom like : 50-100 and 100-150, etc., and when you click on it there will be a list of sites random that #place
- will add a character counter so people won't post a site with as description a longer description than 250 characters
- and some more things ^^.
enjoy

EDDIT: created a start on a admin panel
directory: toplist\admin
files:
index.php
delete.php
search.php
info.php


file name: index.php

Quote:
<?php
session_start();
include("../modules/config.php");
$_SESSION['denied'] = 0;
if($_SESSION['denied'] == 5) {
echo "<font color='red'>You have tried to many times to login with an invalid username/password!</font>";
}
if(isset($_SESSION['admin_logged']) && !empty($_SESSION['admin_logged']) && $_SESSION['admin_logged'] == 'true') {
echo " <form method='POST' action='search.php'><table align='center'><tr><td><b>Welcome Administrator!</b></td><td align='right'> <b> search: </b> </td> <td align='right'> <input type='text' value='site' name='site_name'> </td> <td> <input type='submit' name='search' value='search'></td></table></form><p>";
?>
<table style='border:1px solid #BABABA;' width='90%' cellspacing='0' cellpadding='4' align='center'>
<tr>
<td background='../images/b1.jpg' style='border-bottom:1px solid #BABABA;' width='70%' height='29' align='center'><font color='#FFFFFF'> Site </font> </td>
<td background='../images/b1.jpg' style='border-bottom:1px solid #BABABA;' width='7.5%'> <font color='#FFFFFF'> IN </font> </td>
<td background='../images/b1.jpg' style='border-bottom:1px solid #BABABA;' width='7.5%'> <font color='#FFFFFF'> OUT </font> </td>
<td background='../images/b1.jpg' style='border-bottom:1px solid #BABABA;' width='15%'> <font color='#FFFFFF'>action</font></td>
</tr>
<?php
$top_sites = mysql_query("
SELECT
*
FROM
sites
ORDER BY
'id'
DESC
") or die(mysql_error());
while($site = mysql_fetch_assoc($top_sites)) {
if($light == 0) {
$light = 1;
$bgcolor = "#D8D8D8";
}else{
$light = 0;
$bgcolor = "#BCBCBC";
}
?>
<tr>
<td bgcolor='<?php echo $bgcolor; ?>' width='70%' style='border-bottom:1px solid #BABABA;'> <?php if(mysql_num_rows(mysql_query("SELECT banner FROM sites WHERE name = '".$site['name']."'")) > 0 && isset($site['banner']) && !empty($site['banner'])) { ?><img src='<?php echo $site['banner']; ?>'><br><?php } ?><a href='../out.php?id=<?php echo $site['id']; ?>' target='_BLANK'><b> <?php echo $site['name']; ?></b></a><br> <?php echo $site['description']; ?> </td>
<td bgcolor='<?php echo $bgcolor; ?>' width='7.5%' style='border-bottom:1px solid #BABABA;'> <?php echo $site['votes']; ?> </td>
<td bgcolor='<?php echo $bgcolor; ?>' width='7.5%' style='border-bottom:1px solid #BABABA;'> <?php echo $site['hits']; ?> </td>
<td bgcolor='<?php echo $bgcolor; ?>' width='15%' style='border-bottom:1px solid #BABABA;'> <a href='delete.php?id=<?php echo $site['id']; ?>'>delete</a> <a href='info.php?id=<?php echo $site['id']; ?>'>edit</a> </td>
</tr>
<?php
}
?>
</table> <?php
}else{
if(!isset($_POST['submit'])) {
?>
<form method='POST' action='index.php'>
username: <input type='text' name='admin_user'>
password: <input type='text' name='admin_pass'>
<input type='submit' name='submit' value='login'>
</form>
<?php
}else{
if($_POST['admin_user'] == $admin['username'] && $_POST['admin_pass'] == $admin['password']) {
echo " <form method='POST' action='search.php'><table align='center'><tr><td><b>Welcome Administrator!</b></td><td align='right'> <b> search: </b> </td> <td align='right'> <input type='text' value='site' name='site_name'> </td> <td> <input type='submit' name='search' value='search'></td></table></form><p>";
?>
<table style='border:1px solid #BABABA;' width='90%' cellspacing='0' cellpadding='4' align='center'>
<tr>
<td background='../images/b1.jpg' style='border-bottom:1px solid #BABABA;' width='70%' height='29' align='center'><font color='#FFFFFF'> Site </font> </td>
<td background='../images/b1.jpg' style='border-bottom:1px solid #BABABA;' width='7.5%'> <font color='#FFFFFF'> IN </font> </td>
<td background='../images/b1.jpg' style='border-bottom:1px solid #BABABA;' width='7.5%'> <font color='#FFFFFF'> OUT </font> </td>
<td background='../images/b1.jpg' style='border-bottom:1px solid #BABABA;' width='15%'> <font color='#FFFFFF'>action</font></td>
</tr>
<?php
$top_sites = mysql_query("
SELECT
*
FROM
sites
ORDER BY
'id'
DESC
") or die(mysql_error());
while($site = mysql_fetch_assoc($top_sites)) {
if($light == 0) {
$light = 1;
$bgcolor = "#D8D8D8";
}else{
$light = 0;
$bgcolor = "#BCBCBC";
}
?>
<tr>
<td bgcolor='<?php echo $bgcolor; ?>' width='70%' style='border-bottom:1px solid #BABABA;'> <?php if(mysql_num_rows(mysql_query("SELECT banner FROM sites WHERE name = '".$site['name']."'")) > 0 && isset($site['banner']) && !empty($site['banner'])) { ?><img src='<?php echo $site['banner']; ?>'><br><?php } ?><a href='../out.php?id=<?php echo $site['id']; ?>' target='_BLANK'><b> <?php echo $site['name']; ?></b></a><br> <?php echo $site['description']; ?> </td>
<td bgcolor='<?php echo $bgcolor; ?>' width='7.5%' style='border-bottom:1px solid #BABABA;'> <?php echo $site['votes']; ?> </td>
<td bgcolor='<?php echo $bgcolor; ?>' width='7.5%' style='border-bottom:1px solid #BABABA;'> <?php echo $site['hits']; ?> </td>
<td bgcolor='<?php echo $bgcolor; ?>' width='15%' style='border-bottom:1px solid #BABABA;'> <a href='delete.php?id=<?php echo $site['id']; ?>'>delete</a> <a href='info.php?id=<php echo $site['id']; ?>'>edit</a> </td>
</tr>
<?php
}
?>
</table>
<?php
$_SESSION['admin_logged'] = 'true';
}else{
echo "<font color='red'>ACCES DENIED</font> You don't have the permission to acces to this page!";
$_SESSION['denied']++;
}
}
}
?>
The admin controll panel index, from out of here you can delete sites, edit sites, or search to one to see the information of the site and maybe to edit it(including user's IP address!)

file name: delete.php

Quote:
<?php
session_start();
include("../modules/config.php");
$site_id = $_GET['id'];
$site_query = mysql_query("SELECT * FROM sites WHERE id = '".$site_id."' LIMIT 1") or die(mysql_error());
if(isset($_GET['d']) && isset($_GET['id'])) {
if($_GET['d'] == 'true') {
$delete_query = mysql_query("DELETE FROM sites WHERE id = '".$site_id."' ")or die(mysql_error());
echo "Site was succesfully deleted! Please wait while you're getting redirected...";
echo "<meta content='3; URL=index.php' http-equiv='Refresh' />";
}elseif($_GET['d'] == 'false'){
echo "<meta content='1; URL=index.php' http-equiv='Refresh' />";
echo "Site was NOT deleted. Please wait while you're getting redirected back.";
}
}else{
while($rs = mysql_fetch_assoc($site_query)) {
echo "<p>Are you sure you want to delete ".$rs['name']."?</p>";
echo "<a href='delete.php?d=true&&id=".$rs['id']."'>yes</a> | <a href='delete.php?d=false'> no </a> ";
}
}
?>
Makes you able to delete a site.

Last edited by skyfe; 05-20-2007 at 08:36 PM.
Reply With Quote
  #10 (permalink)  
Old 05-20-2007, 08:36 PM
Senior Member
 
Join Date: May 2007
Posts: 181
Blog Entries: 1
skyfe is on a distinguished road
Thumbs up

file name: search.php

Quote:
<?php
session_start();
include("../modules/config.php");
$select_result = mysql_query("SELECT * FROM sites WHERE name LIKE '%".$_POST['site_name']."%' ");
echo "<table align='center'><p>The follow results have been found:</p></table>";
if(mysql_num_rows($select_result) > 0) {
while($result = mysql_fetch_assoc($select_result)) {
?>
<table style='border:1px solid #BABABA;' width='90%' cellspacing='0' cellpadding='4' align='center'>
<tr>
<td background='../images/b1.jpg' style='border-bottom:1px solid #BABABA;' width='70%' height='29' align='center'><font color='#FFFFFF'> Site </font> </td>
<td background='../images/b1.jpg' style='border-bottom:1px solid #BABABA;' width='7.5%'> <font color='#FFFFFF'> IN </font> </td>
<td background='../images/b1.jpg' style='border-bottom:1px solid #BABABA;' width='7.5%'> <font color='#FFFFFF'> OUT </font> </td>
<td background='../images/b1.jpg' style='border-bottom:1px solid #BABABA;' width='15%'> <font color='#FFFFFF'>action</font></td>
</tr>
<?php
if($light == 0) {
$light = 1;
$bgcolor = "#D8D8D8";
}else{
$light = 0;
$bgcolor = "#BCBCBC";
}
?>
<tr>
<td bgcolor='<?php echo $bgcolor; ?>' width='70%' style='border-bottom:1px solid #BABABA;'> <?php if(mysql_num_rows(mysql_query("SELECT banner FROM sites WHERE name = '".$result['name']."'")) > 0 && isset($result['banner']) && !empty($result['banner'])) { ?><img src='<?php echo $result['banner']; ?>'><br><?php } ?><a href='../out.php?id=<?php echo $result['id']; ?>' target='_BLANK'><b> <?php echo $result['name']; ?></b></a><br> <?php echo $result['description']; ?> </td>
<td bgcolor='<?php echo $bgcolor; ?>' width='7.5%' style='border-bottom:1px solid #BABABA;'> <?php echo $result['votes']; ?> </td>
<td bgcolor='<?php echo $bgcolor; ?>' width='7.5%' style='border-bottom:1px solid #BABABA;'> <?php echo $result['hits']; ?> </td>
<td bgcolor='<?php echo $bgcolor; ?>' width='15%' style='border-bottom:1px solid #BABABA;'> <a href='delete.php?id=<?php echo $result['id']; ?>'>delete</a> <a href='edit.php?id=<?php echo $result['id']; ?>'>edit</a> </td>
</tr>
</table><?php
}
}else{
echo "No results have been found...";
}
?>
Shows the results of your search if any.

file name: info.php

Quote:
<?php
session_start();
include("../modules/config.php");
$get_info = mysql_query("
SELECT
*
FROM
sites
WHERE
id = '".$_GET['id']."'
")or die(mysql_error());
while($row_get = mysql_fetch_assoc($get_info)) {
$_SESSION['url'] = $row_get['url'];
$_SESSION['banner'] = $row_get['banner'];
$_SESSION['description'] = $row_get['description'];
$_SESSION['in'] = $row_get['votes'];
$_SESSION['out'] = $row_get['hits'];
$_SESSION['site_id'] = $row_get['id'];
$_SESSION['site'] = $row_get['name'];
$_SESSION['password'] = $row_get['name'];
$ip = $row_get['ip'];
}
if(isset($_POST['submit'])) {

if(!isset($_POST['pass_update']) || empty($_POST['pass_update'])) {
$pass = $_SESSION['password'];
}else{
$pass = $_POST['pass_update'];
}

if(!isset($_POST['site_name']) || empty($_POST['site_name'])) {
$site = $_SESSION['site'];
}else{
$site = $_POST['site_name'];
}

if(!isset($_POST['description']) || empty($_POST['description'])) {
$description = $_SESSION['description'];
}else{
$description = $_POST['description'];
}
if(!isset($_POST['site_url']) || empty($_POST['site_url'])) {
$url = $_SESSION['url'];
}else{
$url = $_POST['site_url'];
}
$update_query = mysql_query("
UPDATE
sites
SET
password = '".$pass."',
name = '".$site."',
description = '".$description."',
url = '".$url."'
WHERE
name = '".$_SESSION['site']."'
&&password = '".$_SESSION['password']."'
")or die(mysql_error());
echo "<table align='center'>Profile succesfully updated!</table>";
$_SESSION['password'] = $pass;
$_SESSION['site'] = $site;
$_SESSION['url'] = $url;
$_SESSION['description'] = $description;
}else{
?>
<form method='POST' action='index.php?act=profile'>
<table align='center'>
<b><font size='6'>PROFILE</b></font><p>
user ip: <b><?php echo $ip; ?> </b><br>
site name: <input type='text' name='site_name' value='<?php echo $_SESSION['site']; ?>'><br>
site url : <input type='text' name='site_url' value='<?php echo $_SESSION['url']; ?>'> <br>
description: <textarea name='description'><?php echo $_SESSION['description']; ?></textarea><br>
password : <input type='text' name='pass_now' value='<?php echo $_SESSION['password']; ?>' disabled='enabled'> <br>
change password: <input type='password' name='pass_update'> <br>
IN: <input type='text' name='votes' value='<?php echo $_SESSION['in']; ?>' disabled='enabled'><br>
OUT: <input type='text' name='hits' value='<?php echo $_SESSION['out']; ?>' disabled='enabled'> <br>
<input type='submit' name='submit' value='update profile' class='box'>
</table>
</form>
<p>
<table align='center'>
<textarea cols='60' rows='6' align='left'><!-- Toplist voting --><?php echo "\n"; ?>
<a href='<?php echo $site['url']; ?>in.php?site=<?php echo $_SESSION['site_id'];
?>'><img src='<?php echo $site['url'] ?>images/icon.jpg' border='0'></a>
<!-- End Toplist voting --></textarea>
<p>
<!-- Toplist voting --><?php echo "\n"; ?>
<a href='<?php echo $site['url']; ?>in.php?site=<?php echo $_SESSION['site_id'];
?>'><img src='<?php echo $site['url']; ?>images/icon.jpg' border='0'></a>
<!-- End Toplist voting -->
</table>
<?php
}
?>
shows the info from a specific submited site, and makes you able to eddit it (including users ip address)

enjoy ^^ updated attachment file too

EDDIT:
also eddited the config.php, please overwrite the old config.php with this one and configurate it:

Quote:
<?php
### your database info ###
mysql_connect("localhost", "username", "password"); //localhost, your db username, your db password
mysql_select_db("toplist"); //your database name
## your email ##
$email = "bergjasper@zonnet.nl"; //set to your email
## site ##
$site['name'] = "TOPLIST"; //set this to your site name
$site['url'] = "http://62.59.224.206/programs/toplist/"; //manage this to the url to your toplist site
## admin panel ##
$admin['username'] = "admin"; //configurate this to a username you would like to use for the admin panel
$admin['password'] = "admin"; //set this to a password which is hard to guess and which you will be using for the admin panel
?>
enjoy!


Last edited by skyfe; 05-21-2007 at 08:22 AM.
Reply With Quote
Reply

Bookmarks