dongyi1490 2016-06-25 13:06
浏览 163
已采纳

通过php ECHO <script>。 我想知道正确的方法[关闭]

I have a url path that will send through this myGlobalFunction(); from a different file.

So the following script tag will catch the user on the website root and forward him to the login page. I can't seem to make this working. I know i am missing the single and double quotes. :(

if (!isset($_SESSION['role']))
{
  echo '<script>window.location.assign("'.myGlobalFunction().'/onboardingform/core/admin/login.php")</script>';
  exit();

  } else if (isset($_SESSION['role'])) {


        if($_SESSION['role'] =='CLIENT') {

              echo "<script>window.location.assign('/onboardingform/core/client/index.php')</script>";
              exit();

        } else if($_SESSION['role'] =='RESELLER') {

              echo "<script>window.location.assign('/onboardingform/core/reseller/index.php')</script>";
              exit();

        } else if($_SESSION['role'] =='CSR') {

              echo "<script>window.location.assign('/onboardingform/core/csr/index.php')</script>";
              exit();

        } else if($_SESSION['role'] == 'ADMIN') {


?>
  • 写回答

2条回答 默认 最新

  • douyi1899 2016-06-25 13:12
    关注

    You're not concatenating the strings properly. Use . operator to concatenate the string like this.

    <?php
    
    echo '<script>window.location.assign("'. myGlobalFunction().'/onboardingform/core/admin/login.php")</script>';
    

    And there is no need of echo statement inside another echo.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度