473,765 Members | 1,909 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

custom server variables

Is it possible to set a custom server variable so that it may be used
in the latter part of a script? Say something like $_SERVER["myvar"] =
"myvalue", and then be able to use 'myvar' later.

The reason being that I want some client-side information to flow to
PHP, and the PHP script flow will be controlled depending on this
information.

[snippet]

<?php
if ($_REQUEST["action"] == "setvar")
{
$_SERVER["WindowName "] == $_REQUEST["window"];
exit ();
}
?>
<HTML>
<HEAD>
<SCRIPT TYPE="TEXT/JAVASCRIPT">
var xmlhttp = new ActiveXObject(" Microsoft.XMLHT TP");
var request =
"http://saraswati.tally solutions.com/tallyweb/test/TestRithishGene ric.php?action= setvar&window=" +window.name;
xmlhttp.open("P OST", request, false);
xmlhttp.send();
response = xmlhttp.respons eText;
</SCRIPT>
</HEAD>
<BODY>
<?php
if ($_SERVER["WindowName "] == "x") { ... do this ... }
else { ... do that ... }
?>
</BODY>
</HTML>

[/snippet]

Basically, the execution flows depending on which window the file is
being invoked in. I guess I could use sessions for this. However, I
wanted to know if there were any alternative to sessions. Setting &
Getting a server variable would be that much more simple.

And before I am flamed, the app is being developed for our intranet,
and hence you see the usage of ActiveXObject(" Microsoft.XMLHT TP")

Suggestions / comments / even flamings solicited.

Regards,
Rithish.

Dec 27 '05 #1
6 12858
ri*****@gmail.c om wrote:
Is it possible to set a custom server variable so that it may be used
in the latter part of a script? Say something like $_SERVER["myvar"] =
"myvalue", and then be able to use 'myvar' later.


Yes, you can do that, however once the script ends, the variable is
gone. If you want to do it across requests you'll need to use sessions
or some other storage method (database, files, etc.)

If you want to set a server "variable" it acts more like a constant. For
instance, if you use Apache and have done something like:

SetEnv apache_var1=34

Then in (all) your php scripts, $_SERVER['apache_var1'] == 34

You cannot do something like $_SERVER['apache_var1'] = 63 and have the
next request produce that value...

--
Justin Koivisto, ZCE - ju****@koivi.co m
http://koivi.com
Dec 27 '05 #2
ri*****@gmail.c om wrote:
Is it possible to set a custom server variable so that it may be used
in the latter part of a script? Say something like $_SERVER["myvar"] =
"myvalue", and then be able to use 'myvar' later.
You could, but I would advice you against to do a such thing, as you will most
likely get trouble to see from where the value comes when you are to debug
your code a long time later or it can be someone else who does the debugging.

Use a normal global value instead, like

$myvalue = "myvalue";

The reason being that I want some client-side information to flow to
PHP, and the PHP script flow will be controlled depending on this
information.

[snippet]

<?php
if ($_REQUEST["action"] == "setvar")
{
$_SERVER["WindowName "] == $_REQUEST["window"];
exit ();
}
This don't make any sense, you assign a value to an array and then exit the
script and you loose the value at the same time.

Basically, the execution flows depending on which window the file is
being invoked in. I guess I could use sessions for this. However, I
wanted to know if there were any alternative to sessions. Setting &
Getting a server variable would be that much more simple.
The alternative to sessions are called cookies, but it's really not an
alternative as sessions usually are cookies.

And before I am flamed, the app is being developed for our intranet,
and hence you see the usage of ActiveXObject(" Microsoft.XMLHT TP")


Your loss, not mine...
Dec 27 '05 #3
J.O. Aho wrote:

The alternative to sessions are called cookies, but it's really not an
alternative as sessions usually are cookies.


Sessions are not usually cookies... The session id is usually sent via a
cookie. The session data is usually stored in a file or database on the
server.

--
Justin Koivisto, ZCE - ju****@koivi.co m
http://koivi.com
Dec 27 '05 #4
NC
rith...@gmail.c om wrote:

Is it possible to set a custom server variable so that it may be used
in the latter part of a script? Say something like $_SERVER["myvar"] =
"myvalue", and then be able to use 'myvar' later.


What's wrong with a session variable? Set $_SESSION["myvar"] =
"myvalue",
and use it later.

Cheers,
NC

