0

i am trying to send custom header to the same file (using curl in php)

this is the file (test.php) :

   @session_start();

   @session_unset(($_SESSION['token']));

   if(empty($_SESSION['token'])){

      $_SESSION['token'] = bin2hex(openssl_random_pseudo_bytes(16));
   }

   $token = $_SESSION['token'];

   $uri = 'http://localhost/test.php'; // the samw file
   $ch = curl_init($uri);
   curl_setopt_array($ch, array(
   CURLOPT_HTTPHEADER  => array('X-Simple-Protection: '.$token.''),
   CURLOPT_RETURNTRANSFER  =>true,
   CURLOPT_VERBOSE  => 1));
   $out = curl_exec($ch);
   curl_close($ch);


   if($_SERVER['HTTP_X_SIMPLE_PROTECTION'] == $token){ 

       echo "token : ".token;
   }else{
       echo "error";  
   }

When I run the file I get the following error :

Notice: Undefined index: HTTP_X_SIMPLE_PROTECTION in C:\Users\me\Desktop\xampp\htdocs\test.php on line 24 error

I try to send to the file itself , Is this possible?

Nigel Ren
  • 56,122
  • 11
  • 43
  • 55
brown34
  • 23
  • 2

0 Answers0