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 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)