B
B
Bobur Bakhritdinov2016-01-05 20:02:36
linux
Bobur Bakhritdinov, 2016-01-05 20:02:36

Is it possible to implement the task with curl?

Hello everyone, please help me solve this problem.
There is a php code:

$curl = curl_init('http://sitename');
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "Username:Password");
curl_exec($curl);
curl_close($curl);

and on sitename parameters are specified on .htaccess
Order deny,allow
Deny from all
AuthType Basic
AuthUserFile /www/.htpasswd
AuthName "Protected Area"
require valid-user
Allow from 127.0.0.1

How it is possible to check on a correctness of authorization for conditions?
Conditions:
If (authorization was successful){
<video>
 <source src="http://sitename/filename.mp4">
</video>

} otherwise no

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mark Doe, 2016-01-05
@bakhritdinov_b

Firstly, if the authorization was unsuccessful, 401 Unathorized will be returned, you can do something like this

$curl = curl_init('http://sitename');
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "Username:Password");
curl_exec($curl);
$httpCode = curl_getinfo($curl,CURLINFO_HTTP_CODE);
if($httpCode == 401){
  //failed
}else{
 //maybe success?
}
curl_close($curl);

Or, for example, check for the presence of your pattern in the response in this way
$curl = curl_init('http://sitename');
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "Username:Password");
curl_setopt($curl,CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
if(!strpos("<video",$response)){
 //fail
}else{
 //success
}
curl_close($curl);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question