PHP Login System with Admin Features

Would you like to react to this message? Create an account in a few clicks or log in to continue.
PHP Login System with Admin Features

This forum was created to talk about the PHP Login System with admin features created by jpmaster77 on evolt's website


2 posters

    simple message board

    mattastic
    mattastic


    Number of posts : 25
    Registration date : 2009-10-11

    simple message board Empty simple message board

    Post  mattastic Wed Feb 03, 2010 4:45 pm

    this is a very simple forum script that got from http://www.chipmunk-scripts.com/board/index.php?forumID=43&ID=9268 and added a few things to it. i didn't add all the code from my site since the code is a little different from my files so there could be some errors.

    create topics
    replies to posters
    creates a new page after every 10 topics (newer/older)
    posts/creates topics based on who is logged in

    create database table:
    Code:

    CREATE TABLE forumtutorial_posts (

      postid bigint(20) NOT NULL auto_increment,

      author varchar(255) NOT NULL default '',

      title varchar(255) NOT NULL default '',

      post mediumtext NOT NULL,

      showtime varchar(255) NOT NULL default '',

      realtime bigint(20) NOT NULL default '0',

      lastposter varchar(255) NOT NULL default '',

      numreplies bigint(20) NOT NULL default '0',

      parentid bigint(20) NOT NULL default '0',

      lastrepliedto bigint(20) NOT NULL default '0',

      PRIMARY KEY  (postid)

    )

    connect.php:
    Code:

    <?php



    $db = mysql_connect("localhost", "username", "password") or die("Could not connect.");

    if(!$db)

       die("no db");

    if(!mysql_select_db("database_name",$db))

        die("No database selected.");

    if(!get_magic_quotes_gpc())

    {

      $_GET = array_map('mysql_real_escape_string', $_GET);

      $_POST = array_map('mysql_real_escape_string', $_POST);

      $_COOKIE = array_map('mysql_real_escape_string', $_COOKIE);

    }

    else



      $_GET = array_map('stripslashes', $_GET);

      $_POST = array_map('stripslashes', $_POST);

      $_COOKIE = array_map('stripslashes', $_COOKIE);

      $_GET = array_map('mysql_real_escape_string', $_GET);

      $_POST = array_map('mysql_real_escape_string', $_POST);

      $_COOKIE = array_map('mysql_real_escape_string', $_COOKIE);

    }



    ?>

    styling sheet for the forum:
    Code:

    <!---



    body {

    a:link, a:visited, a:active { text-decoration: none}

    font-family:Verdana, Sans-serif;

    color; #000000;

    font-size: 12px

    }

    input,textarea, select,{

       color : #000000;

       font: normal 12px;

       border-collapse: collapse; border: 1px solid #000000;

    }

    .maintable {border: 0px ; width: 100%; padding: 0px; background-color: #FFFFFF} /*main table for forum*/

    .regrow {font-family: Verdana,Sans-serif; color: #000000; font-weight: bold; background-color: #FFFFFF;font-size: 12px;} /*registration row, mainly here for symetry*/

    .headline {font-family: Verdana,Sans-serif;font-weight: bold;color: #FFFFFF;background-color: #003366;font-size: 11px;} /*headline row, the first row that says forum name, topics, posts and such*/

    .forumrow {font-family: Verdana,Sans-serif; color: #000000;background-color: #F2F2F2;font-size: 12px;} /*color of the forum rows*/

    .mainrow a:link, a:visited,  a:active { text-decoration: none;}

    .mainrow {font-family: Verdana,Sans-serif; color: #000000;background-color: #F2F2F2;font-size: 12px; a:link, a:visited, a:active { text-decoration: none}} /*color of the forum rows*/

    .maintables{background-color: #FFFFFF; width: 95%; padding: 0px; border: 1px solid; cellspacing: no} /*main table for forum*/

    --->

    forum.php: this is where you'll see all the topics
    Code:

    <?php
    include "connect.php"; //mysql db connection here
    include "include/session.php";

    print "<A href='newtopic.php'>New Topic</a><br>";

    "<link rel='stylesheet' href='style.css' type='text/css'>";
    print "<A href='post.php'></a><br>";$blog_postnumber = 10;if(!isset($_GET['page'])) {    $page = 1;}else {    $page = (int)$_GET['page'];}$from = (($page * $blog_postnumber) - $blog_postnumber);

    print "<table class='maintable'>";print "<tr class='headline'><td width=50%>Topic</td><td width=20%>Topic Starter</td><td>Replies</td><td>Last replied time</td></tr>";$getthreads="SELECT * from forumtutorial_posts where parentid='0' order by lastrepliedto desc LIMIT $from, $blog_postnumber";$getthreads2=mysql_query($getthreads) or die("Could not get threads");

    while($getthreads3=mysql_fetch_array($getthreads2)){  $getthreads3[title]=strip_tags($getthreads3[title]);  $getthreads3[author]=strip_tags($getthreads3[author]); 

    print "<tr class='mainrow'><td>

    <A href='message.php?id=$getthreads3[postid]'>$getthreads3[title]</a></td><td>$getthreads3[author]</td><td>$getthreads3[numreplies]</td><td>$getthreads3[showtime]<br>Last post by <b>$getthreads3[lastposter]</b></td></tr>";}

    print "</table>";$total_results = mysql_fetch_array(mysql_query("SELECT COUNT(*) as num FROM forumtutorial_posts where parentid='0'"));$total_pages = ceil($total_results['num'] / $blog_postnumber);if ($page > 1) {    $prev = ($page - 1);    echo "<a href=\"forum.php?page=$prev\">&lt;&lt;  Newer</a> ";}for($i = 1; $i <= $total_pages; $i++) {    if ($page == $i) {        echo "$i ";        }        else {          echo "<a href=\"forum.php?page=$i\">$i</a> ";        }}if ($page < $total_pages) {  $next = ($page + 1);  echo "<a href=\"forum.php?page=$next\">Older &gt;&gt;</a>";} 
     
    ?> 

    message.php: this the page your directed to when you click a topic.
    Code:

    <?php

    include "connect.php"; //mysql db connection here
    include "include/session.php";

    $id=$_GET['id'];

    print "<A href='forum.php'>Back to main forum</a>-<A href='newtopic.php'>New Topic</a>-<A href='reply.php?id=$id'>Reply<br>";

    print "<table class='maintable'>";

    print "<tr class='headline'><td width=20%>Author</td><td width=80%>Post</td></tr>";

    $gettopic="SELECT * from forumtutorial_posts where postid='$id'";

    $gettopic2=mysql_query($gettopic) or die("Could not get topic");

    $gettopic3=mysql_fetch_array($gettopic2);

    print "<tr class='mainrow'><td valign='top'>$gettopic3[author]</td><td vakign='top'>Last replied to at $gettopic3[showtime]<br><hr>";

    $message=strip_tags($gettopic3['post']);

    $message=nl2br($message);

    print "$message<hr><br>";

    print "</td></tr>";

    $getreplies="Select * from forumtutorial_posts where parentid='$id' order by postid desc"; //getting replies

    $getreplies2=mysql_query($getreplies) or die("Could not get replies");

    while($getreplies3=mysql_fetch_array($getreplies2))

    {

      print "<tr class='mainrow'><td valign='top'>$getreplies3[author]</td><td vakign='top'>Last replied to at $getreplies3[showtime]<br><hr>";

      $message=strip_tags($getreplies3['post']);

      $message=nl2br($message);

      print "$message<hr><br>";

      print "</td></tr>";

    }

    print "</table>";
    ?>

    newtopic.php:
    Code:

    <?php

    include "connect.php"; //mysql db connection here
    include "include/session.php";

    $id=$_GET['id'];

    print "<A href='forum.php'>Back to main forum</a>-<A href='newtopic.php'>New Topic</a>-<A href='reply.php?id=$id'>Reply<br>";

    print "<table class='maintable'>";

    print "<tr class='headline'><td width=20%>Author</td><td width=80%>Post</td></tr>";

    $gettopic="SELECT * from forumtutorial_posts where postid='$id'";

    $gettopic2=mysql_query($gettopic) or die("Could not get topic");

    $gettopic3=mysql_fetch_array($gettopic2);

    print "<tr class='mainrow'><td valign='top'>$gettopic3[author]</td><td vakign='top'>Last replied to at $gettopic3[showtime]<br><hr>";

    $message=strip_tags($gettopic3['post']);

    $message=nl2br($message);

    print "$message<hr><br>";

    print "</td></tr>";

    $getreplies="Select * from forumtutorial_posts where parentid='$id' order by postid desc"; //getting replies

    $getreplies2=mysql_query($getreplies) or die("Could not get replies");

    while($getreplies3=mysql_fetch_array($getreplies2))

    {

      print "<tr class='mainrow'><td valign='top'>$getreplies3[author]</td><td vakign='top'>Last replied to at $getreplies3[showtime]<br><hr>";

      $message=strip_tags($getreplies3['post']);

      $message=nl2br($message);

      print "$message<hr><br>";

      print "</td></tr>";

    }

    print "</table>";



    ?> 

    reply.php: you'll see the link to this in the message.php
    Code:

    <?php

    include "connect.php"; //connection string
    include "include/session.php";

    print "<table class='maintables'>";

    print "<tr class='headline'><td>Reply</td></tr>";

    print "<tr class='maintables'><td>";

    if(isset($_POST['submit']))

    {

      $name=$_SESSION['username'];

      $yourpost=$_POST['yourpost'];

      $subject=$_POST['subject'];

      $id=$_POST['id'];
     

      if(strlen($name)<1)

      {

          print "You did not type in a name."; //no name entered

      }

      else if(strlen($yourpost)<1)

      {

          print "You did not type in a post."; //no post entered

      }

      else

      {

          $thedate=date("U"); //get unix timestamp

          $displaytime=date("F j, Y, g:i a");

          //we now strip HTML injections

          $subject=strip_tags($subject);

          $name=strip_tags($name);

          $yourpost=strip_tags($yourpost);

          $insertpost="INSERT INTO forumtutorial_posts(author,title,post,showtime,realtime,lastposter,parentid) values('$name','$subject','$yourpost','$displaytime','$thedate','$name','$id')";

          mysql_query($insertpost) or die("Could not insert post"); //insert post

          $updatepost="Update forumtutorial_posts set numreplies=numreplies+'1', lastposter='$name',showtime='$displaytime', lastrepliedto='$thedate' where postid='$id'";

          mysql_query($updatepost) or die("Could not update post");

          print "Message posted, go back to <A href='message.php?id=$id'>Message</a>.";

      }



    }

    else

    {

      $id=$_GET['id'];

      print "<form action='reply.php' method='post'>";

      print "<input type='hidden' name='id' value='$id'>";

      print "Your message:<br>";

      print "<textarea name='yourpost' rows='5' cols='40'></textarea><br>";

      print "<input type='submit' name='submit' value='submit'></form>";



    }

    print "</td></tr></table>";

    ?>
    Apollo
    Apollo


    Number of posts : 9
    Registration date : 2010-03-22

    simple message board Empty Re: simple message board

    Post  Apollo Tue Mar 23, 2010 11:54 am

    Anyone else tried this out? Is there any errors?

      Current date/time is Fri May 17, 2024 4:26 am