예제 #1
0
if ($guestbookEntries === null) {
    $guestbookEntries = [];
}
$errors = [];
$newEntry = false;
$name = $_POST['name'] ?? '';
$message = $_POST['message'] ?? '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if ($name === '') {
        $errors[] = 'Bitte gib einen Namen ein.';
    }
    if ($message === '') {
        $errors[] = 'Bitte gib eine Nachricht ein.';
    }
    if (count($errors) === 0) {
        saveToDatabase($name, $message);
        // Bestätigungsnachricht anzeigen
        $newEntry = true;
        // Formularfelder leeren
        $name = '';
        $message = '';
    }
}
function saveToDatabase(string $name, string $message)
{
    global $database, $guestbookEntries;
    $newEntry = ['name' => $name, 'message' => $message];
    // Eintrag an Anfang von Array einfügen
    array_unshift($guestbookEntries, $newEntry);
    // Daten in File schreiben
    file_put_contents($database, json_encode($guestbookEntries));
예제 #2
0
$totalPosts = 0;
// for each main url
foreach ($revolicoMainUrls as $url) {
    echo "CRAWLING {$url}\n";
    // get the list of pages that have not been inserted yet
    $pages = getRevolicoPagesFromMainURL($url);
    // calculate the total number of posts
    $totalPosts += count($pages);
    echo "PROCESSING URLs {$url}\n";
    // for every page
    for ($i = 0; $i < count($pages); $i++) {
        echo "SAVING PAGE {$i}/" . count($pages) . "\n";
        // get the page's data and images
        $data = crawlRevolicoURL($pages[$i]);
        // save the data into the database
        saveToDatabase($data);
        echo "\tMEMORY USED: " . convert(memory_get_usage(true)) . "\n";
    }
}
// close the connection
mysqli_close($conn);
// ending message, log and time
$totalTime = (time() - $timeCrawlerStart) / 60;
// time in minutes
$totalMem = convert(memory_get_usage(true));
$message = "CRAWLER ENDED - EXECUTION TIME: {$totalTime} min - NEW POSTS: {$totalPosts} - TOTAL MEMORY USED: {$totalMem}";
saveCrawlerLog($message);
echo "\n\n{$message}\n\n";
// save last run time
$tmpRunPath = dirname(__DIR__) . "/temp/crawler.revolico.last.run";
file_put_contents($tmpRunPath, date("Y-m-d H:i:s") . "|{$totalTime}|{$totalPosts}|{$totalMem}");
예제 #3
0
<?php

$_POST['mail-1'] = substr(htmlspecialchars(trim($_POST['mail-1'])), 0, 200);
$_POST['mail-2'] = substr(htmlspecialchars(trim($_POST['mail-2'])), 0, 200);
$_POST['mail-3'] = substr(htmlspecialchars(trim($_POST['mail-3'])), 0, 200);
$email = $_POST['mail-1'] . $_POST['mail-2'] . $_POST['mail-3'];
$gender = $_POST['gender'];
$buy = $_POST['buy'];
$season = $_POST['season'];
function saveToDatabase($db_name, $data)
{
    file_put_contents($db_name, $data, FILE_APPEND | LOCK_EX);
}
if ($gender === null) {
    $mess = $email . "\r\n";
    saveToDatabase("mail.csv", $mess);
}
if ($gender != null) {
    $mess = $email . ";" . $gender . ";" . $buy . ";" . $season . "\r\n";
    saveToDatabase("mail-ext.csv", $mess);
}
예제 #4
0
session_start();
if ($_POST['test_incomplete'] == 'true') {
    // we're doing a test that includes reloading something
    // wait for the next POST before saving data
    if (isset($_SESSION['partial_data'])) {
        $_SESSION['partial_data'] .= $_POST['data'];
    } else {
        $_SESSION['partial_data'] = $_POST['data'];
    }
} else {
    if (isset($_SESSION['partial_data']) && !empty($_SESSION['partial_data'])) {
        // we have an incomplete data set already. This SHOULD be the final post in the series, so let's save it..
        saveToDatabase($_POST['test'], $_SERVER['HTTP_USER_AGENT'], $_SESSION['partial_data'] . $_POST['data'], $_POST['passed_test']);
        $_SESSION['partial_data'] = '';
    } else {
        saveToDatabase($_POST['test'], $_SERVER['HTTP_USER_AGENT'], $_POST['data'], $_POST['passed_test']);
    }
}
function saveToDatabase($test, $ua, $data, $passed_test)
{
    //echo 'saving '.$test.' '.$ua.' '.$data;
    $link = mysql_connect('localhost', 'root', '');
    mysql_select_db('test_stats');
    $ua = mysql_escape_string($ua);
    $test = mysql_escape_string($test);
    $passed_test = mysql_escape_string($passed_test);
    $data = mysql_escape_string($data);
    $query = mysql_query('SELECT * FROM load_events WHERE UA LIKE "' . $ua . '" AND test LIKE "' . $test . '"');
    if (mysql_num_rows($query) == 0) {
        $sql = 'INSERT INTO load_events (UA, test, data, passed_test) VALUES ( "' . $ua . '", "' . $test . '", "' . $data . '", "' . $passed_test . '"  )';
    } else {
예제 #5
0
	</head>
	<body>
		<?php 
require 'functions.php';
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(-1);
// log file
$file = "output.txt";
// check if file exists
if (!file_exists($file)) {
    print 'ERROR (receive.php): File not found';
} else {
    if (!($fh = fopen($file, 'a'))) {
        print 'ERROR (receive.php): Can\'t open file';
    } else {
        if (isset($_GET['days_array'])) {
            fwrite($fh, PHP_EOL . PHP_EOL . "---------------------------------------------------------------------------------------------------------------------");
            fwrite($fh, date("m/d/Y h:i:s a", time()) . ": writing to database" . PHP_EOL);
            saveToDatabase($fh, $_GET['days_array'], $_GET['starting_times_array'], $_GET['ending_times_array'], $_GET['classes_array']);
            fclose($fh);
        } else {
            echo "No access lad";
        }
    }
}
?>
	</body>
</html>

예제 #6
0
{
    $values = array_map('mysql_real_escape_string', array_values($inserts));
    $keys = array_keys($inserts);
    return mysql_query('INSERT INTO `' . $table . '` (`' . implode('`,`', $keys) . '`) VALUES (\'' . implode('\',\'', $values) . '\')');
}
function saveToDatabase($object)
{
    include "db.php";
    mysql_connect($dbhost, $dbuser, $dbpass);
    mysql_select_db($dbname);
    $result = mysql_insert('android', $object);
    if (!$result) {
        die('Invalid query: ' . mysql_error());
    }
    mysql_close();
}
//Check if HTTP POST
if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
    foreach ($_POST as $key => $value) {
        //Check if json key
        if (strtolower($key) == 'json') {
            //Get JSON from POST
            $json = json_decode($value, true);
            //Convert time from RFC 3339 to MySQL Timestamp
            date_default_timezone_set('Europe/Berlin');
            $json['USER_CRASH_DATE'] = date("Y-m-d H:i:s", parse_date($json['USER_CRASH_DATE']));
            //Save report to database
            saveToDatabase($json);
        }
    }
}