duanjiwu0324 2018-08-10 02:58
浏览 73
已采纳

拒绝访问使用php链接到另一个html页面时

I'm fairly new to php/html so bear with me.

So in the home page of my website, the login link takes the user to either

  1. The login page
  2. The user page if they had already logged in

Before implementing this fully, I decided to check whether or not I could get a simple php link to work and im glad i did because it does not work.

I have currently:

<a href="<?php echo 'login.html';?>">Login</a>

This is supposed to go to login.html when clicked on but when you click on the link you get this Corresponding error log from XAMPP's appache error.log:

[Thu Aug 09 21:51:30.257273 2018] [core:error] [pid 37376:tid 1948] (20024)The given path is misformatted or contained invalid characters: [client ::1:49721] AH00127: Cannot map GET /poll/%3C?php%20echo%20%27login.html%27;?%3E HTTP/1.1 to file, referer: http://localhost/poll/Poll_home.html

If instead of the above code I put

<a href="login.html">Login</a>

then it works fine and links me to the login page. Any help would be great!

edit:

Problem is fixed by creating a new php file (test.php).

<a href="test.php">Login</a>

But when I try to make the link dynamic by changing the test.php to this:

<?php
if(session_status() == PHP_SESSION_NONE){ //if already logged on
    header("Location: login.html");
}
else{ //If not
    header("Location: sign-up.html");
}
exit;
?>

It always goes to login.html even when I am not logged on.

  • 写回答

2条回答 默认 最新

  • dqmhgz5848 2018-08-10 03:21
    关注

    As per error message

    Cannot map GET /poll/%3C?php%20echo%20%27login.html%27;?%3E HTTP/1.1 to file, referer: http://localhost/poll/Poll_home.html

    It says that you are writting PHP code in Poll_home.html file, which is the problem, you should write PHP code in php file (i.e. Poll_home.php). When server see url file is html it will not execute it but send it content to user browser. so rename your file and check. It should work.

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

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作