>>Q1. If I click on a link to go to another HTML page say name.html, I
>> lose the "hop=some_data" part. How do I make the "hop=some_data" go
>> with the "name.html" with the <a> tag from an HTML document ? Is this
>> possible or a script can do this only ?
>
> there are a couple ways -
> one way is to add the "hop=some_data" to the href itself, IF it is a
> static string...  ie:   <a
> href="http://www.domain.com/name.html?hop=some_data";> otherwise, you can
> implement a simple CGI/Perl script to generate the index page from a
> template...

Well the "hop=some_data" is dynamic. Looks like a script is required to do
this then, and pass it dynamically to all <a> tag on the page being viewed
so that when a new page is clicked on, the "hop=some_data" is preserved.

>
>
>>Q2. The order page calls a Perl script say "orderpage.pl", I want the
>> script to capture the "hop=some_data". I got the script to print the
>> whole %ENV, and I see no "HTTP_REFERER". I thought "HTTP_REFERER" would
>> show the url that called "orderpage.pl" with the "hop=some_data" . But
>> if I cannot see "HTTP_REFERER", then how do I get the script to capture
>> the
>>"hop=some_data" ?
>
> The ENV variable you are looking for is definitely the QUERY_STRING...
> or use STDIN to retrieve POST data...

Well from the page

http://www.yourdomain.com/index.html?hop=some_data

I clicked on a link for the order page which has this

<a
href="http://www.yourdomain.com/cgi-bin/orderpage.pl?value=some_data_the_order_script_uses";>

This shows QUERY_STRING as

value=some_data_the_order_script_uses

It looks like I need to somehow parse the "hop=some_data" dynamically to
the "orderpage.pl" scripts so that when clicked it has this

href="http://www.yourdomain.com/cgi-bin/orderpage.pl?value=some_data_the_order_script_uses&hop=some_data";

Any other way I can do this ?

>
> If you are using perl (looks like you are using a hash there - %ENV)
> then you can
> either use the CGI module to retrieve the query strings, in which case
> you don't
> have to worry about that at all, or you can do something like this -
>
>
> my %formData;
>
> read STDIN, $_, $ENV{'CONTENT_LENGTH'};  #Read in STDIN to default
> variable...
> %formData = split/&|=/;                  #Place separate keys/values
> into 'formData' hash, split by '&' and '='
> if (!%formData)                              #- If we didn't get
> anything from POST method,
> {
>    $_ = $ENV{'QUERY_STRING'};                #  try retrieving it from
> QUERY_STRING (GET method)
>    %formData = split/&|=/;                   #  and split like before.
> }
>
>
> Then to access the data, you would go:
> my $hop = $formData{'hop'};
>
> This is a quick hack - CGI module is much better & more efficient
>  eg. what happens when you get a number of values from <select multiple>
> in
> this code?
>

Thanks for this piece of code. I already have a read_input() sub doing
something similar.


-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug

Reply via email to