skip to Main Content

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

Answers


  1. if isn’t working with php use this

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

    or use this

    <a href="login.html">Login</a>
    
    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search