Page 1 of 1

Problem with charset

Posted: Wed Apr 30, 2003 10:17 am
by Nik
in my localhost when i un my script i see greek, but when i upload my perl script to the remote server instead of seeing greek i see some weird characters instead

can anyonte tell me how to correct this?

Posted: Wed Apr 30, 2003 2:37 pm
by volka
probably you have to set a proper charset
http://www.w3.org/TR/REC-html40/charset.html#h-5.2.2

Posted: Thu May 01, 2003 6:11 am
by Nik
volka glad to see u r back man! how was your holdidays?

well, i managed finally to convert my php script to perl: here ir is:

Code: Select all

#!/usr/bin/perl 
use warnings; 
use CGI::Carp qw(fatalsToBrowser); 
use CGI qw(:standard);
use Socket; 
use DBI; 
use DBD::mysql; 

$xronos = localtime;  $i=0; 
$host = gethostbyaddr(inet_aton($ENV{REMOTE_ADDR}), AF_INET);

$db = DBI->connect("DBI:mysql:nik_db", {RaiseError => 1}) or 
$db = DBI->connect("DBI:mysql:nik_db", "nik", "macgyver", {RaiseError => 1}); 

print header(), start_html( {-title => "Didaxes Agion Pateron", -background => "http://localhost/images/anemos.jpg"} ); 

open(IN, "data.txt") || die $!; 
   @data = <IN>; 
close(IN); 

$data = join("", @data);
$data =~s/\n//g; 


#*******************************************************************************
print <<ENDOFHTML;
<html><head><title></title> 
<script type="text/javascript"> 
var textToShow = "$data"; 
var pos = 0; 
var tm; 

function init() 
&#123; tm = setInterval("type()", 50) &#125; 

function type() 
&#123; 
   if (textToShow.length != pos) 
   &#123; 
      d = document.getElementById("divText"); 
      c = textToShow.charAt(pos++); 
      if (c.charCodeAt(0) != 13) 
         d.appendChild(document.createTextNode(c)); 
      else 
         d.appendChild(document.createElement("br")); 
   &#125; 
   else 
      clearInterval(tm); 
&#125; 
</script> 

