Go Back   CodingForums.com > :: Server side development > Perl/ CGI

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-10-2002, 09:03 PM   PM User | #1
technophobia
New to the CF scene

 
Join Date: Aug 2002
Location: PA
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
technophobia is an unknown quantity at this point
Sending a variable from one CGI file to another

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
__________________
-TECHNOPHOBIA-
technophobia is offline   Reply With Quote
Old 09-10-2002, 10:08 PM   PM User | #2
chrisvmarle
Regular Coder

 
Join Date: Jun 2002
Location: the Netherlands
Posts: 215
Thanks: 0
Thanked 0 Times in 0 Posts
chrisvmarle is an unknown quantity at this point
You could use cookies to store a var on the users computer. To send it to another program for example.

Mzzl, Chris
chrisvmarle is offline   Reply With Quote
Old 09-11-2002, 03:38 AM   PM User | #3
technophobia
New to the CF scene

 
Join Date: Aug 2002
Location: PA
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
technophobia is an unknown quantity at this point
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
__________________
-TECHNOPHOBIA-
technophobia is offline   Reply With Quote
Old 09-11-2002, 10:38 PM   PM User | #4
quantumpixel
New Coder

 
Join Date: Sep 2002
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
quantumpixel is an unknown quantity at this point
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 is offline   Reply With Quote
Old 09-11-2002, 10:39 PM   PM User | #5
quantumpixel
New Coder

 
Join Date: Sep 2002
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
quantumpixel is an unknown quantity at this point
i made some typos in the first line sorry


hope this could help !
quantumpixel is offline   Reply With Quote
Old 09-12-2002, 01:42 AM   PM User | #6
Inci
New Coder

 
Join Date: Aug 2002
Location: Moscow, RU
Posts: 23
Thanks: 0
Thanked 1 Time in 1 Post
Inci is an unknown quantity at this point
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.
Inci is offline   Reply With Quote
Old 09-14-2002, 06:39 PM   PM User | #7
idez
New to the CF scene

 
Join Date: Sep 2002
Location: Syracuse, NY
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
idez is an unknown quantity at this point
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.
idez is offline   Reply With Quote
Old 09-14-2002, 10:10 PM   PM User | #8
technophobia
New to the CF scene

 
Join Date: Aug 2002
Location: PA
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
technophobia is an unknown quantity at this point
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:

Code:
#!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
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...
__________________
-TECHNOPHOBIA-

Last edited by technophobia; 09-14-2002 at 10:15 PM..
technophobia is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:18 PM.


Advertisement
Log in to turn off these ads.