home.php
<?php include('core/init.inc.php'); $errors = array(); if (isset($_POST['status'])){ if(empty($_POST['status'])){ $errors[] = 'Your status may not be empty!'; } if (empty($errors)){ get_feeds($_POST['status']); header('Location: home.php'); echo 'Status Successfully posted!'; die(); } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Welcome to Socialcrunch</title> <meta name="description" content="Welcome to Socialcrunch. You may connect with friends, meet new ones, and also hang out when you have free time!" /> <meta name="keywords" content="social, networking, games, chat, hangout, friends" /> <meta name="robots" content="index, follow" /> <link rel="stylesheet" href="styles/style.css" type="text/css"> </head> <body> <div id="wrapper"> <?php mysql_connect('mysql6.000webhost.com','username','password'); mysql_select_db('database'); ?> <div id="navigation"> <ul> <li><a href="">Settings</a></li> <li><a href=""><img src=""></img><?php $user_info['username']; ?></a></li> <li><a href="http://"><img src=""></img></a></li> </ul> </div> <div id="main"> <div id="update"> <div> <?php if (empty($errors) === false){ ?> <ul> <?php foreach ($errors as $error){ echo "<li>{$error}</li>"; } ?> </ul> <?php } ?> </div> <form action="" method="post"> <p class="status"> <textarea name="status" id="status" cols="50" rows="5" placeholder="Update your life here..."></textarea> </p> <input type="submit" value="Post"> </form> </div> <h1>What others have posted</h1> <?php include('feeds.php'); ?> </div> </div> <div id="footer"> <p>© SocialCrunch 2013. All Rights Reserved.</p> </div> </body> </html>feeds.php
<div class="post"> <img src="" alt="" /> <div class="content"> <?php include('core/inc/user.inc.php'); mysql_connect('mysql6.000webhost.com','username','password'); mysql_select_db('database'); $query = mysql_query('SELECT * FROM feeds ORDER BY id DESC'); while($output = mysql_fetch_assoc($query)){ $numberComments = mysql_query("SELECT id FROM newscomments WHERE id = '".$output['id']."'"); echo $output['username'].'<br />'; echo $output['status'].'<br />'; echo '<a href="viewcomments.php?id='.$output['id'].'">View Comments</a> <hr />'; } ?> </div> </div>user.inc.php
<?php // Checks if the given username exists in the table. function user_exists($user){ $user = mysql_real_escape_string($user); $total = mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `user_name` = '{$user}'"); return (mysql_result($total, 0) == '1') ? true : false; } // Checks if the given username and password combination is valid. function valid_credentials($user, $pass){ $user = mysql_real_escape_string(htmlentities($user)); $pass = mysql_real_escape_string($pass); $total = mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `user_name` = '{$user}' AND `user_password` = '{$pass}'"); return (mysql_result($total, 0) == '1') ? true : false; } // Checks if the given user account is active function is_active($user){ $user = mysql_real_escape_string($user); $sql = "SELECT COUNT(`user_activations`.`user_id`) FROM `users` INNER JOIN `user_activations` ON `users`.`user_id` = `user_activations`.`user_id` WHERE `users`.`user_name` = '{$user}'"; $result = mysql_query($sql); return (mysql_result($result, 0) == '0') ? true : false; } // Activates the account related to the given activation code function activate_account($aid){ $aid = mysql_real_escape_string($aid); mysql_query("DELETE FROM `user_activations` WHERE `activation_code` = '{$aid}'"); } // Adds a user to the Database. function add_user($user, $email, $pass, $first_name, $last_name){ $user = mysql_real_escape_string(htmlentities($user)); $email = mysql_real_escape_string($email); $pass = sha1($pass); $first_name = mysql_real_escape_string(htmlentities($first_name)); $last_name = mysql_real_escape_string(htmlentities($last_name)); $charset = array_flip(array_merge(range('a', 'z'), range('A', 'Z'), range(0, 9))); $aid = implode('', array_rand($charset, 10)); $body = <<<EMAIL Welcome to Socialcrunch! Before you can login you must activate your account by clicking the link below. http://socialcrunch.comyr.com/activate.php?aid={$aid} EMAIL; mail($email, 'Welcome to Socialcrunch', $body, 'From: admin@socialcrunch.comyr.com'); mysql_query("INSERT INTO `users` (`user_name`, `user_password`, `user_email`, `first_name`, `last_name`) VALUES ('{$user}', '{$pass}', '{$email}', '{$first_name}', '{$last_name}')"); $user_id = mysql_insert_id(); mysql_query("INSERT INTO `user_activations` (`user_id`, `activation_code`) VALUES ({$user_id}, '{$aid}')"); } // Adds feeds to the Feeds Database function get_feeds($id, $user, $time, $status){ $user = mysql_real_escape_string(htmlentities($user)); $status = mysql_real_escape_string(htmlentities($status)); $charset = array_flip(array_merge(range('a', 'z'), range('A', 'Z'), range(0, 9))); $id = implode('', array_rand($charset, 6)); mysql_query("INSERT INTO `feeds` (`id`, `username`, `time`, `status`) VALUES (`{$id}`, `{$user}`, `{$time}`, `{$status}`)"); } // Displays the feeds on the users page function give_feeds(){ } ?>or see it on the website: socialcrunch.comyr.com