Jump to content

how and where put the captcha


uisneach

Recommended Posts

Hello.

 

:) I got a form like this. It' s a drop down menu. (i took out other menus like day and hours, to make it simple)

 

<form action='form2.php' method='POST'>

<select name='year'>

    <option value='2004'>2008</option>

<option value='2005'>2005</option>

<option value='2006'>2006</option>

<option value='2007'>2007</option>

<option value='2007'>2008</option>

</select>";

   

<select name='month'>

    <option value='10'>october</option>

    <option value='11'>november</option>

  <option value='12'>december</option>

</select>";

<input name='submit' type='submit' value='send' />

  <input type='hidden' name='submitted' value='yes' />

  </form>";

 

My main question is how to insert a captcha script here. I got some problems. I really don't know how to begin.

Sorry, I am newbie.

Anyone has some clue/Advice/suggestion to give me? It's reallyt a bit tricky for me.

Thx in advance.

 

;)

 

Link to comment
Share on other sites

Hello.

I got the captcha script from secuimage. It works ...but the problem is to adapt the scrpt to my website.

This is the example form taken from the tutorial.

<?php

if (empty($_POST)) { ?>

<form method="POST">

Username:<br />

<input type="text" name="username" /><br />

Password:<br />

<input type="text" name="password" /><br />

 

<!-- pass a session id to the query string of the script to prevent ie caching -->

<img src="securimage_show.php?sid=<?php echo md5(uniqid(time())); ?>"><br />

<input type="text" name="code" /><br />

 

<input type="submit" value="Submit Form" />

</form>

 

<?php

} else { //form is posted

  include("securimage.php");

  $img = new Securimage();

  $valid = $img->check($_POST['code']);

 

  if($valid == true) {

    echo "<center>Thanks, you entered the correct code.</center>";

  } else {

    echo "<center>Sorry, the code you entered was invalid.  <a href=\"javascript:history.go(-1)\">Go back</a> to try again.</center>";

  }

}

 

?>

 

 

 

Link to comment
Share on other sites

I MADE like this but it gives an error

 

  session_start();

<form action='form2.php' method='POST'>

<select name='year'>

    <option value='2004'>2008</option>

<option value='2005'>2005</option>

<option value='2006'>2006</option>

<option value='2007'>2007</option>

<option value='2007'>2008</option>

</select>";

 

<select name='month'>

    <option value='10'>october</option>

    <option value='11'>november</option>

  <option value='12'>december</option>

</select>";

<input name='submit' type='submit' value='send' />

  <input type='hidden' name='submitted' value='yes' />

 

  </form>";

 

<img src="securimage_show.php?sid=<?php echo md5(uniqid(time())); ?>"><br />

<input type="text" name="code" /><br />

 

<?php

 

  include("securimage.php");

  $img = new Securimage();

  $valid = $img->check($_POST['code']);

 

  if($valid == true) {

    echo "<center>Thanks, you entered the correct code.</center>";

  } else {

    echo "<center>Sorry, the code you entered was invalid.  <a href=\"javascript:history.go(-1)\">Go back</a> to try again.</center>";

  }

 

Link to comment
Share on other sites

HELLO :)

 

I followed the tutorial step by step but it does not work

 

http://www.phpcaptcha.org/documentation/quickstart/#comment-388

 

that what happens:

 

Hello

Thx for your tutorial

It’s good for the front-end section but failed on back end

 

I strictly followed your suggstions and put

the script

 

/* captcha*/

 

include_once $_SERVER['DOCUMENT_ROOT'] . ‘/securimage/securimage.php’;

 

$securimage = new Securimage();

 

if ($securimage->check($_POST['captcha_code']) == false) {

// the code was incorrect

// handle the error accordingly with your other error checking

 

// or you can do something really basic like this

die(’The code you entered was incorrect. Go back and try again.’);

}

 

on the php file that processes my form

but it doesn’t work

that’s the error:

 

Warning: include_once(/securimage/securimage.php) [function.include-once]: failed to open stream: No such file or directory in D:\Inetpub\webs\istrionicocom\form2.php on line 57

 

