6 Replies - 3886 Views - Last Post: 19 November 2009 - 01:16 AM Rate Topic: -----

#1 Copephobia  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 24
  • Joined: 15-November 09

Anchor tag and SERVER_ROOT

Posted 18 November 2009 - 11:21 PM

I'm currently making a website, and I am confused on what to do about SERVER_ROOT in my anchor tags.

Right now my index page looks like:

<?php
$server = preg_replace('/(.+\/).+\..+/', "$1", $_SERVER['SERVER_ROOT']);
include($server."include/header.inc");

echo "<a href=" . $server. "register.php>Register</a><br>";
echo "<a href=" . $server. "login.php>Login</a><br>";

?>



The header.inc file loads fine, however the links aren't working. The url becomes:
http://www.website.com/home/username/public_html/register.php

What I want is to have it just be:
http://www.website.com/register.php



I wish to correct the anchor tag problem.
Any ideas as to what I should do?

This post has been edited by Copephobia: 18 November 2009 - 11:21 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Anchor tag and SERVER_ROOT

#2 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5380
  • View blog
  • Posts: 27,350
  • Joined: 10-May 07

Re: Anchor tag and SERVER_ROOT

Posted 18 November 2009 - 11:28 PM

View PostCopephobia, on 19 Nov, 2009 - 12:21 AM, said:

Any ideas as to what I should do?

Do you ever leave the root directory?

I have used PHP_SELF in the past, but it's very very very important that you know there are known exploits for both PHP_SELF & SERVER_ROOT. Rather than trust what the server thinks it should be, tell it :)
Was This Post Helpful? 0
  • +
  • -

#3 Copephobia  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 24
  • Joined: 15-November 09

Re: Anchor tag and SERVER_ROOT

Posted 18 November 2009 - 11:29 PM

View Postno2pencil, on 18 Nov, 2009 - 10:28 PM, said:

View PostCopephobia, on 19 Nov, 2009 - 12:21 AM, said:

Any ideas as to what I should do?

Do you ever leave the root directory?



No, that file (and the register/login files) is the index.php for the website, I also have a test folder with the same file, and I get the same results except it is public_html/test/register.php

This post has been edited by Copephobia: 18 November 2009 - 11:30 PM

Was This Post Helpful? 0
  • +
  • -

#4 bbjay  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 18-November 09

Re: Anchor tag and SERVER_ROOT

Posted 19 November 2009 - 01:01 AM

Try this and see if its what you are trying to do:
<?php

include $_SERVER["DOCUMENT_ROOT"] . "/header.inc";

<? echo "<a href=\"" . $SERVER["DOCUMENT_ROOT"] . "/register.php\">Register</a><br>";
echo "<a href=\"" . $SERVER["DOCUMENT_ROOT"] . "/login.php\">Login</a><br>";

?>


Hope that helps.
BBJay
Was This Post Helpful? 0
  • +
  • -

#5 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5380
  • View blog
  • Posts: 27,350
  • Joined: 10-May 07

Re: Anchor tag and SERVER_ROOT

Posted 19 November 2009 - 01:05 AM

You have two start segments in your code.
Was This Post Helpful? 0
  • +
  • -

#6 Copephobia  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 24
  • Joined: 15-November 09

Re: Anchor tag and SERVER_ROOT

Posted 19 November 2009 - 01:14 AM

View Postbbjay, on 19 Nov, 2009 - 12:01 AM, said:

Try this and see if its what you are trying to do:
<?php

include $_SERVER["DOCUMENT_ROOT"] . "/header.inc";

<? echo "<a href=\"" . $SERVER["DOCUMENT_ROOT"] . "/register.php\">Register</a><br>";
echo "<a href=\"" . $SERVER["DOCUMENT_ROOT"] . "/login.php\">Login</a><br>";

?>


Hope that helps.
BBJay



That looks to be the solution, Interesting though that the underscore in the include line works there and not in the echo a href line.
But thank you!
Was This Post Helpful? 0
  • +
  • -

#7 bbjay  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 18-November 09

Re: Anchor tag and SERVER_ROOT

Posted 19 November 2009 - 01:16 AM

Sorry. I didn't test the second part, but I use the includes like that and it works for me. I just wanted to give him a general direction to get him started.

View Postno2pencil, on 19 Nov, 2009 - 12:05 AM, said:

You have two start segments in your code.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1