Solved

Accessing browsers request

Posted on 1997-12-11
8
160 Views
Last Modified: 2013-12-25
Hi there to all, hope you can help,
I'm writing a C program that needs to know Exactly what the User Typed in ie: a URL or IP number. Tryed environment vars PATH_INFO,& PATH_TRANSLATED, these returned NULL, REQUEST_URI not supported by my web server (Zeus), don't know where to go from here, if anyone can help it would be great.
0
Comment
Question by:Matlock
8 Comments
 
LVL 5

Expert Comment

by:icd
ID: 1831618
The only one that might be of help is REQUEST_URI but this does not include the domain name (or the IP).

Try writing a script that will print all environment variables and see if there is one you can use. (I can give you one in perl but not one in C).

If perl is OK then you can get one at:-

http://www.silkwood.co.uk/cgi-scripts/envir.pl

or run it at

http://www.silkwood.co.uk/cgi-bin/envir.pl

Perhaps it will help you.
0
 
LVL 1

Expert Comment

by:dagmar
ID: 1831619
If you're using perl, you really only need this to see all the environment variables Zeus passes to your CGI...

#!/usr/bin/perl

print "Content-type: text/plain\n\n";

foreach $Key (keys %ENV) {
  print "$Key = :$ENV{$Key}:\n";
}

exit;
0
 
LVL 1

Accepted Solution

by:
tiago earned 200 total points
ID: 1831620
use the environment variable "HTTP_HOST".

example in shell script:

<pre>
#!/bin/sh
echo "Content-type: text/plain"
echo
echo "Host:" $HTTP_HOST
</pre>


example in C:
<pre>
#include <stdio.h>
#include <stdlib.h>

main() {
    printf("Content-type: text/plain\n\n");
    printf("Host:%s\n",getenv("HTTP_HOST"));
}
</pre>
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:Matlock
ID: 1831621
I'm unable to grade tiago's answer as perhaps it would seem my question was not correctly phrased, I do not want to know who the Remote Host was  but whether they accessed my site by typing its DNS or by its IP number into their browser, and as unlikely as this may seem, it is actually quite possible for my site.
0
 
LVL 1

Expert Comment

by:tiago
ID: 1831622
"HTTP_HOST" is NOT the remote host!

"HTTP_HOST" provides exactly the information you want:
What host the user has typed in the URL.
0
 

Author Comment

by:Matlock
ID: 1831623
Appologies Tiago,
I misunderstood your response to my Question,
however regretably my server does not support this environment
variable. So I just don't have a clue where to go from here.
Hugh
0
 
LVL 1

Expert Comment

by:tiago
ID: 1831624
Try this (if you have not done it yet):

#!/bin/sh
echo "Content-type: text/plain"
echo
set


and take a look at what environment variables your server uses.
0
 

Author Comment

by:Matlock
ID: 1831625
Tiago, thankyou for your help but it would seem that my Web server doesn't support these environment variables.
I'm out of the office now for over a week so please dont think I'm ignoring any response from you.
Matlock                
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
change home folder path 4 56
scripting, exchange 35 56
User profile Size Report 3 84
Auto-indent certain lines in Notepad++ 10 112
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question