Warning: include_once() [function.include]: Failed opening ‘/securimage/securimage.php’ for inclusion (include_path=’.;c:\php\includes’) in D:\Inetpub\webs\istrionicocom\form2.php on line 57

 

Fatal error: Class ‘Securimage’ not found in D:\Inetpub\webs\istrionicocom\form2.php on line 59

 

Anyone has a clue?

 

regards

paolo

Link to comment
Share on other sites

http://www.pictureinthesky.net/external/phpfreaks/ivan_captcha.zip

 

That's a captcha script I wrote and there should be a sample script in there showing how to use it.

 

One of the features of this script is that it uses TTF (TrueType Fonts) that can be downloaded off the net or from the fonts folder on your computer.

 

To see the script working try sending a message or signing the guestbook on my website:

 

http://www.pictureinthesky.net

Link to comment
Share on other sites

signguestbook.php

That's a cut-down version of the script used on my website.

 

Where the image is used on the page I'm calling the next file IMG within HTML:

<img src="includes/makeimg.php" alt="" width="130" height="34" border="0" />

 

Inside this script you can find this line:

    if (md5($_POST['vcode'])==$_SESSION['vercode']) {

This checks the MD5 hash of the text entered by the user against the MD5 hash of the text inside the captcha image. If it matches it carries on checking the rest of the information and if it fails it tells the user the code doesn't match.

 

makeimg.php

This is the script that makes the captcha image. This needs to access the TTF font so have that inside a FONT folder wherever you put this script.

Link to comment
Share on other sites

OK the onew thing I see missing is the input box so the user can type in the captcha code - apologies if that is what you meant!

 

<input type="text" name="vcode" size="8" maxlength="6" />

 

Add that somewhere near the captcha image. Don't forget to name the text box what you want to use it in the script.

 

Again, sorry for the confusion!

Link to comment
Share on other sites

One last thing I forgot to mention...

 

This line inside makeimg.php:

$chars='abcdefghijkmnqrstuvwxyz0123456789ABCDEFGHIJKLMNPQRSTUVWXYZ';

 

Those characters are those that will be used inside the captcha - change this to what you want to appear inside the image.

 

You can change the font to whatever you want to use by uploading a different one but it must be TTF.

Link to comment
Share on other sites

Yes sorry :)

 

Here is the form

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/Speciali.dwt" codeOutsideHTMLIsLocked="false" -->

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

 

<title>Inserisci i dati: soppressioni</title>

 

<link href="passante.css" rel="stylesheet" type="text/css"/>

 

</head>

 

 

<body>

 

<div class="testata"></div>

<div class="menu">

    <a href="http://segratrain.altervista.org/index.html">Home</a>

    <a href="http://www.istrionico.com/inserisci2.php">Inserisci Soppressione</a>

      <a href="http://www.istrionico.com/listasoppressioni.php">Archivio Soppressioni</a>

      <a href="http://www.istrionico.com/inserisci.php">Inserisci Ritardo</a>

        <a href="http://www.istrionico.com/listaritardi.php">Archivio Ritardi</a>

            <a href="http://segratrain.altervista.org/news.html">News</a>

                <a href="http://segratrain.altervista.org/documenti.html">Documenti</a>

                <a href="http://segratrain.altervista.org/contatti.html">Contatti</a>

    </div>

<div class="centrale2">

<div class="sinistra2"><div class="altosx6"></div>

<br />

 

<?php

  session_start();

// SETTO I DATI PER LA CONFIGURAZIONE DELLA CONNESSIONE CREANDO LE RELATIVE VARIABILI

$host = "";

$user = "";

$password = "";

$dbname = "";

//CREO LA VARIABILE CHE CONNETTE IL SERVER AL DATABASE

$cxn = mysql_connect($host,$user,$password);

mysql_select_db($dbname);

//CONTROLLO CONNESSIONE SE è OK

if (!$cxn)

    echo 'Errore durante la connessione al server MySQL'; 

 

