LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-12-2008, 07:07 AM   #1
extasic
LQ Newbie
 
Registered: Oct 2008
Posts: 7

Rep: Reputation: 0
run CGI and pass GET parameters


Hi,

I want to include the output of the mailgraph perl script (mailgraph.cgi) in my php web. The graphics I need are generated by passing a "QUERY_STRING" to the script, so I would get the output by typing

Code:
export QUERY_STRING="0-n"
./mailgraph.cgi
in the shell.

That graphics should be included in a web that is used by several users simultaneously so I'm looking for a shell command that is executed within PHP and passes a QUERY_STRING value without using the environment variable so the different users don't get in each others way.

Do you know how I can solve that?

Thank you in advance!

Last edited by XavierP; 10-13-2008 at 04:20 AM. Reason: Moved to Programming
 
Old 10-16-2008, 08:17 AM   #2
rglang
LQ Newbie
 
Registered: Apr 2008
Location: Chardon, Ohio
Distribution: RedHat Enterprise, Fedora
Posts: 2

Rep: Reputation: 0
You can do a couple of things. The most straightforward is to pass the data in as arguments to the command itself:

./mailgraph.cgi?0-n

This is easily handled by the script and this form is typically used when passing parameters from a Web page (like a URL link) to a CGI program.

Rich
 
Old 10-16-2008, 11:06 AM   #3
extasic
LQ Newbie
 
Registered: Oct 2008
Posts: 7

Original Poster
Rep: Reputation: 0
thank you for your answer, but that seems not to work (or I am doing something wrong):

Code:
mail:/usr/lib/cgi-bin# ./mailgraph.cgi?n-0
bash: ./mailgraph.cgi?n-0: No such file or directory
mail:/usr/lib/cgi-bin# perl mailgraph.cgi?n-0
Can't open perl script "mailgraph.cgi?n-0": No such file or directory
mail:/usr/lib/cgi-bin#
 
Old 10-16-2008, 11:50 AM   #4
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
I would try:
PHP Code:
putenv('QUERY_STRING="0-n"');
echo 
system('/path/to/mailgraph.cgi'); 
or:
PHP Code:
echo system('export QUERY_STRING="0-n"; /path/to/mailgraph.cgi'); 
 
Old 10-16-2008, 01:22 PM   #5
extasic
LQ Newbie
 
Registered: Oct 2008
Posts: 7

Original Poster
Rep: Reputation: 0
that is what I tried first, but what happens if two users use this at the same time? the export will then be overwritten by the second, won't it?
 
Old 10-17-2008, 08:05 AM   #6
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
I don't think so, AFAIK the variables are exported to the same or child process but not to another process
 
Old 10-17-2008, 08:53 AM   #7
rglang
LQ Newbie
 
Registered: Apr 2008
Location: Chardon, Ohio
Distribution: RedHat Enterprise, Fedora
Posts: 2

Rep: Reputation: 0
When CGI scripts are executed from a Web server like Apache, each "instance" of the script is executed within the context of a newly-created shell. Each shell has its own environment, which will be unique from all other instances. Therefore, you have nothing to fear - multiple users will be properly handled.

The solution I presented will work as well - you have to escape the special meaning of the "?" character when you try to run your command at the prompt:

mail:/usr/lib/cgi-bin# ./mailgraph.cgi\?n-0

You cgi script will have to parse the argument string properly, but if you've been parsing GET input from web forms, the code should already be in place to do that.

Rich
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to call the modules and pass parameters to it? shendeswanand Linux - Software 1 12-31-2005 09:18 PM
How to pass on boot parameters Slack 10.1 tdking19 Slackware 3 03-21-2005 10:41 AM
Pass Parameters to php from bash iman00b Linux - Newbie 2 09-09-2004 05:30 PM
pass parameters to shell scripts ? qwijibow Linux - Newbie 2 08-07-2003 07:27 AM
howto pass parameters to modules Sammy2ooo Linux - Software 5 07-01-2003 08:30 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration