Jump to content


Photo

Base URL


  • Please log in to reply
3 replies to this topic

#1 Dville

Dville
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts

Posted 25 July 2006 - 03:52 PM

I searched both google and here for this, and couldn't find anything. But maybe the standard term for it isn't base url.


I have a config.php where i put the mysql database variables, along with the $admin variable, which tells the script what username in the users table has admin rights.

What I'm wanting to add to this config.php is a 'base url' variable of sorts, that will hold where the script is running from.

So if the user installs it to /digg or /was instead of / the rest of the url/links will be pointing in the right spot.

A - how do i setup this variable
B - how do i use it in the script

for example, if one of my lines look like this
<?php echo "/digg/comment.php?appid=$id"; ?>

where in the config, /digg would be the 'base url'. how would i change the link to work(syntax wise)


thanks in advanced for anyone who can help me with this

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 25 July 2006 - 03:59 PM

typically, when i need to do something like this, i just set a $path variable with my application root folder in relation to the server root in my include file. that way, whenever i call a link or action or whatever, i simply need to append $path to the front:
<?php
// in my include file
$path = "/myApp";

// then, in my application links:
echo "<a href=\"$path/index.php\">Home</a>\n";
?>

hope this helps
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 25 July 2006 - 04:00 PM

Hope I got it right, try this

$baseurl = 'http://'.$_SERVER['HTTP_HOST'].substr($_SERVER['SCRIPT_NAME'],0,strlen($_SERVER['SCRIPT_NAME'])-12);



Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#4 Dville

Dville
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts

Posted 25 July 2006 - 04:27 PM

cool, thanks obs. that wasnt too bad, i was thinking i had to use something like _BASE which i've no exp with.

thanks again




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users