Solved

Passing a JS var to PERL through SSI.

Posted on 1998-03-30
15
478 Views
Last Modified: 2013-11-18
Hi,
     I was wondering how I would go about sending a JS variable to a PERL script through SSI.  I've tried:

<!--#exec cgi="../cgi-bin/name.pl?parent.handle"-->
Where parent.handle = "bob"
but this doesn't work.

What it should do:
.
HTML would equal:
Bob's age is <!--#exec cgi='../cgi-bin/name.pl?parent.handle'-->
And the user would se:
Bob's age is 25.

How would I make it show the proper output so far I just get an error.
0
Comment
Question by:cide
  • 6
  • 3
  • 3
  • +2
15 Comments
 
LVL 3

Expert Comment

by:percyn
Comment Utility
I think you need to make JS print out the exec line so that the VALUE of the variable is passed to the CGI, not the variable itself.

e.g.

document.write ( "<!--#exec cgi='../cgi-bin/name.pl?" + myvar + " '-->

where myvar is the variable containing "Bob"
0
 

Author Comment

by:cide
Comment Utility
No, that didn't work.  I did more experimenting with it and the problem seems to be when I add anything after the ? even normal text.
0
 
LVL 28

Expert Comment

by:sybe
Comment Utility
try replacing the "?" with unescape(%nr) in which nr should be the ascii code for ?

so

document.write ( "<!--#exec cgi='../cgi-bin/name.pl" + unescape(%nr) + myvar + " '-->
0
 
LVL 10

Expert Comment

by:kollegov
Comment Utility
Hmmm...
Probably in this case exec cgi=  do not set enviroment variables
And do not recognize ?query ...

you can try using cmd instead of cgi like:

document.writeln('<!--#exec cmd="some.pl '+yourvar+'"-->')

this will be equivalent to call from cammand prompt
>some.pl yourvarvalue

but in this case parameter will be passed trough
$ARGV[0] variable :)
and association of perl to .pl extension should be set in system.

0
 

Author Comment

by:cide
Comment Utility
Doesn't solve the prob JavaScript is interprated after SSI.
0
 
LVL 10

Expert Comment

by:kollegov
Comment Utility
That what I'm was afraiding of....
Unfortunatly I do not find the way how to set enviroment
variables from Java Script. If this is possible you can pass
it through enviroment.
Last way is to pass through tmp file :(
Not the best solution...



0
 
LVL 2

Expert Comment

by:anguslai
Comment Utility
Before anwsering this question, we have to take a look at when the SSI work and when the JavaScript Work.
1) Before the web server send html to browser, ir parse the html and execute all SSI command in the html.
2) Server send the page to web browser.
3) Web Browser execute client side script (javascript) and html.

           Web Server                                           Web Browser
   -------------------------------------------                    --------------------------------------------------------
 |  html  -> execute SSI          |   ----------->   | execute JS, HTML, client side element|
  -----------------------------------------                     ----------------------------------------------------------

Therefore, If you try to pass client side javascript to a SSI, it will 100% fail. (In SSI state,
the web server don't know what is javascript. (except server-side javascript with Netscape server or ASP with microsoft Information Server)
 
However, there is 1 way to pass JS variable to cgi program in a html page.
you can use :
<img src="http://aaa/cgi-bin/myCGI?name=jsVar">
(sure, you have to use document.write() to write out this line with your jsVar)
In this case, your cgi must return a image, not text.

If you can explan your project more detail, likely we can provide you better answer.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:cide
Comment Utility
Hi,
    What we are trying to do is setup a login script.  We have it now so a person enters their username and pword into a form and this data is passed to PERL script for verification.  If this data is correct it returns a frameset (which is our main page).  The frameset also stores their handle though, as a JS variable.  We can then access their name whenever we want through parent.handle.  However we are having trouble sending this variable to SSI.  We don't want the user to have to click a submit button in order to run every script and we would also like to generate only part of a page at a time like SSI does.....
0
 
LVL 3

Expert Comment

by:percyn
Comment Utility
Then you are using SSI INCORRECTLY !!!!

If you want to call the perl script and pass it some arguments, try

location.href="/cgi-bin/myperlscript.pl?myvar"
 in Javascript.
0
 
LVL 10

Expert Comment

by:kollegov
Comment Utility
Well, Guys, BTW, what JS do you mean, when I answered this question I thought that you mean server-side JavaScript without any doubts, Anguslai in his answer supposed client-side script.
the whole scheme should be:

FILE->SSI(Perl)->ServerSsideJavaScript-->>--ClientJavaScript->HTML

So,Cide, just tell what side JavaScript you mean in question?

0
 

Author Comment

by:cide
Comment Utility
Client Side I'm not sure if my server supports Server Side.
0
 

Author Comment

by:cide
Comment Utility
I think Percyn almost has it except I don't want it to go to a new page.  I want it to append to the current page.  So use location.href="/cgi-bin/myperlscript.pl?myvar" but somehow get it not to go to a new page, just write in the current one.  Is this possible?
0
 
LVL 2

Accepted Solution

by:
anguslai earned 100 total points
Comment Utility
I guess you working in wrong direction.

Your current process is :
1) user type in userID and password
2) a perl cgi verify the id and pass and return something similar to the following:
   <frameset rows="50%, *">
       <frame name="A" src="pageA">
       <frame name="B" src="pageB">
   </frameset>
   and you have already set parent.handle in either pageA or pageB.
3) In pageA or pageB, you want to use SSI to invoke another CGI to get data into the page.

NOTE: If  pageA is generate by a script (the script adding some javascript variable to the page), SSI does not run at all. SSI work only if the web server return a web page to browser directly.

** Passing SSI with javascript is WRONG DIRECTION in this project.
Honestly, you should :
A) insert <!--#exec cgi="../cgi-bin/name.pl?bob"-->  directly to the html page, then return the following to the browser.
    <frameset rows="50%, *">
       <frame name="A" src="pageA.html">
       <frame name="B" src="pageB.html">
   </frameset>

OR

B) return the following to the browser :
   <frameset rows="50%, *">
       <frame name="A" src="pageA.cgi">
       <frame name="B" src="pageB.html">
   </frameset>
   in the program pageA.cgi, you execute name.pl and insrt the result to the page, then print out pageA.html to the browser.

   I know the solution is not that easy to do (require you to modify some existing scripts). However, if you still try to play around with the SSI, I bet you never finish this project.I'm sorry to bring this bad news.

Good Luck to you.
0
 
LVL 2

Expert Comment

by:anguslai
Comment Utility
By the way, why you post this question in perl section with 200 points, but post the same question in JavaScript Section with 100 Points?
Please reduce the point in Perl Section to 150 and increase point to 150 in JavaScript Section. (Unless you think that people who answering question in JavaScript section should earn less!)
0
 

Author Comment

by:cide
Comment Utility
Sorry, can't decrease points in other question.  Although, this seems to be going nowhere fast.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now