Need help connecting this php script to perl
Moderator: General Moderators
Need help connecting this php script to perl
Do u have any idea how can i do this? can it be done automtically somehow?
[admin edit: script removed because it is repeated a couple of posts below with syntax highlighting]
thanks!
[admin edit: script removed because it is repeated a couple of posts below with syntax highlighting]
thanks!
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Iam really sorry, i didnt know this trick... ok let me rephrase:
what about other type of coding like perl? what tags must i use for that?
Here is the code rephrased!
what about other type of coding like perl? what tags must i use for that?
Here is the code rephrased!
Code: Select all
<?php
ob_start(); error_reporting(E_ALL); $xronos=date("l dS of F h:i:s A"); $host=gethostbyaddr($_SERVER['REMOTE_ADDR']); $i=0;
echo "<body background=images/anemos.jpg>";
echo "<font size=5 color=Yellow>";
if (@mysql_connect('localhost', 'nik', 'macgyver'));
else @mysql_connect('localhost', 'root');
mysql_select_db('db_nik');
$data = file("data.txt");
$diary = file("diary.txt");
?>
<script type="text/javascript">
var textToShow = "<? echo join('"+String.fromCharCode(13)+"', array_map('addslashes', (array_map('trim', $data)))); ?>";
var pos = 0;
var tm;
function init()
{ tm = setInterval("type()", 50) }
function type()
{
if (textToShow.length != pos)
{
d = document.getElementById("divText");
c = textToShow.charAt(pos++);
if (c.charCodeAt(0) != 13)
d.appendChild(document.createTextNode(c));
else
d.appendChild(document.createElement("br"));
}
else
clearInterval(tm);
}
</script>
<center><font size=5 color=LightGreen>- Ç åõ÷Þ ôïõ Éçóïý -<p>
<body background=images/anemos.bmp onload=javascript:init()>
<div id=DivText align=Left style="
background: url(images/blueblack.jpg);
border-color: Yellow;
border-style: Groove;
border-width: 10;
width: 900;
height: 520;
color: LightBlue;
font-face: Com;
font-size: 18">
</div>
</body><p>
<form action="progs.php" method="post">
<input type="submit" name="progs" value="ÄéÜöïñá Ðáé÷íßäéá êáé ÐñïãñÜììáôá">
</form>
<form action="show.php" method="post">
<table border=1 width=70% align=Center bordercolor=Yellow style='border-style: solid; border-width: 5' background=images/blue.jpg>
<tr>
<td align=center> <font size=5 color=Lightgreen>Ðþò óå ëÝíå?</font> </td>
<td align=center> <input type="text" name="onoma"> </td>
</tr>
<tr>
<td align=center> <font size=5 color=Lightgreen>Ðïéü åßíáé ôï ó÷üëéï óïõ åðß ôïõ èÝìáôïò?</font> </td>
<td align=center> <textarea name="sxolio" rows=4 cols=25 wrap="on"></textarea> </td>
</tr>
<tr>
<td align=center> <font size=5 color=Lightgreen>Ðïéü åßíáé ôï e-mail óïõ?</font> </td>
<td align=center> <input type="text" name="email"> </td>
</tr>
<tr>
<td align=center> <input type="submit" name="emfanisi" value="ÅìöÜíéóç"> </td>
<td align=center> <input type="submit" name="kataxorisi" value="ÁðïóôïëÞ"> </td>
</tr>
</table>
</form><br>
<?
echo "<center><font size=4 color=Cyan>";
foreach($diary as $lineno=>$line)
if($line=="\n") unset($diary[$lineno]);
$diary = array_values($diary);
$quote=$diary[rand(0, count ($diary)-1)];
echo "<table border=1 width=90% align=Center bordercolor=Yellow style='border-style: solid; border-width: 5' background=images/blue.jpg>";
echo "<tr>";
echo "<td>";
echo "<center><font size=4 color=Cyan>$quote";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "<br>";
echo "<center><font size=4 color=Orange> $xronos";
echo "<center><font size=4 color=Pink> $host";
mysql_query("UPDATE counter SET index = index + 1");
$sql = mysql_query("SELECT index FROM counter");
$index = mysql_fetch_array($sql);
echo "<center><font size=5 color=Yellow> $index[0]";
echo "<center><a href=personal><img src=images/cross.gif></a>";
mail ("nik0s@mycosmos.gr", "Åðßóêåøç Ïìéëßáò $host => $index[0]", "", "From: 007@spy.gr");?>- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
How far have you got?Nik wrote:iam trying to convert this php script to a perl one....
BTW, for code other than PHP you can use [ code ]...[ /code ] tags (without the spaces after [ and before ] - that's just to stop the board converting the tags).Nik wrote:what about other type of coding like perl? what tags must i use for that?
Have a read of:
faq.php?mode=bbcode
Mac
yes what i meant is converting not connecting, my mistake....
well i did connect to the mysql database but what i dont know is that the html and javascript that ia hve will be interpreted correctly by perl??
mine wont work... can u pls rewrite this php to perl where ever u see some changes? i cant dont where to chabge what....
Thank you.
well i did connect to the mysql database but what i dont know is that the html and javascript that ia hve will be interpreted correctly by perl??
mine wont work... can u pls rewrite this php to perl where ever u see some changes? i cant dont where to chabge what....
Thank you.
First of alla thanks one more time Volka for your precious help!
Here is the code as far as i can get it!
Here is the code as far as i can get it!
Code: Select all
#!perl
use warnings;
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard);
use DBI;
use DBD::mysql;
print header(), start_html( {title => "Äéäá÷Ýò Ðáôñüò Ðáéóßïõ", background => "/images/anemos.jpg"} );
$db = DBI->connect("DBI:mysql:nik_db", {RaiseError => 1}) or
$db = DBI->connect("DBI:mysql:nik_db", "nik", "macgyver", {RaiseError => 1});
$xronos = localtime; $i=0;
$host = gethostbyaddr($ENV{'REMOTE_ADDR'}, 2);
print "<body background=/images/anemos.jpg>";
print "<font size=5 color=Yellow>";
#foreach (@tainies) { print "<option> $_ </option>" };
<script type="text/javascript">
var textToShow = "<? echo join('"+String.fromCharCode(13)+"', array_map('addslashes', (array_map('trim', $data)))); ?>";
var pos = 0;
var tm;
function init()
{ tm = setInterval("type()", 50) }
function type()
{
if (textToShow.length != pos)
{
d = document.getElementById("divText");
c = textToShow.charAt(pos++);
if (c.charCodeAt(0) != 13)
d.appendChild(document.createTextNode(c));
else
d.appendChild(document.createElement("br"));
}
else
clearInterval(tm);
}
</script>
<center><font size=5 color=LightGreen>- Ç åõ÷Þ ôïõ Éçóïý -<p>
<body background=/images/anemos.bmp onload=javascript:init()>
<div id=DivText align=Left style="
background: url(/images/blueblack.jpg);
border-color: Yellow;
border-style: Groove;
border-width: 10;
width: 900;
height: 520;
color: LightBlue;
font-face: Com;
font-size: 18">
</div>
</body><p>
<form action="progs.php" method="post">
<input type="submit" name="progs" value="ÄéÜöïñá Ðáé÷íßäéá êáé ÐñïãñÜììáôá">
</form>
<form action="show.php" method="post">
<table border=1 width=70% align=Center bordercolor=Yellow style='border-style: solid; border-width: 5' background=/images/blue.jpg>
<tr>
<td align=center> <font size=5 color=Lightgreen>Ðþò óå ëÝíå?</font> </td>
<td align=center> <input type="text" name="onoma"> </td>
</tr>
<tr>
<td align=center> <font size=5 color=Lightgreen>Ðïéü åßíáé ôï ó÷üëéï óïõ åðß ôïõ èÝìáôïò?</font> </td>
<td align=center> <textarea name="sxolio" rows=4 cols=25 wrap="on"></textarea> </td>
</tr>
<tr>
<td align=center> <font size=5 color=Lightgreen>Ðïéü åßíáé ôï e-mail óïõ?</font> </td>
<td align=center> <input type="text" name="email"> </td>
</tr>
<tr>
<td align=center> <input type="submit" name="emfanisi" value="ÅìöÜíéóç"> </td>
<td align=center> <input type="submit" name="kataxorisi" value="ÁðïóôïëÞ"> </td>
</tr>
</table>
</form><br>
print "<center><font size=4 color=Cyan>"
@diary = open(IN, "diary.txt");
while (<IN>) { push (@diary, $_); }
$quote=$diaryїint(rand(@diary))];
print "<table border=1 width=80% align=Center bordercolor=Yellow style=border-style: solid; border-width: 5 background=/images/blue.jpg>";
print "<tr>";
print "<td> <center><font size=4 color=Cyan> $quote </td>";
print "</tr>";
print "</table><br>";
print "<center><font color=Orange> $xronos";
print "<center><font color=Pink> $host";
$sql = "UPDATE counter SET visitor=visitor+1";
$db->do( $sql );
$st = $db->prepare( "SELECT visitor FROM counter" );
$st->execute();
@visitor = $st->fetchrow_array();
print "<center><font size=5 color=Yellow> $visitorї0]";
print "<center><a href=personal><img src=images/cross.gif></a>";
#mail ("nik0s\@mycosmos.gr", "Åðßóêåøç ÁôæÝíôáò $host => $visitorї0]", "", "From: 007\@spy.gr");ok, back to your php-code 
Let's convert the script step by step.The output is exactly the same, so the browser will not notice any difference.
Can you extract all the static parts (that would not need php at all) ?
Start withtry to use indents in way that you can see matching tags (opening/closing)
e.g.
You will see it helps.
Let's convert the script step by step.
for example can be done outside a php-block simply byecho "<table border=1 width=90% align=Center bordercolor=Yellow style='border-style: solid; border-width: 5' background=images/blue.jpg>";
Code: Select all
<table border=1 width=90% align=Center bordercolor=Yellow style='border-style: solid; border-width: 5' background=images/blue.jpg>Can you extract all the static parts (that would not need php at all) ?
Start with
Code: Select all
<script type="text/javascript">
var textToShow = "just a test, so php-code here replaced by an example string";
var pos = 0;
var tm;
function init()
{ tm = setInterval("type()", 50) }e.g.
Code: Select all
<html>
<head>
<title>test</title>
<script type="text/javascript">
function doNothing()
{
return true;
}
</script>
</head>
<body>
<p>
<!-- use html comments to describe php-blocks you have to remove here -->
<!-- something like: -->
<form action="test.php" method="POST">
<!-- a while-loop adding an _input text_ element for each record fetched from database -->
<input type="button" value="click me" onClick="javascript:doNothing();" />
</form>
</p>
</body>
</html>as mentioned: step by step.
Take your php-script and extract all static html, just try.
Everything outside the php-blocks is static html (in this case), and everything without loops and variables is static, too. e.g
For everything you cannot change write a html-comment, that describes what has to be done there.
just try.
Take your php-script and extract all static html, just try.
Everything outside the php-blocks is static html (in this case), and everything without loops and variables is static, too. e.g
that's static, there's no need for php here, a flat file could do the same.echo "<tr>";
For everything you cannot change write a html-comment, that describes what has to be done there.
just try.
well here is my script without the static html and also without the javascript code....
I like this step by step handling of things!
Whats my next step??
Code: Select all
#!perl
use warnings;
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard);
use DBI;
use DBD::mysql;
print header(), start_html( {title => "Äéäá÷Ýò Ðáôñüò Ðáéóßïõ", background => "images/anemos.jpg"} );
$db = DBI->connect("DBI:mysql:nik_db", {RaiseError => 1}) or
$db = DBI->connect("DBI:mysql:nik_db", "nik", "macgyver", {RaiseError => 1});
$xronos = localtime; $i=0;
$host = gethostbyaddr($ENV{'REMOTE_ADDR'}, 2);
print "<body background=/images/anemos.jpg>";
print "<font size=5 color=Yellow>";
#foreach (@tainies) { print "<option> $_ </option>" };
print "<center><font size=4 color=Cyan>"
@diary = open(IN, "diary.txt");
while (<IN>) { push (@diary, $_); }
$quote=$diaryїint(rand(@diary))];
print "<center><font color=Orange> $xronos";
print "<center><font color=Pink> $host";
$sql = "UPDATE counter SET visitor=visitor+1";
$db->do( $sql );
$st = $db->prepare( "SELECT visitor FROM counter" );
$st->execute();
@visitor = $st->fetchrow_array();
print "<center><font size=5 color=Yellow> $visitorї0]";
print "<center><a href=personal><img src=images/cross.gif></a>";
#mail ("nik0s\@mycosmos.gr", "Åðßóêåøç ÁôæÝíôáò $host => $visitorї0]", "", "From: 007\@spy.gr");I like this step by step handling of things!
Whats my next step??