File targeting.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sHobbsWW
Forum Newbie
Posts: 15
Joined: Wed Jul 16, 2008 10:48 am

File targeting.

Post by sHobbsWW »

I know this probably has an easier solution and I am just over thinking it but:

Say every page you have has a function in php that checks your login status.
--If you are logged in, it says "Hi $accountName"
--If not it pops up the login form.

Here is the code:

Code: Select all

 
function loginStatus(){
        if ($_SESSION['loginStatus'] == "logedIn"){
            $userName = $_SESSION['userLogin'];
            echo "Welcome $userName";       
        } else {
            echo "<form action=\"../php/[color=#00BF40]verify.php[/color]\" method=\"post\" name=\"loginVerify\">
                    Username:: &nbsp;<input type=\"text\" name=\"user\" size=\"8\"/>
                    <br/>
                    Password:: &nbsp;<input type=\"password\" name=\"pass\" size=\"8\"/>
                    <br/>
                    <input type=\"submit\" value=\"login\" name=\"submit\"/>
                </form>";
        }
    }
 
The problem is targeting the verify.php without using a absolute link (http: //www.domain.com/php/verify.php)

I understand you can use relative targeting (../php/verify.php), but this becomes a problem when a page is visited within directories that go deeper then the relative target. So in some cases a page might have to (../../../ etc...) to target the verify.php file.

Is there a way / method to doing this with out using absolute targeting which includes the domain?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: File targeting.

Post by requinix »

Absolute links don't need the domain name. "/php/verify.php" is perfectly fine.
Post Reply