Visualizzazione risultati 1 fino 3 di 3

Discussione: Passaggio da php4 a php5, non funziona lo script

  1. #1
    Guest

    Predefinito Passaggio da php4 a php5, non funziona lo script

    Salve ho un problema su uno script php che funziona perfettamente sul supporto php4, ma non funziona sul php5.
    Siccome avrei necessità di trasferire lo script sul php5, ve lo posto per vedere se qualcuno saprebbe dirmi dove devo aggiornare...
    si tratta di un form per sondaggi con pagina di amministrazione.

    pagina admin.php con password di accesso
    Codice PHP:
    <?php


    $password
    ="admin";


    //#########################################################
    if(!isset($passwd) or $passwd!=$password){
    echo
    "<table width=\"303\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\" height=\"169\" bgcolor=\"#336699\" align=\"center\"><tr><td bgcolor=\"#336699\" height=\"110\">
    <table width=\"311\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\" bgcolor=\"#FFFFFF\" height=\"136\">
    <tr><td height=\"175\"><div align=\"center\"><font face=\"Verdana, Arial, Helvetica, sans-serif\"><b><font size=\"2\">Entra con la tua password d'amministrazione</font></b></font><br>
    </div><form name=\"form1\" method=\"post\" action=\"
    $PHP_SELF\"><div align=\"center\">
    <input type=\"password\" name=\"passwd\"><br><input type=\"submit\" name=\"Submit\" value=\"Login\">
    </div></form></td></tr></table></td></tr></table>"
    ;

    }elseif (
    $passwd==$password){
    if (isset(
    $submit)){
    $fp=fopen($datafile, "w");
    fputs($fp, $question."\n");
    for(
    $i=1; $i <=10; $i++){
    if(
    $answer[$i]==""){ break;}
    $input=$answer[$i]."][".$image[$i]."][".$votes[$i]."\n";
    fputs($fp, $input);
    }
    fclose($fp);
    $config="<?php\n";
    $config.="\$textcolor='$textcolor';\n";
    $config.="\$linkcolor='#FFFFFF';\n";
    $config.="\$bgcolor='$bgcolor';\n";
    $config.="\$tableborder='$tableborder';\n";
    $config.="\$timeout='$timeout';\n";
    $config.="\$ip_file='$ip_file';\n";
    $config.="\$font='$font';\n";
    $config.="\$fontsize='$fontsize';\n";
    $config.="\$datafile='$datafile';\n";
    $config.="?>";
    $fp=fopen($ip_file, "w");
    fclose($fp);
    $fp=fopen("config.php", "w");
    fputs($fp, $config);
    fclose($fp);
    echo
    "<div align=\"center\"><b><font face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"#00CC00\">Your
    settings have been updated!</font></b></div>"
    ;
    }

    include(
    'config.php');
    $data=file($datafile);
    $nb=count($data);
    ?>
    <html>
    <head>
    <title>APP (Another PHP Poll)</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body bgcolor="#FFFFFF" text="#000000" link="#FFFFFF" vlink="#CCCCCC" alink="#CCCCCC">
    <table width="760" border="0" cellspacing="1" cellpadding="0" align="center" height="566">
    <tr>
    <td bgcolor="#336699" height="6"><font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="#FFFFFF"><b>APP</b><font size="1">
    (Another PHP Poll) by Tom Kohnen ( <a href="http://www.tkohnen.com">www.tkohnen.com</a>
    )</font></font></td>
    </tr>
    <tr>
    <td bgcolor="#336699" height="221">
    <table width="768" border="0" cellspacing="1" cellpadding="5" height="634">
    <tr>
    <td bgcolor="#EEEDEA" height="463" valign="top">
    <form name="APP" method="post" action="">
    <p><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b><i>Impostazioni:</i></b><br>
    <br>
    </font></p>
    <table width="753" border="0" cellspacing="1" cellpadding="3" height="396" align="center">
    <tr>
    <td width="116" height="15"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Domanda</b></font></td>
    <td colspan="3" height="15"> <font face="Verdana, Arial, Helvetica, sans-serif" size="2">
    <input type="text" name="question" size="100" maxlength="150" value="<?php echo $data[0]; ?>">
    </font></td>
    </tr>
    <tr>
    <td colspan="4" height="10">&nbsp;</td>
    </tr>
    <tr>
    <td colspan="4"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Qui potrai inserire le opzioni che gli utenti potranno scegliere di votare, le prime <b>2</b> devono essere compilate, le altre se non necessarie possono rimanere in bianco!</font></td>
    </tr>
    <tr>
    <td width="116">&nbsp;</td>
    <td width="246">
    <div align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Risposta</b></font></div>
    </td>
    <td width="181">
    <div align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>File immagine</b></font></div>
    </td>
    <td>
    <div align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>Voti</b></font></div>
    </td>
    <?
    for($i=1; $i<=10; $i++){
    $subdata=explode("][",$data[$i]);

    echo
    "<tr><td width=\"116\">
    <font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"2\"><b>Opzione
    $i</b></font></td>
    <td width=\"246\">
    <div align=\"center\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"2\">
    <input type=\"text\" name=\"answer[
    $i]\" size=\"40\" maxlength=\"40\" value=\"$subdata[0]\"></font></div>
    </td><td width=\"181\">
    <div align=\"center\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"2\" >
    <input type=\"text\" name=\"image[
    $i]\" size=\"25\" maxlength=\"50\" value=\"$subdata[1]\">
    </font></div></td><td width=\"181\">
    <div align=\"center\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"2\">
    <input type=\"text\" name=\"votes[
    $i]\" size=\"4\" maxlength=\"4\" value=\"$subdata[2]\">
    </font></div></td></tr>"
    ;
    }
    ?>
    pagina voto.php relativa al sondaggio

    Codice PHP:
    <?php
    function head() {
    include(
    'config.php');
    echo
    "<table width=\"207\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\">
    <tr><td bgcolor=\"
    $tableborder\">
    <table width=\"198\" border=\"0\" cellpadding=\"0\" cellspacing=\"\" align=\"center\">
    <tr><td bgcolor=\"
    $bgcolor\">";
    }
    function
    foot () {
    echo
    "</td></tr></table></td></tr></table>";
    }
    function
    record($REMOTE_ADDR) {
    include(
    'config.php');
    $fp=fopen("$ip_file", "a+");
    fputs ($fp,$REMOTE_ADDR."][".time()."\n");
    fclose($fp);
    }
    function
    check($REMOTE_ADDR) {
    include(
    'config.php');
    global
    $valid;
    $ip=$REMOTE_ADDR;
    $data=file("$ip_file");
    $now=time();
    foreach (
    $data as $record) {
    $subdata=explode("][",$record);
    if (
    $now < ($subdata[1]+3600*$timeout)) {
    if (
    $ip == $subdata[0]) {
    $valid=0;
    break;
    }}}}
    //##################### Save data ##############################
    function save($answer){
    global
    $answer;
    include(
    'config.php');
    $data=file($datafile);
    $subdata=explode("][",$data[$answer]);
    $subdata[2]+=1;
    $data[$answer]=implode("][", $subdata);
    $data[$answer]=$data[$answer]."\n";
    $fp=fopen($datafile,"w+");
    $a=0;
    do{
    fputs($fp,$data[$a]);
    $a++;
    }while(
    $a<count($data));
    fclose($fp);
    }
    //########################## Show Form ############################
    function form($PHP_SELF){
    include(
    'config.php');
    head();
    echo
    "<font size=\"$fontsize\" face=\"$font\" color=\"$textcolor\"><form method=\"post\" action=\"$PHP_SELF\"><p align=\"center\">";
    $data=file($datafile);
    $question=$data[0];
    $nb_options=count($data)-1;
    echo
    "<b>$question</b></p>";
    for(
    $nb=1;$nb <= $nb_options; $nb++){
    $option=explode("][","$data[$nb]");
    echo
    "<input type=\"radio\" name=\"answer\" value=\"$nb\"> ";
    echo
    "$option[0]<br>";
    }
    echo
    "<input type=\"hidden\" name=\"save\" value=\"yes\">";
    echo
    "<p align=\"center\"><input type=\"submit\" name=\"Submit\" value=\"Vota\"></form></font>";
    echo
    "<font size=\"$fontsize\" face=\"$font\" color=\"$textcolor\"><a href=\""; echo $PHP_SELF; echo "?action=results\"><input type=\"submit\" value=\"Guarda i risultati\"></font></p>";
    foot();
    }
    //################## Function to show results ########################
    function results(){
    include(
    'config.php');
    head();
    $data=file($datafile);
    $nb_answers=count($data);
    $votes=0;
    $a=1;
    do{
    $subdata=explode("][",$data[$a]);
    $votes += $subdata[2];
    $a++;
    }while(
    $a < $nb_answers);
    $a=1;
    $b="answerv";
    $v=100/$votes;
    echo
    "<p align=\"center\"><font size=\"$fontsize\" face=\"$font\" color=\"$textcolor\"><b>$data[0] ($votes votanti)</b><br><br>";
    do{
    $subdata=explode("][",$data[$a]);
    $av = $subdata[2] * $v;
    echo
    "<font size=\"$fontsize\" face=\"$font\" color=\"$textcolor\">$subdata[0] -"; printf(" %01.1f", $av); echo"%<br>";
    $p2v = 100-$av;
    echo
    "<img src=\"$subdata[1]\" width=\"$av\" height=\"10\"><img src=\"$image\" width=\"$p2v\" height=\"10\"><br>";
    $a++;
    } while (
    $a < $nb_answers);
    echo
    "<br>";
    foot();
    }
    //###################### Engine ####################################
    check($REMOTE_ADDR);
    if (
    $valid=="0"){ results();}
    elseif (
    $action=="results") { results(); }
    elseif (
    $save=="yes" && $valid!="0") { save($Answer); record($REMOTE_ADDR); results();}
    elseif (
    $action=="save" && !empty($valid)) { results(); }
    elseif (
    $action!="save" && $valid!="0"){ form($PHP_SELF); }
    ?>

  2. #2
    L'avatar di andreafallico
    andreafallico non è connesso Super Moderatore
    Data registrazione
    02-06-2009
    Messaggi
    1,981

    Predefinito

    Ricevi qualche errore?
    Register Globals è attivato o disattivato?

  3. #3
    Guest

    Predefinito

    non ricevo errori, solo che quando clicco "invia" non fà nessuna azione.
    Il register globals è attivato, ho provato a disattivarlo ma è uguale

Regole di scrittura

  • Non puoi creare nuove discussioni
  • Non puoi rispondere ai messaggi
  • Non puoi inserire allegati.
  • Non puoi modificare i tuoi messaggi
  •