exit();

 

  } 

  else { 

   

echo ''; 

}

  echo "<span style='font-family:arial'/>Inserisci i dati del treno SOPPRESSO </span>";

  echo "<p style='font-family:arial'>

 

  <form action='form2.php' method='POST'>

    <select name='giorno'>

  <option value='01'>1</option>

  <option value='02'>2</option>

<option value='03'>3</option>

  <option value='04'>4</option>

  <option value='05'>5</option>

  <option value='06'>6</option>

  <option value='07'>7</option>

  <option value='08'>8</option>

  <option value='09'>9</option>

  <option value='10'>10</option>

  <option value='11'>11</option>

  <option value='12'>12</option>

  <option value='13'>13</option>

  <option value='14'>14</option>

  <option value='15'>15</option>

  <option value='16'>16</option>

  <option value='17'>17</option>

  <option value='18'>18</option>

  <option value='19'>19</option>

  <option value='20'>20</option>

  <option value='21'>21</option>

  <option value='22'>22</option>

  <option value='23'>23</option>

  <option value='24'>24</option>

  <option value='25'>25</option>

  <option value='26'>26</option>

  <option value='27'>27</option>

  <option value='28'>28</option>

  <option value='29'>29</option>

  <option value='30'>30</option>

  <option value='31'>31</option>

</select>";

 

  echo "Giorno

    <select name='mese'>

    <option value='10'>ottobre</option>

    <option value='11'>novembre</option>

  <option value='12'>dicembre</option>

</select>";

   

  echo "Mese

    <select name='anno'>

    <option value='2008'>2008</option>

 

</select>";

   

  echo "anno <br /><br />

    <select name='direzione'>

  <option value='Pioltello'>Pioltello</option>

  <option value='Varese'>Varese</option>

 

</select>";

  echo "Direzione <br /><br />

    <select name='orario'>

  <option value='0614'>6.14</option>

  <option value='0644'>6.44</option>

  <option value='0714'>7.14</option>

  <option value='0744'>7.44</option>

  <option value='0814'>8.14</option>

  <option value='0844'>8.44</option>

  <option value='0914'>9.14</option>

  <option value='0944'>9.44</option>

    <option value='1014'>10.14</option>

    <option value='1044'>10.44</option>

      <option value='1114'>11.14</option>

        <option value='1144'>11.44</option>

          <option value='1214'>12.14</option>

            <option value='1244'>12.44</option>

              <option value='1314'>13.14</option>

                <option value='1344'>13.44</option>

<option value='1414'>14.14</option>

      <option value='1444'>14.44</option>

        <option value='1514'>15.14</option>

          <option value='1544'>15.44</option>

            <option value='1614'>16.14</option>

              <option value='1644'>16.44</option>

                <option value='1714'>17.14</option>

<option value='1744'>17.44</option>

        <option value='1814'>18.14</option>

          <option value='1844'>18.44</option>

            <option value='1914'>19.14</option>

              <option value='1944'>19.44</option>

                <option value='2014'>20.14</option>

                <option value='2044'>20.44</option>

        <option value='2114'>21.14</option>

          <option value='2144'>21.44</option>

            <option value='2214'>22.14</option>

              <option value='2244'>22.44</option>

                <option value='2314'>23.14</option>

             

          <option value='2344'>23.44</option>

            <option value='0014'>.00.14</option>

             

</select>";

 

  echo "Orario *<br/ >

  <br />

  <select name='annunciata'>

  <option value='si'>Si</option>

  <option value='no'>No</option>

 

 

</select>";

  echo "Annunciata<br />

  <br />

 

 

  <br />

 

 

  <img src='includes/makeimg.php' alt='captcha' width='130' height='34' border='0 />

 

  <input type='hidden' name='submitted' value='yes' /> <br /><br />

  <input type='text' name='vcode' size='8' maxlength='6' /><br />verifica codice

  <input name='submit' type='submit' value='invia' /><br />

  </form>";

 

 

?>

 

<br />

<br />

<br />

<br />

<h4 class="pippo">* Nota: L'orario verso Pioltello è diverso:   .15 o .45   invece che .14 o .44;  Ma, dato che pochissima gente utilizza il treno in direzione Pioltello,<br /> si è deciso di lasciare un solo orario di riferimento, quello per Varese  ma si puo' utilizzare anche per il Treno in direzione Pioltello</h4>