Dec 27 '05 #5
>Is it possible to set a custom server variable so that it may be used
in the latter part of a script? Say something like $_SERVER["myvar"] =
"myvalue", and then be able to use 'myvar' later.
You can't make changes to $_SERVER and have them stick in subsequent
invocations of PHP. And even if you could, you wouldn't want to,
especially for this application.
The reason being that I want some client-side information to flow to
PHP, and the PHP script flow will be controlled depending on this
information.
You want client-side information to flow from MY browser to PHP,
and from there control the script flow for ME, YOU, THE POPE, and
PRESIDENT BUSH? In the current political environment, that may
make you guilty of treason. I hope this information does not contain
credit card numbers or nuclear launch codes.
<?php
if ($_REQUEST["action"] == "setvar")
{
$_SERVER["WindowName "] == $_REQUEST["window"];
exit ();
}
?>
<HTML>
<HEAD>
<SCRIPT TYPE="TEXT/JAVASCRIPT">
var xmlhttp = new ActiveXObject(" Microsoft.XMLHT TP");
var request =
"http://saraswati.tally solutions.com/tallyweb/test/TestRithishGene ric.php?action= setvar&window=" +window.name;
xmlhttp.open(" POST", request, false);
xmlhttp.send() ;
response = xmlhttp.respons eText;
</SCRIPT>
</HEAD>
<BODY>
<?php
if ($_SERVER["WindowName "] == "x") { ... do this ... }
else { ... do that ... }
?>
</BODY>
</HTML>

[/snippet]

Basically, the execution flows depending on which window the file is
being invoked in. I guess I could use sessions for this. However, I
wanted to know if there were any alternative to sessions. Setting &
Getting a server variable would be that much more simple.
No, setting and getting a server variable would be really, really
messy. Have you ever thought about what a grocery store would be
like if each store had exactly ONE cart, and all customers had to
share it? Oh, yes, your customers DON'T have unique identification,
like driver's license numbers, names, IP address, or whatever.

How do you propose for this to work when you've got 500 simultaneous
users? (Sessions are a good way of letting each user have his
own set of variables.)

Variables passed in a URL as you show above show up in $_GET or
$_POST (and $_REQUEST). It seems like you are using the variable
in the same page fetch as retrieving it, in which case why bother
with "server variables"?
And before I am flamed, the app is being developed for our intranet,
and hence you see the usage of ActiveXObject(" Microsoft.XMLHT TP")

Suggestions / comments / even flamings solicited.


Gordon L. Burditt
Dec 28 '05 #6
I think you'll be better served by having two separate scripts
altogether, as you seem to have two distinct execution paths. It
doesn't make sense to make the decision on which fork to take yet
postpone the actual divergence.

Dec 28 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
4174
by: laurenq uantrell | last post by:
I'm using Access 2K. I'm hoping someone can tell me which method performs faster- (currently I'm using a mix of both methods) a.) creating custom properties and then calling functions to set and retrieve the values... (ie: application.currentproject.properties(propName)) b.) creating global variables in the form of an array and using a function to populate and retrieve them.
3
10837
by: Joe Bloggs | last post by:
Does anyone know if its possible to pass parameters or the values of Request.QueryString from a web page to a custom control class? I'm using a C# Web Application. For Example I have Web Page1 which has to parameters passed to it from another Web page Parameter # 1 dbid and Parameter # 2 reportid. I know that I can access the values of the parameters from the code behind .aspx.cs using Request.QueryString so
6
3255
by: Scott Zabolotzky | last post by:
I'm trying to pass a custom object back and forth between forms. This custom object is pulled into the app using an external reference to an assembly DLL that was given to me by a co-worker. A query-string flag is used to indicate to the page whether it should instantiate a new instance of the object or access an existing instance from the calling page. On the both pages I have a property of the page which is an instance of this custom...
15
5759
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
2643
by: Beren | last post by:
Hello With trial and error I'm attempting to create an extended identity to store some more data than just the Name, for example a Subscription and a LastSearchPerformed property... Is this a good idea ? I'm coming from ASP and Session variables, but I explicitly wanted to avoid that for .NET. The problem I'm facing is that I don't find a good way to bring my source
0
1561
by: Roy | last post by:
Hey all, I must be losing my touch. I have made many pages in the 1.1 framework that utilize custom bidirectional paging in datagrids. We've converted over to 2.0 and I've been trying to use the built-in functionality of gridviews and objectdatasource's to accomplish the same thing (w/o resorting to the 1.1 methodology). I discovered two very nice and comprehensive articles concerning this: Custom Paging in ASP.NET 2.0 with SQL Server...
0
1354
by: EADeveloper | last post by:
Quick ASP.Net architectural question.... We're creating a set of standard web controls for use in our app, and those custom controls need access to a set of variables that we are initializing at the PAGE level (in the Master page, actually). What's the syntax to access those variables from inside the custom control's render sub? Will we be able to just reference Master.varnm like we can in the page, or is there a different syntax when...
4
2334
by: Charles Zhang | last post by:
I created a custom server control whose rendering logic relies on session variables and cookies. It works just fine at run time. The problem is at the design time, because session variables and cookies are not available, so that I get error messages. I just wonder if there are any way such as conditional compile options to overcome the problem? Thanks Charles Zhang
0
4430
by: Tom | last post by:
I've been trying to install the PECL library libssh2 for secure shell2 functions. I'm on a shared webhost which allows custom php installations that run as a CGI binary. I've been trying to configure libssh2 but I cannot get the server I'm on to find autoconf... it originally was not installed on the server, so I downloaded, unpacked, and installed it successfully to a custom folder in my /home directory (along with autoheader). ...
0
9566
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
9393
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
10153
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
10007
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
9946
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
9832
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
8830
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...
1
7371
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6646
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...

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.