-1

I have a login form with an action heading to the con_login.php file. When the con_login.php is under the same folder as the current page everything works fine. But i want the file to be under another folder, so when instead of action="con_login.php" i move the file and i type action="../functions/con_login.php" it doesn't work. When i press submit the browser looks for the con_login.php under the same folder as the login_page.php. How can i fix that?

<?php
  $title="WebVillas - Welcome";
  require('../parts/header_welcome.php');
?>

<main id="main">
       <h2>Home Page</h2>

       <?php echo_msg(); ?>

       <?php if(!isset($_SESSION['username'])) { ?>

       <p>Please login:</p>
       <form name="form1" method="post" action="../functions/con_login.php">
         <p>username: <input type="text" name="username"/> </p>
         <p>password: <input type="password" name="password"/> </p>
         <p><input name="submit" type="submit"></p>
       </form>

       <?php } else echo '<p> Hello ' .$_SESSION['username'].'</p>';?>

    </main>


</div>
<?php require('../parts/footer_welcome.php'); ?>
smksmk
  • 17
  • 4
  • (There are probably better [duplicates..](https://duckduckgo.com/?q=site%3Astackoverflow.com+php+form+action+not+found+file+relative+url).) – mario Apr 22 '20 at 09:50

1 Answers1

1

The "action" is an absolute URL, i.e the URL you might type into your browser (because it's your browser that will open it, not the server), not a virtual URL as you might use in your include statements. So it needs to be expressed relative to the virtual root of your web site.

droopsnoot
  • 931
  • 1
  • 7
  • 11
  • "virtual URL" is perhaps better explained as "filesystem-relative". In contrast to the absolute request path, which is documentroot-based. – mario Apr 22 '20 at 09:48
  • In my head I thought of them the other way around - the virtual URL is surely the one presented by the web server, whereas the absolute one is the filesystem-related? "/" to the browser is virtual because it actually maps to something like /webserver/site/webroot (or something like that), not the actual root. – droopsnoot Apr 22 '20 at 10:29