Forgot Password / Register
Site Statistics
Total Members: 520
Total Tutorials: 242
Newsest User: 8884244477
Todays Unique Hits: 190
0 Users 10 Guests Online

Friendlist and Blocklist + Msg URLs to Members

In this tutorial you will be able to keep track of your friends and ignore people.

This tutorial is quite long so bear with me.

First let's SQL the blocklist. You should have the tables `friends` and `friend_requests` from new2old's Friend System.

Code

CREATE TABLE `blocklist` (
`id` int(10) NOT NULL auto_increment,
`foe` varchar(225) NOT NULL default '',
`username` varchar(225) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM;


Ok, now its time to create your Friend list. Call this my_friends.php

PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
include ('config.php');
switch(
$_GET[page]){ //make some links ?page=case

case 'deleteall'// delete page
$delete mysql_query"DELETE FROM `friends` WHERE `username` = '$logged[username]' "); // deletes friend request
echo ( "You have deleted all your friends." ); // echos completion
break; //ends delete page

case 'delete'// delete page
if ($_GET[user]) { //get username
$delete mysql_query"DELETE FROM `friends` WHERE `friendname` = '$_GET[user]' "); // deletes friend request
echo ( "$_GET[user] has been deleted from your friendlist." ); // echos completion
}
break; 
//ends delete page

case 'msgto'// delete page
$getuser mysql_query("SELECT * FROM `members` WHERE `id` = '$_GET[user]'");
$suser mysql_fetch_array($getuser); 
if (
$_GET[user]) { //get username
if(!$_POST[send]){ //if the form was not submitted
echo "<style>
form#sendmsg
{
background:#DFF6FF;
border: 1px solid #4B9EBE;
padding: 8px;
width: 390px;
}
input
{
background:#F1F6F8;
border:1px solid #4B9EBE;
color: #397D97;
}
textarea
{
background:#F1F6F8;
border:1px solid #4B9EBE;
color: #397D97;
font-family: tahoma;
font-size:12px;
padding: 4px;
}
</style>
<form method=\\"
post\\" action=\\"\\" id=sendmsg>
<b>To User</b>:"
//echo some of the form and whatnot
if(isset($_GET[user])){ //check if there is a user in the address bar
echo "<input type=\\"text\\" name=\\"to\\" value=\\"$_GET[user]\\" size=\\"15\\" readonly=yes>
<br>Sending message to 
$suser[username]"//if there is
}else{ //or not..
echo "<input type=\\"text\\" name=\\"to\\" size=\\"15\\">"//echo the input box without the value of the user!
//end user check in address bar
echo "<br><b>Subject</b>:
<input type=text name=title value=Message size=15><br>
<br><b>Message</b>:<br>
<textarea name=message rows=7 cols=68></textarea><br><br>
<input type=submit name=send value=Send Message> - <a href=\\"
inbox.php\\">Go Back</a>
</form>"
//echo the rest of the form
}else{ //or if it was....
$to stripslashes(htmlspecialchars(strip_tags($suser[username]))); //who its to
$from $logged[username]; //who its from
$date date("F j, Y, g:i a"); //the date sent
$msg addslashes($_POST[message]); //the message variable
$subject addslashes($_POST[title]); //the subject
$do mysql_query("INSERT INTO `privates` (`to`,`from`,`date`,`subject`,`content`) VALUES ('" $to "','" $from "','" $date "','" $subject "','" $msg "')") or die(mysql_error()); //insert into the table!
echo "Message Sent! Returning back...<meta http-equiv=refresh content=1;url=http://sodadome.com/inbox.php>";
//end sent check
}
break; 
//end make new msg

default: //set up the default page upon going to inbox.php

$afed mysql_query("SELECT * FROM `friends` WHERE `username` = '$logged[username]' ORDER BY `id` ASC") or die(mysql_error()); 
//loops there name out 
echo "<div id='title'>My Friends</div>

<br><a href='?page=deleteall'>Delete All Friends</a><br> <style>
table {
background: #D1E8F7;
padding: 4px;
width: 400px;
border: 1px solid #2694DC;
color: #3C769C;
}
tr#top {
background: #B4DBF5;
}
</style><br><center>
<table align=center><tr align='center' id='top'><td>Username</td><td>Send Message</td><td>Remove</td></tr>"
;
while (
$fr mysql_fetch_array($afed)) { 
    
$fid mysql_query("SELECT * FROM `members` WHERE `username` = '$fr[friendname]'") or die(mysql_error()); 
$fri mysql_fetch_array($fid);
echo 
"<tr align='center'><td><a href='http://sodadome.com/members.php?user=$fri[id]'>$fr[friendname]</a></td><td><a href='http://sodadome.com/members.php?page=msgto&amp;user=$fri[id]'><img src='http://sodadome.com/scp/email_go.png' border='0' title='Send Message'></a></td><td><a href='?page=delete&amp;user=$fr[friendname]'><img src='http://sodadome.com/phpimgs/cross.png' border='0' title='Remove Friend?'></a></td></tr>";
}
echo 
"</table></center>";
break;
}