</div>

</div>

<div class="footer" > <a href="maito:segratrain@libero.it">segratrain@libero.it</a></div>

 

 

</body>

</html>

 

Link to comment
Share on other sites

and this is the php file that makes the form working

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/Speciali.dwt" codeOutsideHTMLIsLocked="false" -->

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

 

<title>Inserisci i dati:ritardi</title>

 

<link href="passante.css" rel="stylesheet" type="text/css"/>

 

</head>

 

 

<body>

 

<div class="testata"></div>

<div class="menu">

    <a href="http://segratrain.altervista.org/index.html">Home</a>

    <a href="http://www.istrionico.com/inserisci2.php">Inserisci Soppressione</a>

      <a href="http://www.istrionico.com/listasoppressioni.php">Archivio Soppressioni</a>

      <a href="http://www.istrionico.com/inserisci.php">Inserisci Ritardo</a>

        <a href="http://www.istrionico.com/listaritardi.php">Archivio Ritardi</a>

            <a href="http://segratrain.altervista.org/news.html">News</a>

                <a href="http://segratrain.altervista.org/documenti.html">Documenti</a>

                <a href="http://segratrain.altervista.org/contatti.html">Contatti</a>

    </div>

<div class="centrale">

<div class="sinistra2"><div class="altosx6"></div>

<br />

<?

 

require ('config.php');

 

$giorno = $_POST['giorno'];

$mese = $_POST['mese'];

$anno = $_POST['anno'];

$orario = $_POST['orario'];

$direzione = $_POST['direzione'];

$annunciata = $_POST ['annunciata']; 

$var = $annunciata;

 

 

 

 

if ($var == 'si'){

$si = 1;

$no = 0;

}

else {

$si = 0;

$no = 1;

 

}

 

/* captcha*/

 

 

   

/* Controllo IP */

 

$Ip_address = $_SERVER['REMOTE_ADDR'];

 

/* Controllo se un utente inserisce una data o un'ora non ancora passata */

$time = strtotime("now");

 

$then = strtotime("$giorno-$mese-$anno-$orario");

if ($then > $time) {

echo "Questo treno non è ancora passato, fai un altro inserimento";

exit();

} else {

//okay

}

 

 

 

 

/* Controllo se un utente inserisce un giorno sbagliato esempio 31 novembre */

if (($mese == '11') && ($giorno == '31')){

 

echo "<br />";

echo "<p> Non esiste quel giorno. Per favore, controlla il tuo inserimento";

die();

}

else {

echo "";

}

/* Controllo se è già presente l'id del treno */

 

$sql1="SELECT * FROM treni_soppressione WHERE giorno = '$giorno' AND mese = '$mese' AND anno = '$anno' AND orario = '$orario' AND direzione = '$direzione'";

$risultato = mysql_query ($sql1);

$num_righe = mysql_num_rows($risultato);

 

if($num_righe == 0) {

/* se non è stato ancora inserito quel particolare treno , creo la nuova combinazione nel database*/

$sql = "INSERT INTO treni_soppressione (giorno,mese,anno,orario,direzione,annunciata,no,si) VALUES ('$giorno','$mese','$anno','$orario','$direzione','$annunciata','$no','$si')";

$result = mysql_query($sql);

/* faccio inserimento dell'indirizzo IP dell'utente che inserisce dati treni*/

 

$inserisciIp = "INSERT INTO controllo_ip_treni_sop (ip, giorno, mese, anno, orario, direzione) VALUES ('$Ip_address','$giorno','$mese','$anno','$orario','$direzione')";

$result = mysql_query ($inserisciIp);

}

 

