Пример #1
0
function get_from_url($config)
{
    global $debug;
    // try to get the url
    $url = 'http://search.twitter.com/search.json?rpp=100&q=' . urlencode($config['twitter']['search']);
    if (isset($config['twitter']['since_id'])) {
        $url .= '&since_id=' . $config['twitter']['since_id'];
    }
    if ($debug) {
        echo $url . "\n";
    }
    if ($debug === true) {
        return test_data();
    }
    $json = '';
    $handle = fopen($url, 'r');
    // check to make sure the URL didn't fail for some reason
    if ($handle) {
        while (!feof($handle)) {
            // loop through and build the XML file
            $json .= fread($handle, 1024);
        }
        // clean-up the file pointers
        fclose($handle);
    } else {
        // fopen failed for some reason!!!
        exit('There was an error fetching the URL');
    }
    if ($json == '') {
        // the XML is blank, nothing was pulled from the URL!!!
        exit('There was an error fetching the XML!');
    }
    return $json;
}
Пример #2
0
<?php

function addNewChat($post)
{
    mysql_connect("devweb2014.cis.strath.ac.uk", "rnb12162", "consista");
    mysql_select_db("rnb12162") or die(mysql_error());
    mysql_query("INSERT INTO chat (message)\n      VALUES ('{$post}')") or die(mysql_error());
    header('Location: chat.html');
}
function test_data($data)
{
    // Make a connection
    $conn = mysql_connect("devweb2014.cis.strath.ac.uk", "rnb12162", "consista");
    // Selecting Database
    $db = mysql_select_db("rnb12162") or die(mysql_error());
    $data = trim($data);
    $data = stripslashes($data);
    $data = mysql_real_escape_string($data);
    $data = htmlspecialchars($data);
    return $data;
}
$post = test_data($_POST['message']);
addNewChat($post);
?>