0

I have some document and sample code with jquery Basic Authentication login sample code. I need the php code for my project

$.ajax({
  url: 'http://loginurl',
  headers: {accept:'text/xml'}, //veya "text/json"
  contentType: 'application/json',
  method: 'GET',
  beforeSend: function (xhr) {
    xhr.setRequestHeader("Authorization", "Basic " + btoa('test' + ':' + 'test'));
  },
  success: function (data) {
    //success
  },
  error: {
    //error
  }
});

I tried to convert php like this but I can't login at

$username = "username";
$password = "pass";
$remote_url = 'http://loginurl';

// Create a stream
$opts = array(
  'http'=>array(
    'method'=>"GET",
    'header' => "Authorization: Basic " . base64_encode("$username:$password")                 
  )
);
$context = stream_context_create($opts);
// Open the file using the HTTP headers set above
$file = file_get_contents($remote_url, false, $context);

What's wrong? Thanks for any help

Shiladitya
  • 12,003
  • 15
  • 25
  • 38
safa
  • 3
  • 5
  • Possible duplicate of [What is the difference between client-side and server-side programming?](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – svgrafov Nov 02 '18 at 00:50
  • What's wrong? We have no idea because you haven't told us what the problem is. – miken32 Nov 02 '18 at 02:27
  • @miken32 my php code gives connection timeout so not logined i don't understand actualy jquery works file but i need correct php code. thanks for your interest – safa Nov 02 '18 at 02:30

0 Answers0