Using an HTML form action using a PHP script in another directory (relative paths)

Here my tree looks like

/application /lib /util /login /views /base_view 

My login page

 localhost:737/astuto-lena/branches/application/views/base_view/index.php 

And I want my form to be like this

 localhost:737/astuto-lena/branches/application/util/login/main.php 

Here is my form ad

 <form class="form_login" action="./util/login/main.php" method="POST"> ... </form> 

But when I click the submit button, it takes me away

 localhost:737/astuto-lena/branches/application/views/base_view/util/login/main.php 

This is the wrong way and generates a 404 error.

So what happened to the way I use relative paths in a form declaration and how can I fix this?

+6
source share
4 answers

In your relative ./util/login/main.php path ./util/login/main.php you use ./ , which refers to the current folder, therefore assumes that the folder structure /util/login is inside /base_view . You should try using ../ , which refers to the parent folder:

 <form class="form_login" action="../../util/login/main.php" method="POST"> ... </form> 
+7
source

You need to set the action to the best relative path or use the absolute path. Examples:

 ../../util/login/main.php 

or

 /astuto-lena/branches/application/util/login/main.php 

./ just means this directory (aka current working directory )

+1
source

You must use .. / to go to the parent directory

 <form class="form_login" action="../../util/login/main.php" method="POST"> ... </form> 
+1
source

I ran into a similar problem and the error I received was not found /application /includes connect.php insert.php index.php

 <form action="/includes/insert.php" method="post"> //code </form> 

the above code did not work and showed error 404, the object was not found. But,

 <form action="./includes/insert.php" method="post"> //code </form> 

The only difference is the addition . into the path of action. The strange things /include/filename work fine for require or include , but you need to add . for the action attribute

0
source

Source: https://habr.com/ru/post/946704/


All Articles