473,800 Members | 2,365 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Server variable $_SERVER["DOCUMENT_R OOT"]

18 New Member
Hi,
I am using the Linux Server and server variable $_SERVER["DOCUMENT_R OOT"] to get the root folder to open a text file located in the folder for ex.

fopen($_SERVER["DOCUMENT_R OOT"]."/folder/file.txt","r");
......


I want to use the same scripts to work with Windows Server, Is there any way to get the root folder of the domain installation in Windows?
like it should return c:\www


Could any one suggest me?

Thanks in advance

Sakthi
Dec 25 '07 #1
6 8705
pbmods
5,821 Recognized Expert Expert
Heya, Sakthi.

$_SERVER['DOCUMENT_ROOT'] evaluates to the path to your server's document root regardless of operating system....
Dec 25 '07 #2
sakthipro
18 New Member
Heya,
I didn't find the variable $_SERVER["DOCUMENT_R OOT"] in the phpinfo() in the Windows server. How to enable this variable in Windows Server?

Sakthi
Dec 26 '07 #3
pbmods
5,821 Recognized Expert Expert
Heya, Sakthi.

... except for Windows, it seems, which likes to make life difficult.

Do you have $_SERVER['ORIG_PATH_TRAN SLATED'] by any chance?

Alternatively, if you have a file at the document root, you can use dirname(__FILE_ _).
Dec 27 '07 #4
sakthipro
18 New Member
Hi,
Its working in Windows, but is not the situation,
I want a single variable that returns the document root in both servers,
here the _SERVER["ORIG_PATH_TRAN SLATED"] variable is not available in my Linux Server.

For ex,
1. In Linux Server it should refer /www/project
2. Where as in Windows Server it should return D:\www\project

where project is the root for the particular project

Suggest me

Sakthi
Dec 27 '07 #5
sakthipro
18 New Member
Heya,
Actually the problem with dirname(__FILE_ _) is,
When I call this from the root, ie. from /www/projects it solves the situation.

The problem is, when I call from the sub directory inside the root ie.

From /www/projects/aaa, I want to refer the path /www/projects/bbb, here the function returns /www/projects/aaa as result, so the final result will be,

dirname(__FILE_ _)."/bbb" = /www/projects/aaa/bbb which is wrong

Suggest me

Sakthi
Dec 29 '07 #6
pbmods
5,821 Recognized Expert Expert
Heya, Sakthi.

Try creating a common include file in your document root:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     if( empty($_SERVER['DOCUMENT_ROOT']) )
  3.     {
  4.         $_SERVER['DOCUMENT_ROOT'] = dirname(__FILE__);
  5.     }
  6. ?>
  7.  
Then simply include() this file at the top of any script that needs to use $_SERVER['DOCUMENT_ROOT'].
Dec 30 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

8
10917
by: MeAndI | last post by:
How to everybody, how it is possible to change the value of the AUTH_USER server variable? Is this possible? If no, how I could change the logged user? Thanks for help
4
3511
by: Bob T | last post by:
Hi All, I am trying to pass a variable from my VB asp.net script (from for example Sub Page_Load in mypage.aspx.vb) to my Client side script. I have found and looked at a very good example "Client and Server Scripting in Web Pages" but it only shows server side scripting that is written in HTML in mypage.aspx and not script from mypage.aspx.vb. How can I pass a variable value from mypage.aspx.vp to my client side script?
15
5763
by: joun | last post by:
Hi all, i want to create in my asp.net application a custom server variable, so i can retrieve later in other pages (even asp or perl) with request.servervariables("HTTP_mycustomvariable") i've tried with response.appendheader("mycustomvariable", "somevalue") but this doesn't work, or the variable scope is limited to aspx files, not asp or perl. So there is a solution with my problem, event with a external vc++ program?
1
1312
by: Tillman | last post by:
I am working on reducing the size of the ViewState value passed between client and server in a web app. And I am asking myself why the ViewState value can't be stored in a server variable rather than in the hidden input control. Can someone give me the answer?
2
2923
by: shil | last post by:
Hi all, I am using javascript confirm() function to get user's confirmation from codebehind after a condition is met. I don't want to attach the function to the button on page load. When I submit the page, I want to check some business rules, and based on the response from the database, if the response is Yes, I need to display a confirmation alert to user. When the user clicks ok, then I should take an action, if not, exit out of the...
0
1013
by: ndrw_cheung | last post by:
Hi, all. I recently migrated a website from IIS5.0 (running on Windows 2000 Server SP4) to IIS6.0 (running Windows Server 2003 SP1). The ASP.NET version is upgraded from 1.1 to 2.0 as well. I found that the value of the server variable "QUERY_STRING" differs. I don't know if it is because of the IIS version change or the .NET version change. For example : IIS5.0 and ASP.NET 1.1 : it returns http://www.test.com/mypage
1
1437
by: mbasil77 | last post by:
I'm trying to create a custom server variable in DOTNET. Is there a way to do this? I know there are MUCH better/easier ways to store session data ... However, I'm dealing with a legacy application that relies on this. Thanks in advance. mb
6
1791
by: rlm51 | last post by:
Hey everyone, hope all are fine ... Dreamweaver uses a login_user server behavior to send the user to a specified page on a successful login. Normally you would provide a url, but I would like to use the server variable that holds the url of the last page visited so I can use the same login form for different sections of the website. $MM_redirectLoginSuccess = $_SERVER; doesn't work. The command doesn't recognize it as a pathname. ...
8
2829
by: doublestack | last post by:
I have a server variable that is being called from an aspx page in a WSS site. I need to find a way to remove part of the variable before passing it to the URL. The server variable is LOGON_USER... TIA
0
9697
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9555
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10515
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10291
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10260
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10049
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9100
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
2
3771
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2956
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.