?>


If you have at least one friend, it will show up. If not it will say "You have no friends."

From there you have two options - Message them or Remove from friendlist.

Now onto the Blocklist. Lets name this file blocklist.php

PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php 
include ('config.php');
switch(
$_GET[page]){ //make some links ?page=case

case 'deleteall'// delete page
$delete mysql_query"DELETE FROM `blocklist` WHERE `username` = '$logged[username]' "); // deletes friend request
echo ( "You have unblocked all your foes." ); // echos completion
break; //ends delete page

case 'block'// delete page
if ($_GET[user]){ //gets username
$thefoe htmlspecialchars($_GET[user]); //friend
$query mysql_query("INSERT INTO `blocklist` ( `username` , `foe` ) VALUES ( '$logged[username]' , '$thefoe' )"); //inserts the request
echo ( "You have blocked $thefoe. They cannot send you PMs anymore." ); // echos completion
}
break;

case 
'delete'// delete page
if ($_GET[user]) { //get username
$delete mysql_query"DELETE FROM `blocklist` WHERE `foe` = '$_GET[user]' "); // deletes friend request
echo ( "$_GET[user] has been unblocked." ); // echos completion
}
break; 
//ends delete page

default: //set up the default page upon going to inbox.php
$afed mysql_query("SELECT * FROM `blocklist` WHERE `username` = '$logged[username]' ORDER BY `id` ASC") or die(mysql_error()); 
//loops there name out 
echo "<div id='title'>Blocklist</div>

<br><a href='?page=deleteall'>Delete All Foes</a><br> <style>
table {
background: #D1E8F7;
padding: 4px;
width: 400px;
border: 1px solid #2694DC;
color: #3C769C;
}
tr#top {
background: #B4DBF5;
}
</style><br><center>
<table align=center><tr align='center' id='top'><td>Username</td><td>Remove</td></tr>"
;
$get mysql_query("SELECT * FROM `blocklist` WHERE `username` = '" $logged[username] . "'"); //get the private messages
$enemys mysql_query("SELECT * FROM `blocklist` WHERE `username` = '$logged[username]' ORDER BY `id` ASC") or die(mysql_error()); 
if(
mysql_num_rows($get) == "0"){
    echo 
"<tr align='center'><td colspan='2'>You Have No Enemies!</td></tr></table>";
}else{
while (
$e mysql_fetch_array($enemys)) { 
    
$fid mysql_query("SELECT * FROM `members` WHERE `username` = '$e[foe]'") or die(mysql_error()); 
$fri mysql_fetch_array($fid);
echo 
"<tr align='center'><td><a href='http://sodadome.com/members.php?user=$fri[id]'>$e[foe]</a></td><td><a href='?page=delete&amp;user=$e[foe]'><img src='http://sodadome.com/phpimgs/cross.png' border='0' title='Unblock User'></a></td></tr>";
}
echo 
"</table></center>";
}
break;
}

?>


Now for go to where you show your member's profile (usually members.php) and find

PHP Code
1
2
//if it does exist then show there profile
$user = mysql_fetch_array($getuser);


and below it add:

PHP Code
1
2
3
4
$getfoe = mysql_query("SELECT * FROM `blocklist` WHERE `foe` = '$user[username]'");
$en = mysql_fetch_array($getfoe); 
$getfriend = mysql_query("SELECT * FROM `friends` WHERE `friendname` = '$user[username]'");
$fa = mysql_fetch_array($getfriend);

then in the same file find: where it has like Age, Location, email, etc.

and add:

PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
";
if ($user[username] == $fa[friendname]){
    echo "<a href='http://sodadome.com/my_friends.php?page=delete&amp;user=$user[username]'><img src='http://sodadome.com/scp/user_add.png' border='0' title='Remove from friendlist'></a>";
    }else{
        echo "<a href='friendrequest.php?user=$user[username]'><img src='http://sodadome.com/scp/user_add.png' border='0' title='Add as friend'></a>";
    }
if ($user[username] == $en[foe]){
    echo "<a href='blocklist.php?page=delete&amp;user=$user[username]'><img src='http://sodadome.com/scp/user_block.png' border='0' title='Unblock user'></a>";
    }else{
        echo "<a href='members.php?page=block&amp;user=$user[username]'><img src='http://sodadome.com/scp/user_block.png' border='0' title='Block user'></a>";
    }
echo "<a href='members.php?page=msgto&amp;user=$user[id]'><img src='http://sodadome.com/scp/email_go.png' border='0' title='Send Message'></a></td></tr></table>";
echo "


