每隔几秒从HTTP源到HTTPS网站获取和更新文本 [英] Get and update text every few seconds from an HTTP source to an HTTPS website

查看:117
本文介绍了每隔几秒从HTTP源到HTTPS网站获取和更新文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我有一个广播电台,我的主机提供商没有SSL证书,我有一个带有SSL证书的网站,我想要显示当前的曲目名称(再次提到,只有曲目名称,而不是艺术家)正在电台播放。曲目名称可在此处找到: http://91.121.139.194:8157/currentsong?sid=1



以上链接的输出显示:X - X - Y



X - 艺术家,
Y - 曲目名称。
我不希望显示第一个X,因此它不会显示艺术家两次(一个来自艺术家元数据,一个来自曲目名称元数据)



<问题是我无法从HTTP到HTTPS获取文本。
我试过Ajax和Javascript。他们中的每一个都被阻止了。



我知道从不安全的HTTP显示数据会对我拥有的HTTPS造成风险,这就是为什么我会隐藏轨道名称直到用户点击播放。播放音频也会带来风险,因为它是从HTTP发送的....



我的主机提供商也提供API,但它附带的javascript,也请求数据来自HTTP,被阻止......



这有什么解决方法吗?我认为使用我使用的Ajax和Javascript是没有意义的,因为这两种方法都不起作用。我也听说过使用curl或file_get_contents,但我真的不想花更多的时间,就像我尝试的前两种方法一样,发现它不起作用。我需要一个建议来做什么。



另外,如果有更好的方法从ShoutCast服务器获取曲目名称,我也可以。



在旁注中,我真的不知道为什么我的主机提供商不使用OpenSSL ...它是免费的。



编辑:我想的另一个想法是从实际的.mp3流媒体源获取曲目标题元数据。但是这个来源是来自不安全的HTTP,我不确定它是否会起作用。

解决方案

如果你的网站托管服务提供商有你用于Shoutcast站的端口,然后做我将在下面解释的。如果没有,请检查下面的其他答案。


方法1


index.php 附近创建一个名为 trackid.php 的文件,并输入以下代码: / p>

 <?php 
$ server =http://91.121.139.194:8157/stats?sid=1 ;
$ srv_url = urlencode($ server);
$ sc_stats = simplexml_load_file($ srv_url);
echo $ sc_stats-> SONGTITLE
?>

通过 echo将数据(歌曲名称)从不安全的HTTML解析为安全的HTML 它可以直接从安全连接进行访问。
不要忘记更换IP和端口。



On index.php 添加:

 < script src =jquery.min.jstype =text / javascript>< / script> 
< script type =text / javascript>
函数trackid(){
$ .get('trackid.php',函数(数据){
$(。TrackTitle)。text(data);
} );
}
trackid()
setInterval(trackid,5000);
< / script>
< div class =TrackTitle>正在加载...< / div>

这种方法的缺点是它会在你的服务器上为每个用户创建一个后台进程,因为javascript请求为每个用户输出一个PHP文件。


方法2


您还可以设置 trackid.php ,每隔6秒将输出(曲目名称)保存在FTP上的文本文件中:

 <?php 
$ server =http://91.121.139.194:8157/stats?sid=1;
$ LoopMaximum = 10;
$ LoopInitial = 0;
循环:{
if($ GLOBALS [LoopInitial]< $ GLOBALS [LoopMaximum]){
$ srv_url = urlencode($ GLOBALS [server]);
$ sc_stats = simplexml_load_file($ srv_url);
$ node = $ sc_stats-> SONGTITLE;
$ location = fopen(playing.txt,w +);
fwrite($ location,$ node);
fclose($ location);
$ GLOBALS [LoopInitial] ++;
睡觉(6);
goto LoopF​​ollow;} else if($ GLOBALS [LoopInitial] == $ GLOBALS [LoopMaximum]){
exit();}
}
LoopF​​ollow:{
if($ GLOBALS [LoopInitial]< $ GLOBALS [LoopMaximum]){
$ srv_url = urlencode($ GLOBALS [server]);
$ sc_stats = simplexml_load_file($ srv_url);
$ node = $ sc_stats-> SONGTITLE;
$ location = fopen(playing.txt,w +);
fwrite($ location,$ node);
fclose($ location);
$ GLOBALS [LoopInitial] ++;
睡觉(6);
goto Loop;} else if($ GLOBALS [LoopInitial] == $ GLOBALS [LoopMaximum]){
exit();}
}
?>

每分钟添加一个CronJob:

  php /home/user/public_html/trackid.php> / dev / null 2>& 1 

注意:每个webhost的PHP路径可能不同。



现在每5秒从文本文件中读取一次:

 < script type =text / javascript> 
函数trackid(){
var client = new XMLHttpRequest();
client.open('GET','/ playing.txt');
client.onreadystatechange = function(){
var trackName = client.responseText;
$(。TrackTitle)。text(trackName);
}
client.send();
}
trackid()
< / script>
setInterval(trackid,5000);
< div class =TrackTitle>正在加载...< / div>

