hardcoded paths

2005-10-28 Thread Dermot Paikkos
Hi,

I am moving a site from once host to another. There are lots of 
hardcoded fully qualified paths to the localhost (EG 
http://myserver/cgi-bin/someprog.pl?name=val  
http://myserver/css/mystyle.css).

I am pretty sure this isn't good practise but I am not a bit lost as 
to what are good alternatives. I don't want to make the same mistake 
and have to do all this editing again next time the hardware changes.

Should I be trying to create a module with these paths in? Or is 
there some other way?
Thanx.
Dp.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: hardcoded paths

2005-10-28 Thread David Dorward
On Fri, Oct 28, 2005 at 10:28:20AM +0100, Dermot Paikkos wrote:

 I am moving a site from once host to another. There are lots of 
 hardcoded fully qualified paths to the localhost

 I am pretty sure this isn't good practise but I am not a bit lost as 
 to what are good alternatives.

Relative URLs?

-- 
David Dorward  http://dorward.me.uk


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




CGI Upload() for nonexistent files?

2005-10-28 Thread Joby Jones
Hello all,
  I have a question about the CGI upload()
function.

  Why does it return a valid file handle to a file
that does not exist on the client (web browser)
machine, and what's the best way to handle this?


Details:


1. A user enters a nonexistent file name in an upload
field in a form handled by my cgi script. (E.g. on
windows c:\uplaodthis.txt -- note typo). 
   
2. My cgi script does something like this:

my $q = new CGI;
if(defined($q-param('Upload'))){
my $upload_file_handle = 
   $q-upload('upload_file');
if(defined($upload_file_handle)){
   print Valid file handle to empty file is:\n .

  Dumper($upload_file);
}
}


3. It outputs: 
Valid file handle ... 
 $VAR1 = bless( \*{FH::uplaodthis.txt ...}, 'Fh' );



What to do?
---

Currently, I write out all valid file handles (checked
for basic security problems as described in perlsec). 
If the file is zero length, I delete it and report an
error.  Which just isn't very satisfying.

What am I missing?
Is there a better way?



All advice and documentation pointers (beyond 'CGI'
:-) appreciated.

Thanks,
joby



__ 
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: hardcoded paths

2005-10-28 Thread Wiggins d'Anconia
Dermot Paikkos wrote:
 Hi,
 
 I am moving a site from once host to another. There are lots of 
 hardcoded fully qualified paths to the localhost (EG 
 http://myserver/cgi-bin/someprog.pl?name=val  
 http://myserver/css/mystyle.css).
 
 I am pretty sure this isn't good practise but I am not a bit lost as 
 to what are good alternatives. I don't want to make the same mistake 
 and have to do all this editing again next time the hardware changes.
 
 Should I be trying to create a module with these paths in? Or is 
 there some other way?
 Thanx.
 Dp.
 
 

Relative URLs as David mentioned would be good whereever they can be
used. The other option I use is to create a Setup.pm module that
contains constants for these things.

use constant CONFIG_URL_BASE = 'http://yoursite.com';
use constant CONFIG_URL_CGI_BASE = 'http://yoursite.com/cgi-bin';

Then you need to export those constants into the calling code. The only
bummer about using constants is that they don't interpolate inside
strings, but I have settled on using concatenation and prefer to have
the extra overhead to have the ease of changing all URLs on a site at once.

This also makes module code that generates links reusable across sites.

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: CGI Upload() for nonexistent files?

2005-10-28 Thread Wiggins d'Anconia
Joby Jones wrote:
 Hello all,
   I have a question about the CGI upload()
 function.
 
   Why does it return a valid file handle to a file
 that does not exist on the client (web browser)
 machine, and what's the best way to handle this?
 

Presumably because this is really a client side error. It is not an
error to upload a zero length file, a file could need to be created but
empty, and you could want to have a program do that. So it is not
unreasonable to think that a file upload could be empty, which means CGI
has to handle the case where a file is uploaded but empty.  Chances are
good the browser is creating the proper HTTP request despite the local
file not existing, but to me that is a browser fault.  CGI just sees the
header that says there is a file coming, then no data so it creates the
file, puts nothing in it, and happily crunches along.

 
 Details:
 
 
 1. A user enters a nonexistent file name in an upload
 field in a form handled by my cgi script. (E.g. on
 windows c:\uplaodthis.txt -- note typo). 

 2. My cgi script does something like this:
 
 my $q = new CGI;
 if(defined($q-param('Upload'))){
 my $upload_file_handle = 
$q-upload('upload_file');
 if(defined($upload_file_handle)){
print Valid file handle to empty file is:\n .
 
   Dumper($upload_file);
 }
 }
 
 
 3. It outputs: 
 Valid file handle ... 
  $VAR1 = bless( \*{FH::uplaodthis.txt ...}, 'Fh' );
 
 
 
 What to do?
 ---
 
 Currently, I write out all valid file handles (checked
 for basic security problems as described in perlsec). 
 If the file is zero length, I delete it and report an
 error.  Which just isn't very satisfying.
 

Why is it not satisfying? It is a requirement of yours that the file not
be empty NOT the CGI world at large, so this is an error you should be
handling. Sounds like you are doing a fine job.

 What am I missing?
 Is there a better way?

Doubtful. You could write a web server module to handle the case at the
front end of the request but the only thing that really saves is a
little processing time, you still have a server side error to throw.

 
 
 
 All advice and documentation pointers (beyond 'CGI'
 :-) appreciated.


I say move on and work on bigger problems. Faulty user input, is well
the fault of the user. Let them deal with the consequences of having to
resubmit the form, assuming your error message is clear.

http://danconia.org


 Thanks,
 joby
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Taking Multiple Values for The Same Form Field.

2005-10-28 Thread Sara
Never thought of it before, but now I need help as how to pass multiple values 
of a form field with a single submit to script.

** example **

form

!-- Name is a required Field, but E-mail could be left blank --

!--- First Input --
input type=text name=name
input type=text name=email

!-- Second Input --
input type=text name=name
input type=text name=email

!-- Third Input --
input type=text name=name
input type=text name=email

input type=submit value=Submit

/form



use CGI;
my $q = new CGI;

my $name = $q-param('name');

Now What as multiple name values will be coming.??


Thanks for any help.

Sara.

Re: Taking Multiple Values for The Same Form Field.

2005-10-28 Thread Ovid
--- Sara [EMAIL PROTECTED] wrote:

 
 use CGI;
 my $q = new CGI;
 
 my $name = $q-param('name');
 
 Now What as multiple name values will be coming.??

Use list context:

  my @names = $q-param('name');

Cheers,
Ovid

-- 
If this message is a response to a question on a mailing list, please send
follow up questions to the list.

Web Programming with Perl -- http://users.easystreet.com/ovid/cgi_course/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Taking Multiple Values for The Same Form Field.

2005-10-28 Thread Sara
Thanks for the quick respons, just need a bit more help. Now I need to write 
these values in a text file (I am fully aware of writing to files) but where 
I am gettin' confused is that : I told you that Name is a required field, 
but Email is optional. so what if :


my @name = ('Sara', 'John', 'Doe'); # 3 names coming from form.
my @email = ('[EMAIL PROTECTED]'); # coming from form as Email Optional field is 
ONLY filled for John.


The problem is $name[0] does not corresponds with $email[0] and so on 
Otherwise I would have used while or foreach for @name and @email to write 
it to file like it:


### TEXT FILE TO WRITE ###
Sara |
John | [EMAIL PROTECTED]
Doe |
##

Thanks again for your help.

Sara.



- Original Message - 
From: Ovid [EMAIL PROTECTED]

To: beginners-cgi@perl.org
Sent: Saturday, October 29, 2005 9:14 AM
Subject: Re: Taking Multiple Values for The Same Form Field.



--- Sara [EMAIL PROTECTED] wrote:



use CGI;
my $q = new CGI;

my $name = $q-param('name');

Now What as multiple name values will be coming.??


Use list context:

 my @names = $q-param('name');

Cheers,
Ovid

--
If this message is a response to a question on a mailing list, please send
follow up questions to the list.

Web Programming with Perl -- http://users.easystreet.com/ovid/cgi_course/

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response