Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6735565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:01:38+00:00 2026-05-26T11:01:38+00:00

I’m wondering something, but I can’t seem to be finding a good, clear answer,

  • 0

I’m wondering something, but I can’t seem to be finding a good, clear answer, or even a solution to this problem:

My PHP website has the following structure:

root
   functions
   generators
   helpers
   scripts
   style
   index.php

These are all folders and one php file. Functions contains a bunch op php files related to database connection and various other database operations such as inserting, deleting, updating,… Generators contains classes to automatically generate web pages to make them look all the same. Helpers are classes that handle login, logout, register, etc. Scripts are javascript and Style is CSS.

In my generators folder, there is a file mainGenerator.php, this generates various pieces of the website:

 private function generateLogin()
    {
        if (!isLoggedIn()) {
            echo "
                <h2>Login</h2>
                <form method='post' action='../helpers/login.php' id='loginForm'>
                <p>
                Username:<br/>
                <input class='search' type='text' name='username'/>
                Password:<br/>
                <input class='search' type='password' name='password'/>
                <input name='login' type='image' style='border: 0; margin: 0 0 -9px 5px;' src='style/login.png' alt='Login' title='Login'/><br/>
                No account yet? <a href='../register.php'>Register</a>
                </p></form>";
        } else {
            echo "
                <h2>Welome, <a href='user.php' style='color: #1293EE;'>" .
                 $_SESSION['user_name'] .
                 "</a></h2>
                <a href='logout.php'>Log off</a>";
        }
    }

This piece of code generates the loginbox on every page, or displays a welcome message if the user is already logged in. As you can see, the action references to “../helpers/login.php”, because that’s the relative location of the loginhelper from this generator’s point of view.

Now, here’s the problem: If I press the login button on the index.php (http://example.com/ProjectName/index.php) it redirects me to http://example.com/helpers/login.php and says the file isn’t found.

I see what the problem is, the post action sees the request coming from index.php and goes up one directory and then looks for /helpers/login.php, which doesn’t exist of course.

A fix might be to change the action to

action='/helpers/login.php'

but that gives me the same problem should I need access to generateLogin() from within a certain subdirectory…
How can this particular problem be solved, i.e: that the reference to /helpers/login.php stays correct, no matter from where I try to access it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:01:39+00:00Added an answer on May 26, 2026 at 11:01 am
    action='/ProjectName/helpers/login.php'
    

    Assuming your root is http://localhost then the above link should always resolve to http://localhost/ProjectName/helpers/login.php whether it’s called from http://localhost/ProjectName/index.php or http://localhost/ProjectName/subdir/index.php

    If you don’t want to hardcode “ProjectName” into many different scripts, you can use a global variable and define it in a config file:

    helpers/ConfigOptions.php:

    <?php
    $ProjectName = "ProjectName";
    ?>
    

    Then in your scripts, include the config file and use the variable you defined:

    index.php:

    include $_SERVER['DOCUMENT_ROOT'] . '/helpers/ConfigOptions.php';
    
    ...
    
    echo "
      <form action='/$ProjectName/helpers/login.php'>
      ....
    ";
    

    More about DOCUMENT_ROOT:

    DOCUMENT_ROOT is defined in the server configuration file and is the root on the filesystem of where scripts are executing, not the web address you would type in a browser. In the above example, I’m assuming that document root looks something like /home/user/www/ProjectName. If DOCUMENT_ROOT is only /home/user/www then you can change your include path to this:

    include $_SERVER['DOCUMENT_ROOT'] . '/ProjectName/helpers/ConfigOptions.php';
    

    or use a relative path. My vote would be on the latter since you wouldn’t need to hardcode “ProjectName”.

    So include() and require() would take either:

    1. An absolute path to the file
    2. A path that’s relative to the current executing script. If A includes B and B includes C, when B includes C it needs to provide a path that is relative to A.

    So when do you need to use DOCUMENT_ROOT? Usually with templates where a relative path like ../helpers/file.php can resolve to different absolute paths depending on what’s including the file. In the above example where index.php is including ConfigOptions.php, you probably don’t need to use DOCUMENT_ROOT since index.php is not a template. I used it anyway to be safe, but maybe I opened up a whole can of worms here. I hope I didn’t confuse you even more.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.