Current location: Hot Scripts Forums » Programming Languages » Perl » translating from cgi to php


translating from cgi to php

Reply
  #1 (permalink)  
Old 07-04-08, 04:17 AM
theighost theighost is offline
Newbie Coder
 
Join Date: Jul 2008
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
translating from cgi to php

hi,i am suppose to translate a text of cgi into php...i know little php and don't know perl at all, so any advices.

lets start of what the function param() does?????

and what does this code do: $num = $q->param('num');
$keyword = $q->param('keyword');
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-06-08, 10:22 PM
chaosprime's Avatar
chaosprime chaosprime is offline
Newbie Coder
 
Join Date: Jun 2008
Location: New Jersey
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
$q->param() is a method on a CGI object that retrieves a query parameter. The equivalent of $q->param('foo') in PHP is $_REQUEST['foo'].
__________________
Chaos
Lost Souls: text based RPG
MUDseek: MUD search
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-07-08, 12:55 AM
curbview.com's Avatar
curbview.com curbview.com is offline
Junior Code Guru
 
Join Date: May 2006
Posts: 555
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by chaosprime View Post
$q->param() is a method on a CGI object that retrieves a query parameter. The equivalent of $q->param('foo') in PHP is $_REQUEST['foo'].
IN PERL IT'S:

Code:
$q->param('foo')  

TRANSLATION 

$q = $FORM{'NAME'}
HERE IS AN EXAMPLE WRITTEN IN PERL not PHP


Code:
How to Use a Form Data in Perl

This page shows how to send information from a web page form to a perl script.
The Form

Create a standard HTML form with the input values you wish to pass to the script. For example:

<form name="myForm" method="post" action="myScript.cgi">
<input type="text" name="textfield">
<input type="hidden" name="hiddenfield" value="Secret Text">
<input type="submit" name="subbtn" value="Submit">
</form>

The Script Code

In the perl script, use a block of code like the one below to extract the form data. The comments are included to show you what is happening - you can safely remove them.

# Read the standard input (sent by the form):
read(STDIN, $FormData, $ENV{'CONTENT_LENGTH'});
# Get the name and value for each form input:
@pairs = split(/&/, $FormData);
# Then for each name/value pair....
foreach $pair (@pairs) {
	# Separate the name and value:
	($name, $value) = split(/=/, $pair);
	# Convert + signs to spaces:
	$value =~ tr/+/ /;
	# Convert hex pairs (%HH) to ASCII characters:
	$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
	# Store values in a hash called %FORM:
	$FORM{$name} = $value;
}

The form's input values can now be used with a key like so: $FORM{'inputname'} , where 'inputname' is the name of the form input item. For example:

print "The following text was entered in the e text field: $FORM{'textfield'}";
print "The hidden text is: $FORM{'hiddenfield'}";
__________________
Whatever you decide, you should make sure best security methods are used and practiced. Should you really need more help, PM me.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 07-07-08, 03:04 AM
theighost theighost is offline
Newbie Coder
 
Join Date: Jul 2008
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
thnx guys!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 07-07-08, 03:33 AM
theighost theighost is offline
Newbie Coder
 
Join Date: Jul 2008
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
could someone plz tell me what this function exactly does???
Code:
sub get_file_contents{
my ($filename) = @_;
my ($filesize, $filesize, $thefile);

if ((-e "$filename") > 0) 
	{
$filesize = (-s "$filename");
open (TFILECNTS, "$filename") || die "$filename";
	read(TFILECNTS,$thefile,$filesize);
close (TFILECNTS);
	}

return ($thefile);

}

Last edited by Nico; 07-07-08 at 03:46 AM. Reason: Wrappers.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 07-07-08, 05:33 AM
curbview.com's Avatar
curbview.com curbview.com is offline
Junior Code Guru
 
Join Date: May 2006
Posts: 555
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by theighost View Post
could someone plz tell me what this function exactly does???
Code:
sub get_file_contents{ 
my ($filename) = @_; # Accepts the data sent to it
my ($filesize, $filesize, $thefile); # declares three variables to be used later
if ((-e "$filename") > 0) # Checks to see if a file exists.
	{
$filesize = (-s "$filename");# checks the size of a file
open (TFILECNTS, "$filename") || die "$filename"; #opens the file for reading
	read(TFILECNTS,$thefile,$filesize); #reads the file
close (TFILECNTS); # closes the file
	}

return ($thefile); returns what it read.

}
Look at the comments for answers (it's inside the quoted code you posted above). To be honest, you should read more about perl as translating it is not the purpose of this forum. Glad to help though.
__________________
Whatever you decide, you should make sure best security methods are used and practiced. Should you really need more help, PM me.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
2 profitable script sites for sale cms-master.com General Advertisements 3 07-03-07 11:17 AM
Help installing php as cgi djhlhn PHP 2 12-04-06 12:04 PM
HTML, CGI, Perl, PHP service offer sujata_ghosh Job Offers & Assistance 0 09-06-06 01:25 PM


All times are GMT -5. The time now is 12:14 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.