douruhu4282 2016-11-28 20:58
浏览 17

简单的PHP代码无法在移动设备上运行

THis may be super basic, but I have not been able to resolve this after spending hours!

I am running PHP 7 on Ubuntu 16.1.

The PHP file is EXACTLY as follows

  <?php

header("Content-type: application/javascript");
header("HTTP/1.1 200 OK");

ExpandShortLink();


function ExpandShortLink()
{

    // get URL
    $URL_To_Expand = $_REQUEST['url'];
    // for short links, get the full links

    // get full URL
    $arr_URL_Header = get_headers($URL_To_Expand, 1);
    $strLink        = $arr_URL_Header['Location'];

//echo $URL_To_Expand;
    //print_r($arr_URL_Header);

    if ($strLink) {
        if (is_array($strLink)) {
            $Full_URL = array_pop($strLink);
        } else {
            $Full_URL = $strLink;
        }
    } else {
        $Full_URL = $URL_To_Expand;
    }

    echo $Full_URL;
}

--> produces the url I enter as a "url" parameter on desktop. But nothing on mobile!

On some reading, I found that in sometimes PHP interprets everything after "//" as a comment and that may be happening here. But then why does it happen on mobile only? Also, andy suggestions on resolving this will be great!

Thanks much for your help,

You can see this live here

If you click this on desktop, you will see http:// example. com. However, on mobile it will return http:

  • 写回答

1条回答 默认 最新

  • douzhong4222 2016-12-04 19:27
    关注

    Not sure if this qualifies as answer, but I wanted to put a note here for anyone else who may be facing a similar problem.

    I was using the PHP pasted above for an ajax call. I tried using text/plain instead of application/json and now it works across all browsers and all devices (as far as I could test).

    Not sure why application/javascript was causing problems on mobile chrome, but I think text/plain makes sense as I was just passing back a text string instead of a javascript.

    As I said it probably is not the fully qualified answer, but hopefully it helps someone in future!

    评论

报告相同问题?

悬赏问题

  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景