else{

/* Altrimenti aumento il numero di segnalazioni*/

/* Ma prima controllo se un utente con un certo ip voglia segnalare lo stesso treno due volte*/

$controllaIP = "SELECT * FROM controllo_ip_treni_sop WHERE ip='$Ip_address' AND giorno = '$giorno' AND mese = '$mese' AND anno = '$anno' AND orario = '$orario' AND direzione = '$direzione'";

$risIP = mysql_query ($controllaIP);

$num_righe2 = mysql_num_rows($risIP);

 

if ($num_righe2 == 0) {

 

$sql2 ="UPDATE treni_soppressione SET no=(no+'$no'), si=(si+'$si')  WHERE giorno = '$giorno' AND mese = '$mese' AND anno = '$anno' AND orario = '$orario' AND direzione = '$direzione' ";

$result2 = mysql_query($sql2);

$sicontr="SELECT * FROM treni_soppressione  WHERE giorno = '$giorno' AND mese = '$mese' AND anno = '$anno' AND orario = '$orario' AND direzione = '$direzione'";

$pippo = mysql_query ($sicontr);

$sql5 = mysql_fetch_row ($pippo);

 

if ($sql5[8]  >= $sql5[7]) {

 

 

$sql3 = "UPDATE treni_soppressione SET annunciata = 'si'  WHERE giorno = '$giorno' AND mese = '$mese' AND anno = '$anno' AND orario = '$orario' AND direzione = '$direzione' ";

$result3 = mysql_query($sql3);

  } 

  else {

 

$sql6 ="UPDATE treni_soppressione SET annunciata = 'no' WHERE giorno = '$giorno' AND mese = '$mese' AND anno = '$anno' AND orario = '$orario' AND direzione = '$direzione' ";

$result4 = mysql_query($sql6);

 

  }

 

}

else {

 

echo "Hai appena inserito una segnalazione per quel treno.";

exit();

}

 

}

 

echo "<span style='font-family: arial';>grazie per la segnalazione</span></br>";

echo "<span style='font-family: arial';><a href='http://segratrain.altervista.org/'>torna alla pagina principale</a></span>";

 

 

 

?>

 

</div>

 

<div class="footer" ><a href="maito:segratrain@libero.it">segratrain@libero.it</a></div>

 

 

</body>

</html>

 

Link to comment
Share on other sites

sorry really.  I hope to understand what you mean

 

Here is the form

 

[ code]

<?php

  session_start();

// SETTO I DATI PER LA CONFIGURAZIONE DELLA CONNESSIONE CREANDO LE RELATIVE VARIABILI

$host = "";

$user = "";

$password = "";

$dbname = "";

//CREO LA VARIABILE CHE CONNETTE IL SERVER AL DATABASE

$cxn = mysql_connect($host,$user,$password);

mysql_select_db($dbname);

//CONTROLLO CONNESSIONE SE è OK

if (!$cxn)

{

    echo 'Errore durante la connessione al server MySQL';

 

exit();

 

  }

  else {

 

  echo '';

}

  echo "<span style='font-family:arial'/>Inserisci i dati del treno SOPPRESSO </span>";

  echo "<p style='font-family:arial'>

 

      <form action='form2.php' method='POST'>

    <select name='giorno'>

  <option value='01'>1</option>

  <option value='02'>2</option>

<option value='03'>3</option>

  <option value='04'>4</option>

  <option value='05'>5</option>

  <option value='06'>6</option>

  <option value='07'>7</option>

  <option value='08'>8</option>

  <option value='09'>9</option>

  <option value='10'>10</option>

  <option value='11'>11</option>

  <option value='12'>12</option>

  <option value='13'>13</option>

  <option value='14'>14</option>

  <option value='15'>15</option>

  <option value='16'>16</option>

  <option value='17'>17</option>

  <option value='18'>18</option>

  <option value='19'>19</option>

  <option value='20'>20</option>

  <option value='21'>21</option>

  <option value='22'>22</option>

  <option value='23'>23</option>

  <option value='24'>24</option>

  <option value='25'>25</option>

  <option value='26'>26</option>

  <option value='27'>27</option>

  <option value='28'>28</option>

  <option value='29'>29</option>

  <option value='30'>30</option>

  <option value='31'>31</option>

</select>";

 

  echo "Giorno

    <select name='mese'>

    <option value='10'>ottobre</option>

    <option value='11'>novembre</option>

  <option value='12'>dicembre</option>

