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

拒绝访问使用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 请问一下这个运行结果是怎么来的
  • ¥15 这个复选框什么作用?
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下