Home > Backend Development > PHP Tutorial > PHP 页面重定向的问题

PHP 页面重定向的问题

WBOY
Release: 2016-06-23 14:11:51
Original
1150 people have browsed it

PHP 提问

$url=$_SERVER['SERVER_NAME']."/login.html";
echo "<script> location.href=$url </script>";


为什么location.href  被赋值为localhost/index.htmllocalhost/login.html
我的意思 是想用变量的方式 把它赋值为localhost/login.html,各位大神们,我该怎么实现!

回复讨论(解决方案)

$url=$_SERVER['SERVER_NAME']."/login.html";
echo "<script> location.href= '$url' </script>";

echo "<script> location.href='$url' </script>"; 
加单引号 也是同样的结果  跳转到 localhost/index.htmllocalhost/login.html页面

那就不是这两句的原因了
你看看其他的代码

我的代码只有这几句啊。。
文件名为test.php 在www文件夹下
$url=$_SERVER['SERVER_NAME']."/login.html";
echo "<script> location.href='$url' </script>"; 
?>

那就不知道原因了,我几个浏览器测试都是正确的

你最好把协议也写出来

$url='http://'.$_SERVER['SERVER_NAME']."/login.html";echo "<script language=\"JavaScript\"> location.href='$url' </script>";
Copy after login

$url=$_SERVER['SERVER_NAME']."/login.html";这行中,你将其改为$url=“login.html";看看行不行?

localhost/index.htmllocalhost/login.html
这个是在localhost/index.html的基础上跳的,那根据你的显示明显是得到的SERVER_NAME是:
localhost/login.html注意前面没有“/”,那浏览器就会把你的地址加在当前地址的后面,所以你需要在前面那个一个“/”表示从根目录开始。。。。。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template