S
S
Scuba2018-05-18 15:48:55
PHP
Scuba, 2018-05-18 15:48:55

Is it possible to set a session via POST?

There is a script:

session_start();

if (!isset($_SESSION['counter'])) {
  $_SESSION['counter'] = 0;
}

if ($_SESSION['counter'] > '30') { ####
  print 'limit';
  exit;
}

print ++$_SESSION['counter'];

This script is called by another using CURL:
$url = 'site.com';
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    $response = curl_exec($ch);
    curl_close($ch);
    print_r($response);

But it always returns 1.
Is it possible to set the handler script call counter using sessions?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Valery, 2018-05-18
@it_monk

You need to configure curl to work with cookies:

curl_setopt ($ch, CURLOPT_COOKIESESSION, TRUE);
curl_setopt ($ch, CURLOPT_COOKIEFILE, "/tmp/my_php_script_cookie_1.txt");

A
Arman, 2018-05-18
@Arik

the session identifier is written in cookies (you can of course set it up on GET), so this script does not store cookies and therefore there is always a new user for the first code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question