...

View Full Version : Sending a variable from one CGI file to another



technophobia
09-10-2002, 10:03 PM
how would i take a variable from one file and send it to another file. Is there some type of memory that i can store it in and then get another program to call it?

Basicaly all i want to do is get a user name which was inputed through one cgi file and stored into a variable and send that user name to another file.

Thankyou


here is where it leads to:

#!c:/perl/bin/perl.exe
#START
#
#-----------LOGIN_SCRIPT_FOR_NEWS--------------
#
# created by Mark Y. (DRT_Phobia)
#
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
my $theplace='addcontent.cgi';#the place that gets $user
my ($user,$pw,$reg);
my %drts='phobia'=>'mark','matt'=>'matt',
'loc'=>'loc','twistedlady'=>'twistedlady');
$user=param('user');
$pw=param('pass');
$reg=$drts{$user};
#
if (($pw eq '') || ($user eq '')){
print "Content-type: text/html\n\n";
print "<html><body>";
print "missing user name (and) or password";
}elsif ($pw eq $reg) {
print "Content-type: text/html\n\n";
print "<html><body>";
print "Logged on! <b>$user</b><br><br>";
#<----
print "<form action=$theplace method=post>";
print "<input type=submit value=Continue>";
print "</form>";

}else {
print "Content-type: text/html\n\n";
print "<html><body>";
print "deneyed $user";
}print "</body></html>";
#END

chrisvmarle
09-10-2002, 11:08 PM
You could use cookies to store a var on the users computer. To send it to another program for example.

Mzzl, Chris

technophobia
09-11-2002, 04:38 AM
i never thought of that. ill try it, but going into cookies just for one little variable :(

i did try a txt file too. I just want to fine the shortest way possible. There just has to be some kind of way to make a variable global from one CGI program to another...


ty Chris

quantumpixel
09-11-2002, 11:38 PM
im new to this but i just though of a crazy idea...

u can create a lib file where u can have a sub with the desire variable...

and everytime u want to rewrite it... do the following...

open FILE <open(FILE, ">Global_Var.lib");

print FILE 'sub DUNNO {';
print FILE '$Var = ';
print FILE "$Var_On_Script";
print FILE ' } \n';

close(FILE);

quantumpixel
09-11-2002, 11:39 PM
i made some typos in the first line sorry :o


hope this could help ! :thumbsup:

Inci
09-12-2002, 02:42 AM
Hello,

Well, You have two ways: you can create the file and write your variable into it or open a socket and send the variable to your other script (but it must be hosted on server) by get method.

thats it.

idez
09-14-2002, 07:39 PM
Well, not sure but is there any reason, you don't URL encode it? You are just passing the name right?

just add the variable to the end of the call to your other CGI

cgi-bin/blah.pl?Name=SomeYahoo

Then use

if ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
} else {
$buffer = $ENV{'QUERY_STRING'};

$buffer is whatever you posted. Sounds like some work, but no more than creating a file to hang around.


R.

technophobia
09-14-2002, 11:10 PM
i started playing with is before, but then i got lost and started to look for an alternative. ill just post the thing i made:



#!c:/perl/bin/perl.exe
#START
#----------------------------------------------------------------------------------
#-----------ADD_CONTENT_SCRIPT_FOR_NEWS--------------
#----------------------------------------------------------------------------------
# created by Mark Y. (DRT_Phobia) and some people
#
#--------------INCLUDES------------------------------------------------------
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
#--//----------------------------------------------------------------------------//
#
#--------------VARIABLES-----------------------------------------------------
my $user;
my $servernews='../docs/cs_news.html';
my $internetnews='http://localhost/cs_news.html';
my ($name,$value,$aline,$buffer,@alinesotxt);
my ($sec,$min,$hour,$mday,$mon,$year_off,$junkus,$atop,$year,$min2);
my ($subject,$content,$update_info);
#--//----------------------------------------------------------------------------//
#
#
#--------get the user name from the login.cgi------GET_USER_NAME
if ($ENV{'REQUEST_METHOD'} eq 'POST') { # <--idez
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); #should be name=phobia <--idez
chomp $buffer; # <--me
($name,$user)=split(/=/,$buffer); #$name=user,$value=phobia<--me
} else { # <--idez
$user=$ENV{'QUERY_STRING'};} # <----idez
#----------------------------------------------------------/GET_USER_NAME
#
#
#--------Time-formating-----------------------------------TIME_FORMAT
($sec,$min,$hour,$mday,$mon,$year_off,$junkus,$junkus,$junkus)=localtime;
#
$year=($year_off+1900);
#
if ($hour>12){
$atop='PM';
$hour=($hour)-12;
}else{
$atop='AM';}
#
if ($min<10){$min2='0';}
#
#----------------------------------------------------/TIME_FORMAT
#
#print "Content-type: text/html\n\n";
#print "<html><body>";
#print "</body></html>";
#
#
# ---------------------title-and-post-input-area--------------GET_POST
print "Content-type: text/html\n\n";
print "<html><body>";
print "$user $buffer";
print "
<br><br><br>$user $buffer<br>
<form action=$ method=post>
Title:<input type=text name=subject size=40
maxlength=40><br><br>
Post Information:<br><textarea name=content cols=65
rows=5 wrap></textarea><br><br><br>
<input type=submit value=submit><input type=reset value=reset>
</form>
";
print "</body></html>";
exit;
#-----------------------------------------------------------/GET_POST
#
#
#
#
#-----take form input of form and sort the string given--FIND_VAR
read(STDIN,$buffer,$ENV{'CONTENT_LENGTH'});
@alinesotxt=split(/&/,$buffer);
foreach $aline(@alinesotxt){
($name,$value)=split(/=/,$aline); #
$value=~tr/+/ /; //#takes out '+' which is a space and replaces it with a space
$value=~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
$value=~s/<\!\-\-\.*\-\->//g; #takes out commnets
$in{$name}=$value;
}
#------------------------------------------------------------/FIND_VAR
#
#---------open the html file and write to it-----------------------WRITE
# ---------------------> !!!! im not done this part yet !!!!
if(/<!--NEWSHERE-->/){
print NEWS"
<table border=0>
<TR>
<TD bgcolor=990000 WIDTH=25%>
$mon-$mday-$year $hour:$min2$min$atop</TD>
<TD bgcolor=990000 WIDTH=65%>
$in{'subject'}</TD>
<TD bgcolor=333333 WIDTH=10%>
$user</TD>
<TR/>
<TR><TD colspan=3>
$in{'content'}
</TD><TR/>
<hr color=black width=498>
</table>";
}
#------------------------------------------------------------/WRITE
#
#
#END



im just stuck :confused:
for some reason its not sorting the user name from the file before this one.

it gets this-

htp://localhost/cgi-bin/addcontent.cgi?name=phobia

i tryed to print it but that didnt work so i guess i gets nothing...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum