<?php
function post($url, $data) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close ($ch);
return $output;
}
echo post("https://google.com", [
'foo' => 'bar'
]);
session_start();
$currentCookieParams = session_get_cookie_params();
$sidvalue = session_id();
if(!isset($_COOKIE['PHPSESSID'])) {
setcookie(
'PHPSESSID', //name
$sidvalue, //value
0, //expires at end of session
$currentCookieParams['path'], //path
$currentCookieParams['domain'], //domain
true //secure
);
}
<?php
$template = implode("\n", [
'<!DOCTYPE html>',
'<html lang="en">',
'<head>',
'<meta charset="UTF-8">',
'<title>Document</title>',
'</head>',
'<body>',
'<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Minima consectetur placeat, doloribus, qui eaque quas laborum fuga voluptas dolorum distinctio illo quibusdam quia cum, inventore quos. Quo ipsam sed asperiores.</p>',
'</body>',
'</html>'
]);
$response = array(
"html" => urlencode($template),
"show" => 'true'
);
header('Content-type: application/json; charset=utf-8');
$json = json_encode($response);
echo $json;
?>
<script>
var data = new FormData();
data.append("foo", "bar");
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === this.DONE) {
console.log(decodeURIComponent(this.responseText));
}
});
xhr.open("GET", "/ajax");
xhr.send(data);
</script>
<?php
function parseAudio($message) {
$matches = [];
$s = preg_match('/\[audio (.*?)\]/', $message, $matches);
return str_replace($matches[0], "<audio controls><source src=\"{$matches[1]}\" type=\"audio/wav\"></audio>", $message);
}
echo parseAudio("Message with audio\n[audio records/1517754431.wav]");
?>
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
//Load composer's autoloader
require 'vendor/autoload.php';
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user@example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('from@example.com', 'Mailer');
$mail->addAddress('joe@example.net', 'Joe User'); // Add a recipient
$mail->addAddress('ellen@example.com'); // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');
//Attachments
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "/ajax.php",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--\r\n",
CURLOPT_HTTPHEADER => array(
"content-type: multipart/form-data; boundary=---011000010111000001101001"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
<?php
$client = new http\Client;
$request = new http\Client\Request;
$body = new http\Message\Body;
$body->addForm(array(
'foo' => 'bar'
), NULL);
$request->setRequestUrl('/ajax.php');
$request->setRequestMethod('POST');
$request->setBody($body);
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
<?php
# подключаемся к базе данных
try {
$DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
$DBH->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}catch(PDOException $e) {
echo "Хьюстон, у нас проблемы.";
}
# данные, которые мы вставляем
$data = [
'type' => $_GET['type']
];
# делаем запрос
$STH = $DBH->prepare("select * from catalog where catalog.type = :type order by catalog.id desc");
$STH->execute($data);
# устанавливаем режим выборки
$STH->setFetchMode(PDO::FETCH_ASSOC);
# выводим результат
while($row = $STH->fetch()) {
echo "<div class=\"item active\">{$row['name']} - {$row['price']}</div>";
}
?>
<?php
$backgrounds = array_diff(scandir('./backgrounds/'), array('.','..','.DS_Store'));
$texts = array_diff(scandir('./texts/'), array('.','..','.DS_Store'));
$filters = array_diff(scandir('./filters/'), array('.','..','.DS_Store'));
function nameGenerator($length) {
return substr(str_shuffle("_0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $length);
}
//
foreach ($backgrounds as $background) {
//
foreach ($texts as $text) {
//
foreach ($filters as $filter) {
//
$layer1 = imagecreatefrompng("./backgrounds/{$background}");
$layer2 = imagecreatefrompng("./texts/{$text}");
$layer3 = imagecreatefrompng("./filters/{$filter}");
//
imagealphablending($layer1, true);
imagesavealpha($layer1, true);
//
imagecopy($layer1, $layer2, 0, 0, 0, 0, 900, 900);
imagecopy($layer1, $layer3, 0, 0, 0, 0, 900, 900);
//
imagejpeg($layer1, "./results/".nameGenerator(10).".jpg");
//
imagedestroy($layer1);
imagedestroy($layer2);
imagedestroy($layer3);
}
}
}
?>
<?php
// Задаем пароль
$password = "iddqd";
// Берем ссылку для редиректа из ?url=*
$link = array_key_exists("url", $_GET) ? $_GET['url'] : "http://google.com";
// Проверяем сабмит формы с паролем
if (array_key_exists("password", $_POST)) {
// Проверяем введенный пароль
if (strcasecmp($_POST['password'], $password) == 0) {
// Пароль совпал, редиректим
header("Location: {$link}");
}else{
// Пароли не совпали показываем ошибку
require_once 'error.php';
}
}else{
// Показываем форму для ввода пароля
require_once 'form.php';
}
?>
<?php
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
echo ' [*] Waiting for messages. To exit press CTRL+C', "\n";
$connection = new AMQPStreamConnection($AMQP);
$channel = $connection->channel();
$channel->queue_declare('test', false, false, false, false);
$callback = function($msg) {
global $channel;
$condition = json_decode($msg->body);
if (!$condition) {
$msg = new AMQPMessage(json_encode(array(
'condition' => false
)));
$channel->basic_publish($msg, '', 'test');
}
};
$channel->basic_consume('test', '', false, true, false, false, $callback);
while(count($channel->callbacks)) {
$channel->wait();
}
$channel->close();
$connection->close();
?>