5 Replies - 541 Views - Last Post: 29 March 2013 - 11:00 PM Rate Topic: -----

#1 DoxramosPS  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 174
  • Joined: 07-October 12

Site Root Variables

Posted 29 March 2013 - 11:24 AM

Hey Everyone. So I'm working on a website now that I plan on making forums and an install and everything for. After you do the install I want it to redirect you to the admin page, but I'm having a bit of issues with it on localhost so I'm assuming there's going to be an issue doing it on a mainstream server as well. At the moment I have it set to where you finish the final bits of the admin page and when you click Finish it sends you to
$SITE_ROOT = $_SERVER['DOCUMENT_ROOT']; 
<a href="<?php echo ''.$SITE_ROOT.'/admin/'; ?> class="continue_button_active">Finish</a>


Which would work great if it read right, but when the link is created it's actually read by the server as
<a href="localhost/var/www/admin">


Since it's localhost www is where localhost is sending you right away so by sending it to localhost/var/www/admin I believe it's being read essentially as /var/www/var/www/admin. Does anyone know a better way to go about setting this up since it will be needed for the forums later on as well as they'll be in a different directory forum so it would need to utilize the $SITE_ROOT variable to send it correctly as well. Thanks for any help out there.

Is This A Good Question/Topic? 0
  • +

Replies To: Site Root Variables

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4333
  • View blog
  • Posts: 12,128
  • Joined: 18-April 07

Re: Site Root Variables

Posted 29 March 2013 - 11:33 AM

DOCUMENT_ROOT is the path from which the documents are served from. Check out $_SERVER["SERVER_NAME"] or $_SERVER["HTTP_HOST"] but that one may not exist. Server name may be what you are looking for. :)
Was This Post Helpful? 1
  • +
  • -

#3 DoxramosPS  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 174
  • Joined: 07-October 12

Re: Site Root Variables

Posted 29 March 2013 - 12:16 PM

Thought Server_Name was what I was looking for, but when used in a link it comes out a little off still. Say I'm in the install folder and I'm having it link back to the admin folder in the root.
<a href="<?php echo ''.$_SERVER["SERVER_NAME"].'/include'; ?>">Link</a> 


Will have Link link to localhost/install/localhost/admin rather then stripping out the localhost/install part of the link. HTTP Hosts exists so far, but gives the exact same string. I don't know if there's a way to Strip the localhost/install out of it universally (IE; Say someones domain is mydomain.com to strip out mydomain.com/install and only link mydomain.com/admin and then strip someones who is mydomain.org) Hopefully that makes sense. I know it's possible so I'll keep looking around and keep it posted what I find.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3479
  • View blog
  • Posts: 11,826
  • Joined: 12-December 12

Re: Site Root Variables

Posted 29 March 2013 - 12:26 PM

I might be missing something, but if you are returning to the root folder then doesn't

<a href='/admin/'>

work?

This assumes, of course, that there is an index.php in this folder or that re-directs have been configured on your server.

This post has been edited by andrewsw: 29 March 2013 - 12:32 PM

Was This Post Helpful? 1
  • +
  • -

#5 DoxramosPS  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 174
  • Joined: 07-October 12

Re: Site Root Variables

Posted 29 March 2013 - 12:32 PM

Basic Directory Navigation Win. Thanks a ton Andrew that's all I need to do this whole time that I've been trying to set up a navigation. For some reason I was thinking that /admin would tell it to go to install/admin.
Was This Post Helpful? 0
  • +
  • -

#6 DoxramosPS  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 174
  • Joined: 07-October 12

Re: Site Root Variables

Posted 29 March 2013 - 11:00 PM

Trying to find out why this portion isn't working. I had to use the site root to copy a file after it's had user inputted information appended, but it isn't working for the second copy.
This is the code I'm trying to use.
$SITE_NAME = $_POST['Site_Name'];
		$SITE_EMAIL = $_POST['Admin_Email'];

$str=file_get_contents('tempFile.txt');



$str=str_replace(
array('SITENAME','ADMINEMAIL'),
array("$SITE_NAME","$SITE_EMAIL"),$str);

file_put_contents('tempFile.txt', $str);
copy('tempFile.txt', ''.$SITE_ROOT.'/include/config.php');
copy('tempFile.txt', ''.$SITE_ROOT.'/install/includes/config.php');


It writes to the first include, but not the second one in the install directory.
I've tried using
copy('tempFile.txt', '/install/includes/config.php');


As well, but it still doesn't copy. I tried removing the first copy and it didn't copy over to it. It's almost as if the path doesn't exist, but I'm 100% positive the path is correct.
'.$SITE_ROOT.'/install/includes/config.php'


Directs to /var/www/install/includes/config.php and doesn't write the new copy.
and
'.$SITE_ROOT.'/include/config.php'


Directs to /var/www/include/config.php and does write the new copy.
Last but not least I have also tried having it set to
copy('tempFile.txt', 'includes/config.php');


And that has also proved to fail. And so that no one thinks I mislabeled the directory. The include path for the site root is include and the one for the install is includes.
I had attempted to use
require_once('/include/config.php');


require_once(''.$SITE_ROOT.'/include/config.php');


And both produced a blank screen which I can only assume means that it didn't find the path (Which means I also need to look into my PHP E_WARNINGS in my config)
SITE_ROOT is defined as $_SERVER['DOCUMENT_ROOT'] Just to knock that out now as well which sets to /var/www and seems to only work for the first copy function. (Not any other thing though.) Other than that. I'm not sure what else I can say regarding the matter. Appreciate any help that can be given regarding this issue.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1