<center><font size=5 color=LightGreen>- H Euxi tou Ihsou -<br><br> 
<body background=images/anemos.jpg onload=javascript:init()> 
  <center> 
  <div id="DivText" align="Left" style=" 
    background: url(http://localhost/images/blueblack.jpg); 
    border-color: Yellow; 
    border-style: Groove; 
    border-width: 10; 
    width: 900; 
    height: 500; 
    color: LightBlue; 
    font-face: Com; 
    font-size: 19"> 
  </div> 
</body>
</html> 
ENDOFHTML
#*******************************************************************************

print start_form(), br();
print table( &#123;-border => 5, -align => "center", -background => "http://localhost/images/blue.jpg"&#125;, 
      Tr( th( h2( "Pos se lene file?" ),         th( textfield( "onoma" ) ) ) ), 
      Tr( th( h2( "Poio einai to sxolio sou?" ), th( textarea( -name => "sxolio", -rows => 4, -columns => 25 ) ) ) ), 
      Tr( th( h2( "Poio einai to e-mail sou?" ), th( textfield( "email" ) ) ) ),
	  Tr( th( submit( "Emfanisi" ),              th( submit( "Apostoli" ) ) ) ) );
print end_form(), br(); 

open(IN, "tips.txt") || die $!;
   @tips = <IN>;
close(IN);
$tips = $tips&#1111;int(rand(@tips))]; 

print table( &#123;-border => 5, -align => "center", -background => "http://localhost/images/blueblack.jpg"&#125;, 
      Tr( th( h4( &#123;-align => "center"&#125;, $tips ) ) ) ); 

$sql = "UPDATE counter SET visitor = visitor + 1"; 
$db->do( $sql ); 

$st = $db->prepare( "SELECT visitor FROM counter" ); 
$st->execute(); 
@visitor = $st->fetchrow_array(); 

print h3( &#123;-align => "center"&#125;, $xronos); 
print h3( &#123;-align => "center"&#125;, $host); 
print h3( &#123;-align => "center"&#125;, $visitor&#1111;0]);             

print a( &#123;href => "http://www.jokes.gr"&#125;, img &#123;src => "http://localhost/images/cross.gif"&#125; );
exec('mail nik0s@mycosmos.gr');
I have 3 problems now.... :)

a) i cant set the character set although i have found the correct one

b) in my localhost when i try from the browser to get http://localhost/index.pl it asks me if it should open the file intead of display it and

c) do i have correct tha mial syntax in my script?

Posted: Thu May 01, 2003 10:04 am
by daven
For your execution problem:

perl scripts should be in your CGI-bin directory. Even if they are not, you need to
a) make sure that the file has the proper permissions.
b) make sure that PERL can access/execute scripts in the proper directory

Posted: Thu May 01, 2003 10:07 am
by Nik
how can i make sure of b?

my index.pl its not any more in cg-bin
i have putted it in d:\web

what changes must i make to help perl undertand where i put it?

Posted: Thu May 01, 2003 6:59 pm
by volka
adding charset definition to the html-output: http://stein.cshl.org/WWW/software/CGI/#header

I can't remember: Do you have full control of the server in use or just a shared account, i.e. do you administer that box yourself?
If you do you should set up your webserver to handle your perl-files as scripts otherwise they are send as text/plain or application/occtet
http://perl.apache.org/docs/2.0/user/config/config.html tells you how to do so

Posted: Thu May 01, 2003 8:16 pm
by Nik
man pls give me a hand heer i ve trying for dayts for this and i cant meke tha DAMN thing work!!

here is my code so far, the one we were talking about.....

Code: Select all

#!/usr/bin/perl
use warnings; 
use CGI::Carp qw(fatalsToBrowser); 
use CGI qw(:standard);
use Socket;
use DBI; 
use DBD::mysql; 

$xronos = localtime;  $i=0; 
$host = gethostbyaddr(inet_aton($ENV&#123;REMOTE_ADDR&#125;), AF_INET);

$db = DBI->connect("DBI:mysql:nik_db", &#123;RaiseError=>1&#125;) or 
$db = DBI->connect("DBI:mysql:nik_db", "nik", "macgyver", &#123;RaiseError=>1&#125;); 

print header(), start_html( -lang=>'el', -title=>"Didaxes Agion Pateron", -background=>"http://localhost/images/anemos.jpg" );

open(IN, "data.txt") || die $!; 
   @data = <IN>; 
close(IN); 

$data = join("", @data);
$data =~s/\n//g; 


#*******************************************************************************
print <<ENDOFHTML;
<html><head><title></title>
<script type="text/javascript"> 
var textToShow = "$data"; 
var pos = 0; 
var tm; 

function init() 
&#123; tm = setInterval("type()", 50) &#125; 

function type() 
&#123; 
   if (textToShow.length != pos) 
   &#123; 
      d = document.getElementById("divText"); 
      c = textToShow.charAt(pos++); 
      if (c.charCodeAt(0) != 13) 
         d.appendChild(document.createTextNode(c)); 
      else 
         d.appendChild(document.createElement("br")); 
   &#125; 
   else 
      clearInterval(tm); 
&#125; 
</script> 

<center><font size=5 color=LightGreen>- H Euxi tou Ihsou -<br><br> 
<body background=images/anemos.jpg onload=javascript:init()> 
  <center> 
  <div id="DivText" align="Left" style=" 
    background: url(http://localhost/images/blueblack.jpg); 
    border-color: Yellow; 
    border-style: Groove; 
    border-width: 10; 
    width: 900; 
    height: 500; 
    color: LightBlue; 
    font-face: Com; 
    font-size: 19"> 
  </div> 
</body>
</html> 
ENDOFHTML
#*******************************************************************************

print start_form(), br();
print table( &#123;-border=>5, -align=>"center", -text=>"yellow", -background=>"http://localhost/images/brick.gif"&#125;, 
      Tr( th( p( "Pos se lene file?" ),         th( textfield( "onoma" ) ) ) ), 
      Tr( th( p( "Poio einai to sxolio sou?" ), th( textarea( -name=>"sxolio", -rows=>4, -columns=>25 ) ) ) ), 
      Tr( th( p( "Poio einai to e-mail sou?" ), th( textfield( "email" ) ) ) ),
	  Tr( th( submit( "Emfanisi" ),             th( submit( "Apostoli" ) ) ) ) );
print end_form(), br(); 

open(IN, "tips.txt") || die $!;
   @tips = <IN>;
close(IN);

@tips = grep &#123; !/^\s*\z/s &#125; @tips;
$tips = $tips&#1111;int(rand(@tips))];

print table( &#123;-border=>5, -align=>"center", -text=>"pink", -background=>"http://localhost/images/blue.jpg"&#125;, 
      Tr( th( p( &#123;-align=>"center"&#125;, $tips ) ) ) ); 

$sql = "UPDATE counter SET visitor = visitor + 1"; 
$db->do( $sql ); 

$st = $db->prepare( "SELECT visitor FROM counter" ); 
$st->execute(); 
@visitor = $st->fetchrow_array(); 

print h3( &#123;-align=>"center"&#125;, $xronos); 
print h3( &#123;-align=>"center"&#125;, $host); 
print h3( &#123;-align=>"center"&#125;, $visitor&#1111;0]);             
print  a( &#123;href=>"http://www.psyche.gr"&#125;, img &#123;src=>"http://localhost/images/cross.gif"&#125; );

#system("mail -s $host nik0s\@mycosmos.gr");
Pls make it to shwo greek and feel free to correct ig u see any mistake...


thanks one more time...
sometime docs dont help me....

Posted: Thu May 01, 2003 8:19 pm
by volka
print header(), start_html( -lang=>'el', -title=>"Didaxes Agion Pateron", -background=>"http://localhost/images/anemos.jpg" );
add the -charset parameter to header() as described in http://stein.cshl.org/WWW/software/CGI/#header

Posted: Thu May 01, 2003 8:27 pm
by Nik
yeap! now its wotking right....

all it was need ed was this

print header( -charset=>"iso-8859-7" ), start_html( -title=>"Didaxes Agion Pateron", -background=>"http://localhost/images/anemos.jpg" );

not even the -lang=>"el"


i cant beleive it......


now am having problems with javascript
it wont display the text inseide the blue box

check my website pls at

http://www.hostgreece.com/~nik/cgi-bin/index.pl

Posted: Thu May 01, 2003 9:06 pm
by volka
I don't think you can have multiline string literals in a javascript block like in php,e.g.

Code: Select all

<?php
$text = "Line1
Line2";
?>
try

Code: Select all

$data = join("", @data); 
$data =~s/\n/"+String.fromCharCode(13)+"/g;
$data =~s/\r//g;
instead

Posted: Fri May 02, 2003 9:07 pm
by Nik
actully i made it using this:

$data = join("", @data);
$data =~ s/\n//g;

it worked ok!