Php 使用cUrl下载音频文件,其中获取文件需要身份验证

Php 使用cUrl下载音频文件,其中获取文件需要身份验证,php,curl,Php,Curl,我想从服务器下载一个音频文件 当我在服务器上直接访问请求用户名和密码的url时,我希望通过cURL覆盖它 基本上我想让我的网络用户在我的网站上听歌曲。我有一个认证的其他网站这样做。目前,我的网站的用户必须进行双重检查,首先使用凭据登录我的网站,然后单击“播放”按钮,然后再次输入我提供给他们的用户名和密码(来自同一个网站,我有身份验证) 如果忘记设置标头,请使用以下代码进行身份验证 这个问题有点不清楚。您能具体描述一下为什么/如何需要“覆盖身份验证”吗?是的,现在我可以登录管理站点了。最后如何克服

我想从服务器下载一个音频文件

当我在服务器上直接访问请求用户名和密码的url时,我希望通过cURL覆盖它

基本上我想让我的网络用户在我的网站上听歌曲。我有一个认证的其他网站这样做。目前,我的网站的用户必须进行双重检查,首先使用凭据登录我的网站,然后单击“播放”按钮,然后再次输入我提供给他们的用户名和密码(来自同一个网站,我有身份验证)

如果忘记设置标头,请使用以下代码进行身份验证


这个问题有点不清楚。您能具体描述一下为什么/如何需要“覆盖身份验证”吗?是的,现在我可以登录管理站点了。最后如何克服url重定向?
$url="https://example.com/abc.wav";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, "userstring:passString");
curl_exec($ch);
curl_close($ch);

Direct URL after entering the username & password allowed me to listen the audio.
now how can I authenticate my web to access that URL by overriding authentication?
I want to download it and as well as play in the background after clicking on button "download" & "Play" respectively.
On the other hand is there any way that I can email that file without downloading or by downloading it
header("Content-Type: audio/mpeg");
$url = "clip.mp3"
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, "password");
curl_exec($ch);
header('Location: ' . $url);