Answer the question
In order to leave comments, you need to log in
How to create news from a file in the root of the site or another folder?
Hello!
I'm trying to create a script that will create news not from a form on the site, but from a file by sending a post request to the form.
Here is my code:
<?php
ini_set('display_errors', 'On');
include ('engine/api/api.class.php');
//Получаю hash
$row = $db->super_query( "SELECT hash FROM " . USERPREFIX . "_users WHERE name = 'Ivan'" );
$member_id['hash'] = $row['hash'];
$member_id['user_id'] = '1';
$member_id['password'] = '$2y$10$LW3PRJTfN2LG7xwmtPVRN.IHXE/qdpUH.zoMnV9MeQ9HdzmIFFWai';
$dle_login_hash = sha1( SECURE_AUTH_KEY . $member_id['user_id'] . sha1($member_id['password']) . $member_id['hash'] );
$duplicateprotection = md5(SECURE_AUTH_KEY.time());
$url = 'https://site.ru/index.php?do=addnews'; // url, на который отправляется запрос
$headers = ['Content-Type: application/x-www-form-urlencoded']; // заголовки нашего запроса
$post_data = [ // поля нашего запроса
'title' => 'Как твои дела, Друг?',
'alt_name' => '1de11lad',
'catlist' => '1',
'vote_title' => '',
'frage' => '',
'vote_body' => '',
'short_story' => 'iufgt oitoiutgoi goito 1',
'full_story' => '',
'tags' => 'val',
'approve' => '1',
'allow_comm' => '1',
'allow_main' => '1',
'allow_rating' => '1',
'add' => '',
'mod' => 'addnews',
'user_hash' => '' . $dle_login_hash . '',
'duplicateprotection' => '' . $duplicateprotection . ''
];
$headers = []; // заголовки запроса
$post_data = http_build_query($post_data);
$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true); // true - означает, что отправляется POST запрос
$result = curl_exec($curl);
echo $result;
echo $dle_login_hash. '<br />';
echo $duplicateprotection;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question