Proje Php de basit takipçi sistemidir. Bu proje takipçi sisteminin mantığını basitçe anlamanızı sağlayacaktır.
İndex.php Sayfası
Kod:
<html>
<head>
<title> Takipçi Sistemi</title>
<link rel='stylesheet' href='style.css'/>
</head>
<body>
<?php include 'connect.php'; ?>
<?php include 'functions.php'; ?>
<?php include 'header.php'; ?>
<div id='body'>
</div>
</body>
</html>
actions.php Sayfası
Kod:
<?php
include 'connect.php';
include 'functions.php';
$my_id=@$_SESSION('user_id');
$action=$_GET['action'];
$u_id=$_GET['u_id'];
if($action=='follow')
{
mysql_query("INSERT INTO follow VALUES('','$my_id','$u_id')");
}
if($action=='unfollow')
{
mysql_query("DELETE FROM 'follow' WHERE 'user_one'='$my_id' AND 'user_two'='$u_id'");
}
header('********: profile.php?u_id='.$u_id);
?>
connect.php Sayfası
Kod:
<?php
@$connect=mysql_connect('localhost','root','');
if($connect)
{
mysql_select_db('twitter');
}
else
{
echo "Host Connecting Error!";
}
?>
functions.php Sayfası
Kod:
<?php
session_start();
function loggedin()
{
if(isset($_SESSION['user_id'])&&!empty($_SESSION['user_id']))
{
return true;
}
else
{
return false;
}
}
function getuser($field, $user_id){
$query=mysql_query("SELECT $field FROM users WHERE id='$user_id'");
$run=mysql_fetch_array($query);
return $run[$field];
}
?>
header.php Sayfası
Kod:
<div id='header'>
<div id='left'>
<b>Takipçi Sistemi</b>
</div>
<div id='right'>
<a href='index.php'>Anasayfa</a>
<?php
if(loggedin())
{
?>
<a href='profile.php'>Profil</a>
<a href='logout.php'>Çıkış</a>
<?php
} else{
?>
<a href='login.php'>Giriş</a>
<a href='register.php'>Kayıt Ol</a>
<?php
}
?>
</div>
<div class='clear'></div>
</div>
login.php Sayfası
Kod:
<html>
<head>
<title>Giriş-Takipçi Sistemi</title>
<link rel='stylesheet' href='style.css'/>
</head>
<body>
<?php include 'connect.php'; ?>
<?php include 'functions.php'; ?>
<?php include 'header.php'; ?>
<div id='body'>
<b>Giriş Yap</b>
<br/><br/>
<form method='post'>
<?php
if(isset($_POST['submit']))
{
$username=$_POST['username'];
$password=$_POST['password'];
if(empty($username)or empty($password))
{
$message="Boş bıraktınız!";
}else{
$check=mysql_query("SELECT id FROM users WHERE username='$username'AND password='".md5($password)."'");
if(mysql_num_rows($check==0))
{
$message="Kullanıcı adı veya şifre yanlış";
}
else{
$run=mysql_fetch_array($check);
$id=$run['id'];
$_SESSION['user_id']=$id;
header('********:index.php');
}
}
echo "<div id='box'>$message</div>";
}
?>
Kullanıcı Adı:<br/>
<input type='text' name='username'/>
<br/><br/>
Şifre:<br/>
<input type='password' name='password'/>
<br/><br/>
<input type='submit' name='submit' value='Giriş'/>
</form>
</div>
</body>
</html>
logout.php Sayfası
Kod:
<?php
include 'functions.php';
session_destroy();
header('********:index.php');
?>
profile.php Sayfası
Kod:
<html>
<head>
<title> Takipçi Sistemi</title>
<link rel='stylesheet' href='style.css'/>
</head>
<body>
<?php include 'connect.php'; ?>
<?php include 'functions.php'; ?>
<?php include 'header.php'; ?>
<div id='body'>
<?php
$my_id=$_SESSION['user_id'];
if(isset($_GET['u_id'])&&!empty($_GET['u_id'])){
$u_id=$_GET['u_id'];
}else{
$u_id=$_SESSION['user_id'];
}
echo '<b>'.getuser('username',$u_id).'</b>';
?>
<hr/>
<br/>
<?php
if($u_id!=$_SESSION['user_id'])
{
$check=mysql_query("SELECT id FROM follow WHERE user_one='$my_id' AND user_two='$u_id'");
if(mysql_num_rows($check)==1)
{
echo "<a href='actions.php?action=unfollow&u_id=$u_id'>UnFollow</a>";
}else{
echo "<a href='actions.php?action=follow&u_id=$u_id'>Follow</a>";
}
}
?>
<hr/>
Followers:
<?php
$check_followers=mysql_query("SELECT id FROM follow WHERE user_two='$u_id'");
echo mysql_num_rows($check_followers);
?>
<br/>
Followings:
<?php
$check_followings=mysql_query("SELECT id FROM follow WHERE user_one='$u_id'");
echo mysql_num_rows($check_followings);
?>
</div>
</body>
</html>
register.php
Kod:
<html>
<head>
<title>Kayıt Ol-Takipçi Sistemi</title>
<link rel='stylesheet' href='style.css'/>
</head>
<body>
<?php include 'connect.php'; ?>
<?php include 'functions.php'; ?>
<?php include 'header.php'; ?>
<div id='body'>
<b>Kayıt Ol</b>
<br/><br/>
<form method='post'>
<?php
if(isset($_POST['submit']))
{
$username=$_POST['username'];
$password=$_POST['password'];
if(empty($username)or empty($password))
{
$message="Boş bırakılamaz!";
}else{
mysql_query("INSERT INTO users VALUES('','$username','".md5($password)."')");
$message="Kayıt Oldun";
}
echo "<div id='box'>$message</div>";
}
?>
Kullanıcı Adı:<br/>
<input type='text' name='username'/>
<br/><br/>
Şifre:<br/>
<input type='password' name='password'/>
<br/><br/>
<input type='submit' name='submit' value='Kayıt Ol'/>
</form>
</div>
</body>
</html>
style.css Sayfası
Kod:
body{
background:#333;
color:#fff;
font-family:lucida sans unicode;
font-size:14px;
margin:0px;
padding:0px;
}
input{
background:#333;
color:#fff;
font-family:lucida sans unicode;
font-size:14px;
padding:10px;
border:0px;
margin:10px 0px;
}
#header{
background:#4aaee7;
color:#fff;
padding:15px;
}
#box{
background:#333;
color:#fff;
padding:10px;
margin:10px 0px;
}
#left{
float:left;
}
#right{
float:right;
}
#header a{
background:#4aaee7;
color:#fff;
text-decoration:none;
padding:10px;
}
#header a:hover{
background:#fff;
color:#4aaee7;
}
#body{
color:#333;
background:#fff;
padding:10px;
width:50%;
margin:30px auto;
min-height:500px;
}
.clear
{
clear:both;
}
Projenin veritabanı adı twitter olarak verdim ben siz istediğiniz ismi verebilirsiniz. Veritabanımızda iki tane tablo bulunmaktadır. Biri kullanıcıları tutuğumuz users ve kullanıcıların takipçilerini tutuğumuz follow tablolarıdır.
users tablosu mysql de aşağıdaki gibidir.
follow tablosu mysql de aşağıdaki gibidir.
Faydalı olması dileğiyle Richard Jackson...