dream0614 2013-06-21 10:51
浏览 63
已采纳

通过php中的变量重定向

I have my link in a variable:
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

I am passing the $actual_link through sessions to another page and want there to redirect it to main page i.e $actual_link for a particular condition.

The location("header:yoururl.com") doesn't work as it requires a definite url. So anything that can serve my cause?

  • 写回答

3条回答 默认 最新

  • dongqiao0953 2013-06-21 11:10
    关注

    You need to wrap array element in {} if you put it into a string

    $actual_link = "http://${_SERVER['HTTP_HOST']}${_SERVER['REQUEST_URI']}";
    

    and a key need to be a string in single quote.

    or you can put array element outside of string

    $actual_link = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    

    olso if you want it to work with SSL use this check

    $_SERVER['HTTPS'] == "on"
    

    and put s after http

    $protocole = "http" . ($_SERVER['HTTPS'] == "on" ? 's' : '');
    $actual_link =  $protocole . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    

    then you can redirect the url using header

    header('Location: ' . $actual_link);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序