0

I am trying to send cURL request to a remote API server with this code:

$ch = curl_init(); $options = array(CURLOPT_URL => 'http://minecms.info/update/index.php', CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => 1, CURLOPT_POSTFIELDS => $data, CURLOPT_HTTPHEADER => array('Content-type: application/json'), CURLOPT_SSL_VERIFYPEER => false ); curl_setopt_array($ch, $options); $response = curl_exec($ch); 

But I don't want users accessing the updates page on their browsers so I set a content type header on the request. The problem is that I don't know how to detect this content type on the remote server. Basically what I want is to check whether the client request has a content type: application/json set if yes it executes the rest of the code if not it just does exit;.

Thank you to anyone who would help in advance.

5
  • This could help you: stackoverflow.com/questions/5519802/… Commented Mar 28, 2014 at 10:19
  • @ilpaijin No i already read that question before, didn't really help, i did a google search for like 3 hours... Commented Mar 28, 2014 at 10:23
  • There is no reliable cross-environment way to check headers received in php. If it's apache, try apache_request_headers(); Commented Mar 28, 2014 at 10:29
  • @Anthony I am trying to make this an open source CMS so everyone runs it on different server and i would want it to be competible with all servers Commented Mar 28, 2014 at 10:32
  • You want the cms platform to be open-source or just have the cms server you are running be an open cms? If you want to write a new cms, then setting the content-type header is a really weak approach that anyone could bypass. Commented Mar 28, 2014 at 10:44

1 Answer 1

0

You can try using getallheaders() and check whether the Content-Type is in place.

Give a look at the man http://www.php.net/manual/it/function.getallheaders.php for insights

---- EDIT INSIGHTS ----

And what about this one? (Which I'm currently using)

public function getAllHeaders() { if(function_exists('getallheaders')) { return getallheaders(); } $headers = array(); foreach ($this->parameters as $key => $value) { if (substr($key, 0, 5) == 'HTTP_') { $headers[str_replace(" ", "-", ucwords(strtolower(str_replace("_", " ", substr($key, 5)))))] = $value; } if ($key == "CONTENT_TYPE") { $headers["Content-Type"] = $value; } } return $headers; } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.