Then upload it. Right-click the 3 images (add, ignore, message) and save as own and edit the image files in the php file above.

Ok now stay on same file (members.php) and find:

PHP Code
1
echo "$user[username]'s Profile


and add above it:

PHP Code
1
2
3
4
if ($logged[username] == $en[foe]){
    echo "<b>Error:</b> This user has blocked you.";
    }else{


then at the end of your PHP script where it says ?> add an extra }

Ok now to pms.php (or where you have your PM inbox stored)

Find

PHP Code
1
2
$to = stripslashes(htmlspecialchars(strip_tags($_POST[to]))); //who its to
$from = $logged[username]; //who its from


and add above it:

PHP Code
1
2
$getfoe = mysql_query("SELECT * FROM `blocklist` WHERE `foe` = '$logged[username]'");
$en = mysql_fetch_array($getfoe);


Now find... in case 'compose':
PHP Code
1
$do = mysql_query("INSERT INTO `privates` (`to`,`from`,`date`,`subject`,`content`,`sendself`) VALUES ('" . $to . "','" . $from . "','" . $date . "','" . $subject . "','" . $msg . "','" . $cc . "');") or die(mysql_error()); //insert into the table!


and above it add:

PHP Code
1
2
3
if ($_POST[send] && $_POST[to] == $en[username]){
    echo "<b>Error:</b> This user has blocked you from sending any PMs to you.";
    }else{


Now in the break; of case 'compose' add an extra } before it to close the else tag.

Now repeat the steps started from where it says 'find pms.php' and add the same thing to case 'view':.

now find:
PHP Code
1
</form>"; //echo the rest of the form


So yeah, thats about it. Post your errors, if any. You get.

Thanks for your time.
UrbanTwitch
Views:
2666
Rating:
Posted on Friday 22nd August 2008 at 08:35 PM
Dava
Dava
saintpaulos send me the content of you script via msn and ill sort it for ya pm me for addy
Posted on Thursday 21st August 2008 at 03:24 PM
saintpaulos
saintpaulos
thats not the bbcode then lol
Posted on Thursday 21st August 2008 at 03:23 PM
saintpaulos
saintpaulos
Also shouldn't it be?

[Code]
";
if ($user[username] == $fa[friendname]){
echo "<a href='my_friends.php?page=delete&amp;user=$user[username]'><img src='http://sodadome.com/scp/user_add.png' border='0' title='Remove from friendlist'></a>";
}else{
echo "<a href='friendrequest.php?user=$user[username]'><img src='http://sodadome.com/scp/user_add.png' border='0' title='Add as friend'></a>";
}
if ($user[username] == $en[foe]){
echo "<a href='blocklist.php?page=delete&amp;user=$user[username]'><img src='http://sodadome.com/scp/user_block.png' border='0' title='Unblock user'></a>";
}else{
echo "<a href='blocklist.php?page=block&amp;user=$user[username]'><img src='http://sodadome.com/scp/user_block.png' border='0' title='Block user'></a>";
}
echo "<a href='myfriends.php?page=msgto&amp;user=$user[id]'><img src='http://sodadome.com/scp/email_go.png' border='0' title='Send Message'></a></td></tr></table>";
echo "
[/Code]

I can't seem to get the myfriends.php to work at all. All I get is:

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in myfriends.php on line 46

Any help would be great! :)
Posted on Tuesday 19th August 2008 at 01:51 AM
UrbanTwitch
UrbanTwitch
yeah xD ooppppssss
Posted on Tuesday 19th August 2008 at 01:48 AM
Dava
Dava
and you need to change the following or it will block youself from viewing your own profile and let you view people who have blocked you's profiles

Code
$getfoe = mysql_query("SELECT * FROM `blocklist` WHERE `foe` = '$user[username]'");


to

Code
$getfoe = mysql_query("SELECT * FROM `blocklist` WHERE `username` = '$user[username]'");
Posted on Tuesday 19th August 2008 at 01:08 AM
Dava
Dava
well for 1 why use so many else functions in this scipt why not just use a simple

Code


if ($_POST[send] && $_POST[to] == $en[username]){
echo "<b>Error:</b> This user has blocked you from sending any PMs to you.";
}
{
}


that way ya dont get the telse error
Posted on Monday 18th August 2008 at 01:17 AM
UrbanTwitch
UrbanTwitch
such as?
Posted on Monday 18th August 2008 at 12:16 AM
Dava
Dava
its not the changing of code its the fact it didnt work yeah it was coded 95% right but still accounted a few errors
Posted on Sunday 17th August 2008 at 06:31 PM
UrbanTwitch
UrbanTwitch
Actually my base script is RMB's... :S
Posted on Sunday 17th August 2008 at 06:07 PM
jambomb
jambomb
gota change loads of stuff coz its all for his site quite annoying