此方法没有任何缺点,但您需要访问CronJobs并至少具有最低限度允许5个后台进程。
曲目名称将作为DIV元素的文本。您可以使用CSS格式化它。


So, I have a radio station, my host provider does not have a SSL certificate and I have an website with a SSL certificate on where I want to display the current track name (mentioning again, only the track name, and not the artist) being played on the radio station. The track name can be found here: http://91.121.139.194:8157/currentsong?sid=1

The output of the above link displays: X - X - Y

X - Artist, Y - Track name. I don't want the first X to be displayed so it won't display the artist two times (one from artist metadata and one from track name metadata)

The problem is that I can't get text from HTTP to HTTPS. I tried Ajax and Javascript. Every one of them were blocked.

I know that displaying data from unsecured HTTP will pose a risk to the HTTPS I have, that's why I will hide the track name until the user clicks Play. Playing the audio also poses a risk since it is sent from HTTP....

My host provider also offers an API but the javascript that comes with it, also requests data from HTTP, being blocked...

Is there any workaround for this? I think it is pointless to put the Ajax and Javascript I used because both methods don't work. I also heard of using curl or file_get_contents but I really don't want to spend more hours as I did with the first 2 methods I tried just to find that it doesn't work. I need an advice to what to do.

Also, if there are better ways of getting the track name from a ShoutCast server, I am ok with that.

On a side note, I don't really know why my host provider does not use OpenSSL... it is free.

Edit: Another idea I am thinking is to get the track title metadata from the actual .mp3 streaming source. But that source it is from an unsecured HTTP, which again, I am not sure if it would work.

解决方案

If your web hosting provider has the port you use for your Shoutcast station opened, then do what I will explain below. If not, check the other answer below.

Method 1

Create a file named trackid.php near index.php and put the following code:

<?php
$server = "http://91.121.139.194:8157/stats?sid=1";
$srv_url = urlencode($server);
$sc_stats = simplexml_load_file($srv_url);
echo $sc_stats->SONGTITLE
?>

This parses data (song name) from unsecured HTTML to secured HTML by echoit to direct access from a secured connection. Don't forget to replace the IP and Port.

On index.php add this:

<script src="jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
function trackid() {
$.get('trackid.php', function(data) {
$(".TrackTitle").text(data);
}); 
}
trackid()
setInterval(trackid, 5000);
</script>
<div class="TrackTitle">Loading...</div>

Downside for this method is that it will create a background process on your server for every user because javascript requests output of a PHP file for every user.

Method 2

You can also set trackid.php to save the output (track name) inside a text file on FTP every 6 seconds:

<?php
$server = "http://91.121.139.194:8157/stats?sid=1";
$LoopMaximum = 10;
$LoopInitial = 0;
Loop: {
    if ($GLOBALS["LoopInitial"] < $GLOBALS["LoopMaximum"]) {
        $srv_url = urlencode($GLOBALS["server"]);
        $sc_stats = simplexml_load_file($srv_url);
        $node = $sc_stats->SONGTITLE;
        $location = fopen("playing.txt","w+");
        fwrite ($location, $node);
        fclose($location);
        $GLOBALS["LoopInitial"]++;
        sleep(6);
        goto LoopFollow;} else if ($GLOBALS["LoopInitial"] == $GLOBALS["LoopMaximum"]){
        exit();}
}
LoopFollow: {
    if ($GLOBALS["LoopInitial"] < $GLOBALS["LoopMaximum"]) {
        $srv_url = urlencode($GLOBALS["server"]);
        $sc_stats = simplexml_load_file($srv_url);
        $node = $sc_stats->SONGTITLE;
        $location = fopen("playing.txt","w+");
        fwrite ($location, $node);
        fclose($location);
        $GLOBALS["LoopInitial"]++;
        sleep(6);
        goto Loop;} else if ($GLOBALS["LoopInitial"] == $GLOBALS["LoopMaximum"]){
        exit();}
}
?>

Add a CronJob for every minute:

php /home/user/public_html/trackid.php >/dev/null 2>&1

Note: The path to PHP may differ for each webhost.

Now read the track from the text file every 5 seconds:

<script type="text/javascript">
function trackid() {
var client = new XMLHttpRequest();
client.open('GET', '/playing.txt');
client.onreadystatechange = function() {
var trackName = client.responseText;
$(".TrackTitle").text(trackName);
}
client.send();
}
trackid()
</script>
setInterval(trackid, 5000);
<div class="TrackTitle">Loading...</div>

There is no downside for this method but you need to have access to CronJobs and have at least a minimum of 5 background processes allowed. The track name will be as text on the DIV element. You can format it then with CSS.

这篇关于每隔几秒从HTTP源到HTTPS网站获取和更新文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