Beispiel #1
0
function add_friend($sender, $new_friend)
{
    if (account_exists($new_friend)) {
        if (!already_friend($sender, $new_friend)) {
            add_friend_to_db($sender, $new_friend);
            print "";
        } else {
            print "<div id=" . "output" . "> Oh, haha. You're friends with this guy already. </div>";
        }
    } else {
        print "<div id=" . "output" . "> That friend doesn't exist. Try a different friend? </div>";
    }
}
<?php

require_once "../includes/session.php";
require_once "../includes/db_connection.php";
require_once "../includes/functions.php";
if (!isset($_SESSION["user_id"])) {
    set_error_output("Please log in to add friend. ", "log_in.php");
} else {
    if (!isset($_GET["user"])) {
        set_error_output("Invalid friend. ", "index.php");
    } else {
        if ($_SESSION["user_id"] == $_GET["user"]) {
            set_error_output("Cannot add yourself to your own friends list. ", "index.php");
        } else {
            if (already_friend($_SESSION["user_id"], $_GET["user"])) {
                set_error_output("That user is already on your friends list. ", "user.php?user="******"user"]));
            }
        }
    }
}
add_friend($_SESSION["user_id"], $_GET["user"]);
redirect_to("user.php?user="******"user_id"]);