</select>";

 

  echo "Mese

    <select name='anno'>

    <option value='2008'>2008</option>

 

</select>";

 

  echo "anno <br /><br />

    <select name='direzione'>

  <option value='Pioltello'>Pioltello</option>

  <option value='Varese'>Varese</option>

 

</select>";

  echo "Direzione <br /><br />

    <select name='orario'>

  <option value='0614'>6.14</option>

  <option value='0644'>6.44</option>

  <option value='0714'>7.14</option>

  <option value='0744'>7.44</option>

  <option value='0814'>8.14</option>

  <option value='0844'>8.44</option>

  <option value='0914'>9.14</option>

  <option value='0944'>9.44</option>

    <option value='1014'>10.14</option>

    <option value='1044'>10.44</option>

      <option value='1114'>11.14</option>

        <option value='1144'>11.44</option>

          <option value='1214'>12.14</option>

            <option value='1244'>12.44</option>

              <option value='1314'>13.14</option>

                <option value='1344'>13.44</option>

<option value='1414'>14.14</option>

      <option value='1444'>14.44</option>

        <option value='1514'>15.14</option>

          <option value='1544'>15.44</option>

            <option value='1614'>16.14</option>

              <option value='1644'>16.44</option>

                <option value='1714'>17.14</option>

<option value='1744'>17.44</option>

        <option value='1814'>18.14</option>

          <option value='1844'>18.44</option>

            <option value='1914'>19.14</option>

              <option value='1944'>19.44</option>

                <option value='2014'>20.14</option>

                <option value='2044'>20.44</option>

        <option value='2114'>21.14</option>

          <option value='2144'>21.44</option>

            <option value='2214'>22.14</option>

              <option value='2244'>22.44</option>

                <option value='2314'>23.14</option>

             

          <option value='2344'>23.44</option>

            <option value='0014'>.00.14</option>

           

</select>";

 

  echo "Orario *<br/ >

  <br />

  <select name='annunciata'>

  <option value='si'>Si</option>

  <option value='no'>No</option>

 

 

</select>";

  echo "Annunciata<br />

  <br />

 

 

  <br />

 

 

  <img src='includes/makeimg.php' alt='captcha' width='130' height='34' border='0 />

 

  <input type='hidden' name='submitted' value='yes' /> <br /><br />

  <input type='text' name='vcode' size='8' maxlength='6' /><br />verifica codice

  <input name='submit' type='submit' value='invia' /><br />

  </form>";

 

 

?>

[ /code]

<br />

<br />

<br />

<br />

<h4 class="pippo">* Nota: L'orario verso Pioltello è diverso:   .15 o .45   invece che .14 o .44;  Ma, dato che pochissima gente utilizza il treno in direzione Pioltello,<br /> si è deciso di lasciare un solo orario di riferimento, quello per Varese  ma si puo' utilizzare anche per il Treno in direzione Pioltello</h4>

</div>

</div>

<div class="footer" > <a href="maito:segratrain@libero.it">segratrain@libero.it</a></div>

 

 

</body>

</html>

Link to comment
Share on other sites

From what I can see so far I see this code in the second script:

$giorno = $_POST['giorno'];
$mese = $_POST['mese'];
$anno = $_POST['anno'];
$orario = $_POST['orario'];
$direzione = $_POST['direzione'];
$annunciata = $_POST ['annunciata'];

 

