【问题标题】:Php and bash together to generate keysphp 和 bash 一起生成密钥
【发布时间】:2018-06-28 21:18:03
【问题描述】:

我有这个生成密钥和过期时间的 bash 文件:

#!/bin/bash
get_customer_url() {
  local IP=${1:-127.0.0.1}
  local SECRET=${2:-VERY_COOL_SECRET}
  local EXPIRES="$(date -d "today + 30 minutes" +%s)";
  local token="$(echo -n "${EXPIRES} VERY_COOL_SECRET" | openssl md5 -binary | openssl base64 | tr +/ -_ | tr -d =)"
  echo "/${token}/${EXPIRES}/"
}
get_customer_url

我像这样通过 php 调用它

<?php $output = shell_exec('sh generate-keys-hls.sh'); echo "$output";?>

它工作正常,它会生成类似这样的东西

/G8INKLc3VfDMYtQT2NTU-w/1530222035/ 

我的问题是我想把另一个 php 结果放在这样的行中

<?php $output = shell_exec('sh generate-keys-hls.sh'); echo "$output";?><?php echo get_post_meta($post->ID, 'file', true)?>

目前它在两行中打印结果我需要它只是一行而不是这个

/G8INKLc3VfDMYtQT2NTU-w/1530222035/ 
file.mp4.m3u8

我希望它是这样的

/G8INKLc3VfDMYtQT2NTU-w/1530222035/file.mp4.m3u8

没有空格或多行!

【问题讨论】:

  • 当您可以单独使用 PHP 完成所有这些操作时,为什么还要这样做呢?另请参阅generate random key in PHP。
  • @LioraHaydont 为什么会有帮助? echo 本身不会添加换行符。
  • @Barmar 啊,我忘了,对不起
  • 我不知道如何将 bash 脚本转换为 php ,如果有人可以将它转换给我,我将不胜感激!

标签: php bash nginx http-live-streaming


【解决方案1】:

删除shell_exec()结果周围的空格。

echo trim($output);

【讨论】:

    猜你喜欢
    • 2010-11-29
    • 1970-01-01
    • 2016-02-24
    • 2010-09-08
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多