- Home
- Categorie
- Coding e Sistemistica
- Coding
- Sondaggio
-
Sondaggio
Ciao a tutti, ho scaricato lo scipt simplepoll ma non riesco ad inserirlo nel mio sito, non so quale sia il tag per farlo comparire al interno del sito, vi posto il file poll.php
<?php
include("settings.inc.php");
if (isset($mode)) {
switch ($mode) {
// If user voted, process their vote:
case "vote":
if (isset($vote)) {
$vote_allow = 1;
$file_contents = file($current_poll);
if (((isset($vote_logging))) && (($vote_logging == 1) || ($vote_logging == 3))) {
foreach ($file_contents as $line) {
if (eregi($REMOTE_ADDR, $line)) {
echo $already_voted;
display_form();
$set_already_voted = 1;
$vote_allow = 0;
break;
}
}
}
if (((isset($vote_logging))) && (($vote_logging == 2) || ($vote_logging == 3))) {
if ((isset($voted)) && ($voted == "on")) {
if (!$set_already_voted) {
echo $already_voted;
display_form();
}
$vote_allow = 0;
break;
}
}
if ($vote_allow) {
$poll_string = $vote . "|" . $REMOTE_ADDR . "\n";
$fp = fopen($current_poll, "a");
$string_size = strlen($poll_string);
if (fputs($fp, $poll_string, $string_size)) {
if (((isset($vote_logging))) && (($vote_logging == 2) || ($vote_logging == 3))) {
setcookie ("voted", "on", time()+$time_toban);
}
echo $vote_cast . "
";
display_form();
}
fclose($fp);
}
}
break;
// If user asked to show results, display results:
case "results":
$poll_contents = file($current_poll);
// How many total votes we have;
$total_votes = sizeof($poll_contents);
$answers = file($config);
if ($total_votes == 0) {
echo $no_votes_yet;
display_form();
}
else {
echo "Ratings:
";
$size_answers = sizeof($answers) - 1;
$votes = 0;
for ($current_number = 1; $current_number <= $size_answers; $current_number++) {
foreach ($poll_contents as $line) {
$line_parts = explode("|", $line);
if ($line_parts[0] == $current_number) {
$votes[$current_number]++;
}
}
$percentage = $votes[$current_number]/$total_votes*100;
$graph_width = 2 * $votes[$current_number];
echo "<img src=tick.gif height=10 width=" . $graph_width . ">" . round($percentage, 2) . " %" . $answers[$current_number] . ": " . $votes[$current_number]/1 . " votes.
";
}
echo "Total votes: " . $total_votes;
}
break;case "previous": $file_contents = file($archive_poll); if (sizeof($file_contents) == 0) { echo $no_previous; display_form(); } else { for ($i=0;$i<sizeof($file_contents);$i++) { $each_poll = explode("|", $file_contents*); echo $each_poll[0] . "
" . $each_poll[1] . "<hr>";
}
}
break;// If no proper mode selected, display voting form; default: display_form(); break;
}
}
// If no mode selected, display voting form;
if (!isset($mode)) {
display_form();
}function display_form() {
global $config;
global $no_voting;
global $PHP_SELF;
echo "<form name=poll action=" . $PHP_SELF . " method=post>";
$answers = file($config);
if (sizeof($answers) == 0) {
echo $no_voting;
}
else {
$current_number = 1;
$size_answers = sizeof($answers) - 1;
// Display question;
echo $answers[0] . "
";
// Display answers;
for ($current_number = 1; $current_number <= $size_answers; $current_number++) {
echo "<input type=radio name=vote value=" . $current_number . ">" . $answers[$current_number] . "
";
}
echo "<input type=hidden name=mode value=vote>";
echo "
<input type=submit value=vote>";
echo "</form>";
echo "[url=" . $PHP_SELF . "]Results";
echo "";
echo "[url=" . $PHP_SELF . "]Previous polls";
}
}
?>Cosa devo prendere in questo codice per far apparire il sondaggio nel mio sito?
-
Credo dipenda dal fatto che hai register_global (giustamente) settato ad On.
Dovresti sostituire
$PHP_SELF con $_SERVER['PHP_SELF'];
$REMOTE_ADDR con $_SERVER['REMOTE_ADDR'];
$mode con $_POST['mode'] e così via.Oppure, più facilmente, far modificare dal tuo hoster, se ci riesci, register global ad off.
Consiglio? Trovane un altro scritto meglio
-
Infatti, ho lasciato stare questo script, èra pieno di problemi, ora ne ho messo un altro e funziona correttamente solo che appena voto, mi mostra i risultati in una pagina bianca, mentre io vorrei fare in modo che quando uno vota, al posto della domanda e le varie opzioni appaiano i risultati, come faccio?
vi prego aiutatemi mi sto impazzendo
-
hai 3 strade:
- ne trovi uno che fa quello che chiedi pronto da scaricare
- impari e lo programmi da solo
- dai qualche informazione più precisa e proviamo a darti una mano.
-
@massy said:
hai 3 strade:
- ne trovi uno che fa quello che chiedi pronto da scaricare
- impari e lo programmi da solo
- dai qualche informazione più precisa e proviamo a darti una mano.
Grazie per la disponibilita massy, fortunatamente ho risolto bastava inserire il tag <?php require (linkando poll.php) mi sai consigliare uno script che mi permetta di fare la registrazione e login del forum direttamente dal sito?