From then on I presume (I can't read - Italian?) you're validating the data sent from the form. If I'm right, check the code the user entered with the one in the captcha code immediately after the above code I just posted.

 

Remember, the session variable contains just the MD5 hash so you'd check it with this:

if (md5($usercode)==$_SESSION['vercode']) {
  //code right
} else {
  //code wrong
}

 

btw, when posting code use [code] and [/code].

Link to comment
Share on other sites

<?

require ('config.php');

$giorno = $_POST['giorno'];
$mese = $_POST['mese'];
$anno = $_POST['anno'];
$orario = $_POST['orario']; 
$direzione = $_POST['direzione']; 
$annunciata = $_POST ['annunciata'];  
$var = $annunciata;




if ($var == 'si'){
$si = 1;
$no = 0;
}
else {
$si = 0;
$no = 1;

}

/* captcha*/


     
/* Controllo IP */

$Ip_address = $_SERVER['REMOTE_ADDR'];

/* Controllo se un utente inserisce una data o un'ora non ancora passata */
$time = strtotime("now");

$then = strtotime("$giorno-$mese-$anno-$orario");
if ($then > $time) {
echo "Questo treno non è ancora passato, fai un altro inserimento";
exit();
} else {
//okay
}




/* Controllo se un utente inserisce un giorno sbagliato esempio 31 novembre */
if (($mese == '11') && ($giorno == '31')){

echo "<br />";
echo "<p> Non esiste quel giorno. Per favore, controlla il tuo inserimento";
die();
}
else {
echo "";
}
/* Controllo se è già presente l'id del treno */

$sql1="SELECT * FROM treni_soppressione WHERE giorno = '$giorno' AND mese = '$mese' AND anno = '$anno' AND orario = '$orario' AND direzione = '$direzione'";
$risultato = mysql_query ($sql1);
$num_righe = mysql_num_rows($risultato);

if($num_righe == 0) {
/* se non è stato ancora inserito quel particolare treno , creo la nuova combinazione nel database*/
$sql = "INSERT INTO treni_soppressione (giorno,mese,anno,orario,direzione,annunciata,no,si) VALUES ('$giorno','$mese','$anno','$orario','$direzione','$annunciata','$no','$si')";
$result = mysql_query($sql);
/* faccio inserimento dell'indirizzo IP dell'utente che inserisce dati treni*/

$inserisciIp = "INSERT INTO controllo_ip_treni_sop (ip, giorno, mese, anno, orario, direzione) VALUES ('$Ip_address','$giorno','$mese','$anno','$orario','$direzione')";
$result = mysql_query ($inserisciIp); 
}

else{
/* Altrimenti aumento il numero di segnalazioni*/
/* Ma prima controllo se un utente con un certo ip voglia segnalare lo stesso treno due volte*/
$controllaIP = "SELECT * FROM controllo_ip_treni_sop WHERE ip='$Ip_address' AND giorno = '$giorno' AND mese = '$mese' AND anno = '$anno' AND orario = '$orario' AND direzione = '$direzione'";
$risIP = mysql_query ($controllaIP);
$num_righe2 = mysql_num_rows($risIP);

if ($num_righe2 == 0) {

$sql2 ="UPDATE treni_soppressione SET no=(no+'$no'), si=(si+'$si')  WHERE giorno = '$giorno' AND mese = '$mese' AND anno = '$anno' AND orario = '$orario' AND direzione = '$direzione' ";
$result2 = mysql_query($sql2);
$sicontr="SELECT * FROM treni_soppressione  WHERE giorno = '$giorno' AND mese = '$mese' AND anno = '$anno' AND orario = '$orario' AND direzione = '$direzione'";
$pippo = mysql_query ($sicontr);
$sql5 = mysql_fetch_row ($pippo);

if ($sql5[8]  >= $sql5[7]) {
  

$sql3 = "UPDATE treni_soppressione SET annunciata = 'si'  WHERE giorno = '$giorno' AND mese = '$mese' AND anno = '$anno' AND orario = '$orario' AND direzione = '$direzione' ";
$result3 = mysql_query($sql3);
  }  
  else {

$sql6 ="UPDATE treni_soppressione SET annunciata = 'no' WHERE giorno = '$giorno' AND mese = '$mese' AND anno = '$anno' AND orario = '$orario' AND direzione = '$direzione' ";
$result4 = mysql_query($sql6);
  
  }

}
else {

echo "Hai appena inserito una segnalazione per quel treno.";
exit(); 
}

}

echo "<span style='font-family: arial';>grazie per la segnalazione</span></br>"; 
echo "<span style='font-family: arial';><a href='http://segratrain.altervista.org/'>torna alla pagina principale</a></span>";

?>
[ /code]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.