I tried adding $ENV{'HTTP_REFERER'} and no matter how I put that in I'd get an error.
$guestbookurl = "http://www.example.com/themes/includes-toolbar-comments.php";
$guestbookreal = "/home/example/public_html/themes/includes-toolbar-comments.php";
$guestlog = "/home/example/public_html/home/themes/includes-toolbar-comments.php";
$cgiurl = "http://www.example.com/cgi-bin/comments.pl";
John
Anyway this works...
$guestbookurl = $ENV{'HTTP_REFERER'};
So the problem is that the absolute server path will not work...so I need to somehow echo just the local path...
$ENV{'someperlcommand'}
...that will echo the server path as so...
/home/example/public_html/themes/includes-toolbar-comments.php
...instead of the internet path.
The error was (of course) that the file could not be found.
John
*Edit*
PS - Where could I find a full list of Perl's defined $ENV{} variables?
I'll need the variable that I can echo... /home/example/public_html/
...that or the full path minus the file name...and then add the file name with another variable.
Remember, I want to make this script dynamic in the sense that it writes to the refering file! :)
John
#!/usr/bin/perl
use strict;
print "Content-type: text/html\n\n";foreach my $var (sort keys %ENV) {
print "<b>$var</b> = $ENV{$var} <br>\n";
}
you could have found the error in the server error logs too, but the line I gave you makes it easy to see what the error is when you run it from a browser.
Here is what I get with two server enviormentals that catch my eye...
$ENV{DOCUMENT_ROOT} = /home/example/public_html
$ENV{'HTTP_REFERER'} = http://www.example.com/comments/comments.php
Since I can't directly get the server path of the referal file, I'm sure I could take the values that I need and merge them in to a single variable. Then I could just put that variable in to the place of the static server path and success! Or at least thats what I'm hoping...
I really don't know enough about Perl/CGI so I'll give you the visual I can work best with in my head...
$ENV{DOCUMENT_ROOT} = /home/example/public_html
Above is good and nothing we don't want so let's assign it's value to $1.
$1 = $ENV{DOCUMENT_ROOT}
( so $1 = /home/example/public_html )
Now the tricky part (for me at least) is getting rid of part of the next value of the predefined variable...
$ENV{'HTTP_REFERER'} = http://www.example.com/comments/comments.php
We want to get rid of "http://www.example.com" and assign $2 to equal "/comments/comments.php".
$1 = $ENV{DOCUMENT_ROOT}
( so $1 = /home/example/public_html )
$2 = $ENV{'HTTP_REFERER'} - http://www.example.com
( so $2 = /comments/comments.php )
That way we can merge $1 + $2....
$3 = $1 + $2
Which I would imagine would equal...
/home/example/public_html/comments/comments.php
So how do we make that work (if it will?)
John
Dynamic Value
/comments/comments.php
I need to merge these. Remember, I want to make the script usable from any file on my server that refers to it.
IE...
http://www.example.com/home/comments1.php
http://www.example.com/home/comments2.php
http://www.example.com/home/comments3.php
http://www.example.com/home/comments4.php
But the script requires the full server path. So in essence we're trying to make the file dynamically create the full server path of the referer.
So any of these examples as referers (as being the form that is submitted to the script)...
http://www.example.com/home/comments1.php
http://www.example.com/home/comments2.php
http://www.example.com/home/comments3.php
http://www.example.com/home/comments4.php
Would be reformed in to absolute server paths...
/home/example/public_html/home/comments1.php
/home/example/public_html/home/comments2.php
/home/example/public_html/home/comments3.php
/home/example/public_html/home/comments4.php
So if you go back and reread my previous you can maybe now with a clearer understanding (because I suck at programming and thus explaining my ideas a lot) that I was trying to construct an -absolute server path of the refering file-.
So in review of the full script (to try and help round out the explenation....
1.) User fills form on ...
/home/example/public_html/home/comments3.php
2.) Script gets file with referer sent by the browser.
3.) Script uses a miniscript (the script we're trying to put together in this thread) to create an -absolute server referer path-.
4.) The absolute server referer path is set to a variable (in my previous post, this variable was $3).
5.) Later in the script when it writes the contents to the referer we get the $3 variable which is our dynamically created -absolute server referer path-.
The script writes to the file that the form was on.
So...here was my idea slimmed down to a simple question...
How can I set the $2 variable to equal the same as $ENV{'HTTP_REFERER'} but without "http://www.example.com"?
We start with...
$ENV{'HTTP_REFERER'} = http://www.example.com/comments/comments.php
(remember I'm using the specific file as a static referer here, but it would be whatever the refer is in the script)
Then I want to merge...
$1 = $ENV{DOCUMENT_ROOT}
and ...
$2 = $ENV{'HTTP_REFERER'}
and assign these combined variables to $3.
So in this example...
$3 = /home/example/public_html/home/comments.php
So we're removing the domain and then setting the rest of $ENV{'HTTP_REFERER'} to $2.
We then just add $1 and $2 together to set $3.
$3 = whatever the refer was...it's absolute server path.
But I don't know the syntax to the extent you do.
John