I
I
Ivan2022-02-17 16:04:31
DLE
Ivan, 2022-02-17 16:04:31

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;


dle_login_hash is 100% up to date and similar to the user_hash of the addnews.html page
duplicateprotection is simply generated each time - a new one.

As a result of running this script from the site.ru/script.php address, I get a message:
Unfortunately, you do not have the rights to publish articles on our site, while the page shows that you are not authorized. Going to the site.ru/addnews.html page is still authorized.

Please tell me what is the problem?
How can I still add news from the post script with a request without adding it using sql?

Thanks a lot!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question