CHP 5-7 Rough
CHP 5-7 Rough
CHP 5-7 Rough
1|Page
Chapter 5
login.php
<?php
class Login
{
$email = addslashes($data['email']);
$password = addslashes($data['password']);
if ($result)
{
$row = $result[0];
if($this->hash_text($password) == $row['password'])
{
}else
2|Page
{
$this->error .= "Wrong email or password <br>";
}
}else
{
return $this->error;
if ($result)
{
$user_data = $result[0];
return $user_data;
}else
{
header("Location: login.php");
die;
}
}else
{
header("Location: login.php");
die;
}
3|Page
Signup.php
<?php
class Signup
{
if (empty($value))
{
$this->error = $this->error . $key . " is empty!<br>";
}
if ($key == "email")
{
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$value)) {
if ($key == "first_name")
{
if (is_numeric($value)) {
if ($key == "last_name")
{
if (is_numeric($value)) {
4|Page
$this->error = $this->error . $key . " cannot have numeric value.
<br>";
}
}
}
if ($this->error == "")
{
//no error
$this->create_user($data);
}else
{
return $this->error;
}
}
$first_name = ucfirst($data['first_name']);
$last_name = ucfirst($data['last_name']);
$gender = $data['gender'];
$email = $data['email'];
$password = $data['password'];
//create these
$url_address = strtolower($first_name) . "." .strtolower($last_name);
$userid = $this->create_userid();
5|Page
private function create_userid()
{
$length = rand(4,19);
$number = "";
for ($i=0; $i < $length ; $i++) {
# code...
$new_rand = rand(0,9);
return $number;
}
}
6|Page
Connect.php
<?php
class Database
{
function connect()
{
$connection = mysqli_connect($this->host,$this->username,$this->password,$this->db);
return $connection;
}
function read($query)
{
$conn = $this->connect();
$result = mysqli_query($conn,$query);
if (!$result)
{
return false;
}
else
{
$data = false;
while ($row = mysqli_fetch_assoc($result))
{
$data[] = $row;
return $data;
}
}
function save($query)
{
$conn = $this->connect();
$result = mysqli_query($conn,$query);
if(!$result)
7|Page
{
return false;
}else
{
return true;
}
}
8|Page
Post.php
<?php
class Post
{
private $error = "";
$myimage = "";
$has_image = 0;
$is_cover_image = 0;
$is_profile_image = 0;
if (isset($data['is_profile_image']) || isset($data['is_cover_image']))
{
$myimage = $files;
$has_image = 1 ;
if (isset($data['is_cover_image']))
{
$is_cover_image = 1;
}
if (isset($data['is_profile_image']))
{
$is_profile_image = 1;
}
}else
{
if (!empty($files['file']['name']))
{
//Create Folder
if (!file_exists($folder))
{
mkdir($folder,0777,true);
9|Page
file_put_contents($folder . "index.php", "");
}
$image_class->resize_image($myimage,$myimage,1500,1500);
$has_image = 1;
}
}
$post = "";
if (isset($data['post']))
{
$post = addslashes($data['post']);
}
$postid = $this->create_postid();
}else
{
$this->error .= "Please type something to post!<br>";
}
return $this->error;
}
$query = " select * from posts where userid = '$id' order by id desc limit 10 " ;
if ($result)
{
return $result ;
}else
{
10 | P a g e
return false;
}
}
return false;
}
$query = " select * from posts where postid = '$postid' limit 1" ;
if ($result)
{
return $result[0] ;
}else
{
return false;
}
}
return false;
}
$query = " select * from posts where postid = '$postid' limit 1" ;
return false;
}
11 | P a g e
if (is_array($result)) {
if ($result[0]['userid'] == $mybook_userid) {
return true;
}
}
return false;
}
$likes = json_decode($result[0]['likes'],true);
return $likes;
}
}
return false;
}
if ($type == "post") {
$likes = json_decode($result[0]['likes'],true);
if(!in_array($mybook_userid,$user_ids)) {
$arr["userid"] = $mybook_userid;
$arr["date"] = date("Y-m-d H:i:s");
$likes[] = $arr;
12 | P a g e
$likes_string = json_encode($likes);
$sql = "update likes set likes = '$likes_string' where type ='post' &&
contentid = '$id' limit 1";
$DB->save($sql);
}else{
$likes_string = json_encode($likes);
$sql = "update likes set likes = '$likes_string' where type ='post' &&
contentid = '$id' limit 1";
$DB->save($sql);
}else{
$arr["userid"] = $mybook_userid;
$arr["date"] = date("Y-m-d H:i:s");
$arr2[] = $arr;
$likes = json_encode($arr2);
$sql = "insert into likes (type,contentid,likes) values ('$type','$id','$likes')";
$DB->save($sql);
$length = rand(4,19);
$number = "";
for ($i=0; $i < $length ; $i++) {
# code...
13 | P a g e
$new_rand = rand(0,9);
return $number;
}
}
14 | P a g e
Profile .php
<?php
class Profile
{
function get_profile($id){
$id = addslashes($id);
$DB = new Database();
$query = "select * from users where userid = '$id' limit 1";
return $DB->read($query);
}
}
user .php
15 | P a g e
<?php
class User
{
$query= " select * from users where userid = $id limit 1";
if ($result)
{
$row = $result[0];
return $row;
}else
{
return false;
}
}
if ($result)
{
return $result[0];
}else
{
return false;
}
}
if ($result)
{
return $result;
16 | P a g e
}else
{
return false;
}
}
image .php
<?php
17 | P a g e
class Image
{
$array =
array(0,1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','
C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
$text = "";
$random = rand(0,61);
$text .= $array[$random];
}
return $text;
}
if (file_exists($orignal_file_name))
{
$orignal_image = imagecreatefromjpeg($orignal_file_name);
$orignal_width = imagesx($orignal_image);
$orignal_height = imagesy($orignal_image);
$new_width = $max_width;
$new_height = $orignal_height * $ratio;
}else
{
$new_height = $max_height;
$new_width = $orignal_width * $ratio;
}
}
18 | P a g e
//adjust incase max width and height are diffrent
if($max_width != $max_height)
{
if ($max_width != $max_height)
{
if ($max_height > $max_width)
{
}else
19 | P a g e
{
if ($max_width > $new_width)
{
$adjustment = ($max_width / $new_width);
}else
{
$adjustment = ($new_width / $max_width);
}
}
}
imagedestroy($orignal_image);
if ($max_width != $max_height)
{
if ($max_width > $max_height)
{
$y = round($diff / 2);
$x = 0;
}else
{
}else
{
if ($new_height > $new_width)
{
20 | P a g e
$x = 0;
}else
{
imagedestroy($new_image);
imagejpeg($new_cropped_image,$cropped_file_name, 90);
imagedestroy($new_cropped_image);
}
if (file_exists($orignal_file_name))
{
$orignal_image = imagecreatefromjpeg($orignal_file_name);
$orignal_width = imagesx($orignal_image);
$orignal_height = imagesx($orignal_image);
$new_width = $max_width;
$new_height = $orignal_height * $ratio;
}else
{
$new_width = $max_height;
$new_height = $orignal_width * $ratio;
}
}
21 | P a g e
//image adjustment for profile and cover image
if ($max_width != $max_height)
{
if ($max_height > $max_width)
{
}else
{
if ($max_width > $new_width)
{
$adjustment = ($max_width / $new_width);
}else
{
$adjustment = ($new_width / $max_width);
}
}
}
imagedestroy($orignal_image);
imagejpeg($new_image,$resized_file_name, 90);
imagedestroy($new_image);
}
22 | P a g e
{
return $thumbnail;
}
$this->crop_image($filename,$thumbnail,1366,488);
if (file_exists($thumbnail))
{
return $thumbnail;
}else
{
return $filename;
}
}
$this->crop_image($filename,$thumbnail,600,600 );
if (file_exists($thumbnail))
{
return $thumbnail;
}else
{
return $filename;
}
}
$this->crop_image($filename,$thumbnail,600,600);
if (file_exists($thumbnail))
{
return $thumbnail;
23 | P a g e
}else
{
return $filename;
}
}
}
header .php
<?php
$corner_image = "images/user_male.jpg";
if (isset($USER)){
if(file_exists($USER['profile_image']))
{
$image_class = new Image();
$corner_image = $image_class->get_thumb_profile($USER['profile_image']);
24 | P a g e
}else{
if ($USER['gender'] == "Female") {
$corner_image = "images/user_female.jpg";
}
}
}
?>
<a href="logout.php">
<span style="font-size: 13px; float: right;margin: 10px;color: white;">Logout</span>
</a>
</div>
</div>
delete .php
<?php
include("classes/autoload.php");
25 | P a g e
$Post = new Post();
$ERROR = "";
if (isset($_GET['id'])) {
$ROW = $Post->get_one_post($_GET['id']);
if (!$ROW ) {
if ($ROW['userid'] != $_SESSION['mybook_userid']) {
}else{
$Post->delete_post($_POST['postid']);
header("Location: profile.php");
die;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Delete | Mybook</title>
</head>
<style type="text/css">
#blue_bar{
height: 50px;
background-color: #405d9b;
color: #d9dfeb;
#search_box{
26 | P a g e
width: 400px;
height: 20px;
border-radius: 5px;
border: none;
padding: 4px;
font-size: 14px;
background-image: url(search.png);
#profile_pic{
width: 150px;
border-radius: 50%;
border: solid 2px white;
}
#menu_buttons{
width: 100px;
display: inline-block;
margin: 2px;
}
#friends_img{
width:75px;
float: left;
margin: 8px;
#friends_bar{
min-height: 400px;
margin-top: 20px;
padding: 8px;
text-align: center;
font-size: 20px;
color: #405d9b;
}
#friends{
clear: both;
font-size: 12px;
font-weight: bold;
color: #405d9b;
}
textarea{
27 | P a g e
width: 100%;
border: none;
font-family: tahoma;
font-size: 14px;
height: 60px;
#post_button{
float: right;
background-color: #405d9b;
border: none;
color: white;
padding: 4px;
font-size: 14px;
border-radius: 2px;
width: 50px;
}
#post_bar{
margin-top: 20px;
background-color: white;
padding: 10px;
}
}
</style>
<br>
<!-- Top Bar -->
<?php include ("header.php"); ?>
<form method="post">
28 | P a g e
<?php
if ($ERROR != "") {
echo $ERROR;
}else{
include("post_delete.php");
echo "<input type='hidden'
name='postid' value='$ROW[postid]'>";
echo "<input id='post_button'
type='submit' value='Delete'>";
}
?>
<br>
</form>
</div>
</div>
</div>
</div>
</body>
</html>
Code efficiency is directly linked with algorithmic efficiency and the speed of runtime
execution for software. It is the key element in ensuring high performance. The goal of code
efficiency is to reduce resource consumption and completion time as much as possible with
minimum risk to business or operating environment.
One of the recommended best practices in coding is to ensure good code efficiency. Well developed
programming codes should be able to handle complex algorithms.
29 | P a g e
Recommendations for code efficiency include:
A test approach is the test strategy implementation of a project, defines how testing would be carried
out. Test approach has two techniques:
• Proactive - An approach in which the test design process is initiated as early as possible in
order to find and fix the defects before the build is created.
• Reactive - An approach in which the testing is not started until after design and coding are
completed.
• Consultative approaches
• Approaches based on risk-based testing where the entire development takes place based on
the risk
Factors to be considered:
• Risks of product or risk of failure or the environment and the company.
• Expertise and experience of the people in the proposed tools and techniques.
• Regulatory and legal aspects, such as external and internal regulations of the development
process.
30 | P a g e
• The nature of the product and the domain
• Black-Box Testing- Using which the user interface, input and output are tested.
• White-Box Testing- used to test each one of those functions behavior is tested.
• Grey-Box Testing- Used to execute tests, risks and assessment method.
• Big bang Approach: Big Bang Integration Testing is an integration testing strategy
wherein all units are linked at once, resulting in a complete system
31 | P a g e
• Top down Integration: Top-down integration testing is an integration testing
technique used in order to simulate the behavior of the lower-level modules that are
not yet integrated.
• Bottom up Integration: Bottom-up testing is an approach to integrated testing where
the lowest level components are tested first, then used to facilitate the testing of
higher level components.
• Hybrid Integration: A hybrid integration platform is a combination of on-premise
and cloud based system, securely connected using a technology like Transport Layer
Security, so that it supports the integration of on-premise endpoints, cloud endpoints
and the combination of the two, for all integration patterns.
32 | P a g e
RESULTS AND DISCUSSIONS
33 | P a g e
65 | P a g e
Chapter 6
34 | P a g e
35 | P a g e
36 | P a g e
37 | P a g e
38 | P a g e
39 | P a g e
40 | P a g e
41 | P a g e
42 | P a g e
43 | P a g e
44 | P a g e
CONCLUSION
45 | P a g e
Chapter 7
Conclusion
7.1 Conclusion
Basically we can have a smooth and easy interaction on website where people can make
friends online and have great social network.
Another benefit is it is a great platform where people from all over the globe can
connect share their ideas and culture and ofcourse make friends online and grow their
social network.
7.2 Limitation
Still on growing phase. updates to be added.
7.4 Reference
46 | P a g e