简体   繁体   English

如何获取HTML表单以将其发布到非公共目录中

[英]How to get HTML form to post to itself in a non-public directory

I have my PHP files located in a folder that is one directory above the public directory. 我的PHP文件位于一个文件夹中,该文件夹是公用目录上方的一个目录。 I have tried using the following, but have had no luck: 我尝试使用以下方法,但没有运气:

<form action="../Search/search.php" method="get">

<form action="" method="get">

<form action="search.php" method="get">

Can I get an html form to post to itself, in a non-public directory, or do I need to go about this another way? 我可以在非公共目录中获取HTML表单以将其发布到自身吗,还是需要以其他方式进行处理?

Your PHP has to do the logic and use the $_GET[] variable. 您的PHP必须执行逻辑并使用$ _GET []变量。

The PHP file must be reached and called by the user session. 用户会话必须访问并调用PHP文件。 Atleast 1 php file, say index.php or router.php must be inside a public directory in order to call 'search.php'. 至少要有1个php文件,例如index.php或router.php,必须位于公共目录中才能调用“ search.php”。

You can for example route everything to routing.php and that way get to search.php, and/or by using a .htaccess file. 例如,您可以将所有内容路由到routing.php,然后以这种方式到达search.php,和/或使用.htaccess文件。 The latter is not the easiest thing to do if you dont know how it works yet. 如果您尚不了解后者的工作原理,那么这并不是最容易的事情。

My suggestion. 我的建议。 Just put the PHP-file in a public folder. 只需将PHP文件放在公共文件夹中即可。 It is safe*, for it will be executed server side. 这是安全的*,因为它将在服务器端执行。

*unless you are using insecure code *除非您使用的代码不安全

the first thing is you understood that how the problem is happen, so save both html and php file in the same directory and call the php file like this 第一件事是您了解问题是如何发生的,因此将html和php文件保存在同一目录中,然后像这样调用php文件

<html>
<head>
</head>
<body>
<form action ="<?php print $_SERVER['PHP_SELF']?>"> method="Post">
.
.
.
</form>
</body>
</html>

and save this page the same directory with php fle and run. 并使用php fle将页面保存在同一目录中并运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM