Forums

Unfortunately no one can be told what FluxBB is - you have to see it for yourself.

You are not logged in.

#1 2015-04-08 09:12:23

joel
Member
Registered: 2014-07-04
Posts: 440

reworking on a script and issues access a web sub folder

if i try to access the files
from other sub folders, it's calling webroot from
the current folder instead of going back to
the root. pls can any1 help me with the
code/logic for defining web root in a
situation like this. thanks.

it as this defined all over the codes.

define (WEB_ROOT)

and echo web_root.

example you are in localhost/home/admin/admin.php

if you click user from admin.php.

the URL will jump to
localhost/home/admin/home/admin/user.php

creating error page.

this is massively in all pages.


Warning! be informed and be forewarned. <p>
<?php
I'm not a native English Man. So my comments might contain some grammatical explosive (ELD), missapropreation of words (dinamyt), The use of wrong words (missiles), & mis spelling of words (war drones). Any of the occurrence can cause havoc. So be warned
?>

Offline

#2 2015-04-08 12:10:01

Sxderp
Member
Registered: 2012-11-02
Posts: 101

Re: reworking on a script and issues access a web sub folder

Without seeing code we can't do much.

But I think what you need is relative pathing.

If you are located at:
/home/admin/admin.php

Then the link you need is:
"../users.php"
Or
dirname(__FILE__) . "../users.php"

The first one resolves the working directory then moves up one folder. The second one resolves the path of the current file then moves up one.

---------------

Alternatively, if you want to use the constant approach you need to ensure you are actually defining something in the define(). What you posted doesn't put a value to WEB_ROOT.

You want define("WEB_ROOT", dirname(__FILE__))
This should be defined in a file your /home directory and then that file should be 'include'
Or, depending on the host there is a variable $_SERVER["DOCUMENT_ROOT"] you could use. However, this may not be good if the web server root is not the same as the php root.

Anyway, our link would be:
WEB_ROOT . "/user.php"

Last edited by Sxderp (2015-04-08 12:25:21)

Offline

#3 2015-04-08 12:16:57

chris98
Member
From: England, United Kingdom
Registered: 2013-05-31
Posts: 1,292
Website

Re: reworking on a script and issues access a web sub folder

You shouldn't use ../ for obvious reasons, if you change it at some point, it becomes harder to change back to make it work. A constant approach would probably be best, or use a base URL in front of all links.

But, Sxderp is right. We need to really see code.

Last edited by chris98 (2015-04-08 12:17:31)

Offline

#4 2015-04-21 18:02:06

joel
Member
Registered: 2014-07-04
Posts: 440

Re: reworking on a script and issues access a web sub folder

example

<html>
<head>
<title><?php echo $pageTitle; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="<?php echo WEB_ROOT;?>admin/include/admin.css" rel="stylesheet" type="text/css">
<link href="<?php echo WEB_ROOT;?>include/style.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/javascript" src="<?php echo WEB_ROOT;?>admin/library/common.js"></script>
<?php
$n = count($script);
for ($i = 0; $i < $n; $i++) {
	if ($script[$i] != '') {
		echo '<script language="JavaScript" type="text/javascript" src="' . WEB_ROOT. 'admin/library/' . $script[$i]. '"></script>';
	}
}
?>
</head>

<body>
<br>
<table width="700" border="0" align="center" cellpadding="2" cellspacing="1">
 <tr align="center"> 
  <td width="20%" class="nav"><a href="<?php echo WEB_ROOT;?>admin/index.php" class="nav">HOME</a></td>
  <td width="20%" class="nav"><a href="<?php echo WEB_ROOT;?>admin/category/index.php" class="nav">CATEGORY</a></td>
  <td width="20%" class="nav"><a href="<?php echo WEB_ROOT;?>admin/product/index.php" class="nav">PRODUCT</a></td>
  <td width="20%" class="nav"><a href="<?php echo WEB_ROOT;?>admin/orders/index.php" class="nav">ORDERS</a></td>
  <td width="20%" class="nav"><a href="<?php echo WEB_ROOT;?>admin/shop/index.php" class="nav">SHOP CONFIG</a></td>  
 </tr>
</table>
<p>&nbsp;</p>

the link keep jumping from localhost/online/admin to locahost/online/admin/online/admin


Warning! be informed and be forewarned. <p>
<?php
I'm not a native English Man. So my comments might contain some grammatical explosive (ELD), missapropreation of words (dinamyt), The use of wrong words (missiles), & mis spelling of words (war drones). Any of the occurrence can cause havoc. So be warned
?>

Offline

#5 2015-04-21 18:09:27

joel
Member
Registered: 2014-07-04
Posts: 440

Re: reworking on a script and issues access a web sub folder

$thisFile = str_replace('\\', '/', __FILE__);
$docRoot = $_SERVER['DOCUMENT_ROOT'];

$webRoot  = str_replace(array($docRoot, 'library/config.php'), '', $thisFile);
$srvRoot  = str_replace('library/config.php', '', $thisFile);

define('WEB_ROOT', $seRoot);
define('SRV_ROOT', $srvRoot);


what is missing here????


Warning! be informed and be forewarned. <p>
<?php
I'm not a native English Man. So my comments might contain some grammatical explosive (ELD), missapropreation of words (dinamyt), The use of wrong words (missiles), & mis spelling of words (war drones). Any of the occurrence can cause havoc. So be warned
?>

Offline

Board footer

Powered by FluxBB