LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-03-2021, 11:29 AM   #1
2aprepper
LQ Newbie
 
Registered: Jan 2021
Posts: 5

Rep: Reputation: Disabled
Pointing an HTML form "Action" to a php script file which is inaccessible via a URL


Can this be done? I want to point the "action" of an HTML form to a php script which does not have a URL. This script resides in a directory above the web root. I can access it via an "include" directive using various means but cannot access the script via the "action" method of a form. Is this even possible, or MUST the script be web-accessible in this case?

My reason is pure curiosity. It's not a homework assignment (I'm 64) nor is it for my work (I'm retired). I was once a programmer for an engineering firm but that was long ago and I have CRS syndrome now. :-)

Thanks in advance.
 
Old 05-03-2021, 11:51 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,170
Blog Entries: 1

Rep: Reputation: 1536Reputation: 1536Reputation: 1536Reputation: 1536Reputation: 1536Reputation: 1536Reputation: 1536Reputation: 1536Reputation: 1536Reputation: 1536Reputation: 1536
The script must be accessible by the webserver (httpd.exe), but it content can be a single include statement, referring to another php-script, which doesn't have to accessible by the webserver.
 
1 members found this post helpful.
Old 05-03-2021, 12:00 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 21,492

Rep: Reputation: 4106Reputation: 4106Reputation: 4106Reputation: 4106Reputation: 4106Reputation: 4106Reputation: 4106Reputation: 4106Reputation: 4106Reputation: 4106Reputation: 4106
Assuming Apache is the web server as far as I know you would need to enable cgi-bin and configure the server via script-alias to use that directory to run CGI programs. Which means it needs to be web accessible.
 
Old 05-03-2021, 12:09 PM   #4
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 1,339

Rep: Reputation: 1133Reputation: 1133Reputation: 1133Reputation: 1133Reputation: 1133Reputation: 1133Reputation: 1133Reputation: 1133Reputation: 1133

The action attribute of a form contains a URL which receives a POST request when the form is submitted.

Whatever you put into the attribute is interpreted as a URL (based on the page's base location).

Neither HTML nor HTTP cares about PHP scripts - it is web servers which can (automatically and/or manually) map an incoming request's URL to a script, execute that script, then return the result as a HTTP response.

Your scripts do not need to be web accessible, but to use an external script you obviously need to configure the web server appropriately. (It would be a large security hole if a server accepted requests for arbitrary files outside of the webroot!)

 
Old 05-03-2021, 12:55 PM   #5
2aprepper
LQ Newbie
 
Registered: Jan 2021
Posts: 5

Original Poster
Rep: Reputation: Disabled
Answers Accepted. Thanks!

Quote:
Originally Posted by michaelk View Post
Assuming Apache is the web server as far as I know you would need to enable cgi-bin and configure the server via script-alias to use that directory to run CGI programs. Which means it needs to be web accessible.
Yes of course the Apache2 service is configured to run scripts outside the webroot using the Alias mod. I run all my scripts that way. I was just curious if it could be done from a forms "action".

I was looking at the very technique NevemTeve mentioned. Good solution.

:-)
 
Old 05-03-2021, 01:18 PM   #6
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 1,339

Rep: Reputation: 1133Reputation: 1133Reputation: 1133Reputation: 1133Reputation: 1133Reputation: 1133Reputation: 1133Reputation: 1133Reputation: 1133
Quote:
Originally Posted by 2aprepper View Post
I was looking at the very technique NevemTeve mentioned. Good solution.
Whether that technique is a good solution depends on the situation.

If the included script is directly defined by a user-supplied variable then it becomes a security hole.

 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
php form action : second action ?? esteeven Programming 7 05-08-2015 08:06 AM
HTML form action not passing content to PHP file Dafydd Programming 3 12-22-2013 01:41 AM
[SOLVED] Problems using php variable in form "action" attribute lrtward Programming 6 04-27-2012 05:26 PM
form action ="?" ... where is my form posting to? verbatim Programming 2 05-23-2005 06:55 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration