Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New Coder
    Join Date
    Nov 2012
    Posts
    11
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Ip address does not get sent!! Please help.

    Hi guys. I need your help. I have a contact form, on which the ip address is shown, but it does not get send with the form, for whatever reason... What am I doing wrong?? Thanks for your help!!!

    PHP Code:
    <?php
        
    // wenn das Formular ├╝bermittelt wurde
        
    if(isset($_POST['abschicken'])){
          while(list(
    $feld,$wert)=each($_POST)){
            
    // ├╝bermittelte Inhalte "entsch├Ąrfen"
            
    $wert=preg_replace("/(content-type:|bcc:|cc:|to:|from:)/im""",$wert);
            $
    $feld=$wert;
            
    // die ├╝bermittelten Variablen werden zum "Text der Email" zusammengefasst
            
    if($feld!="abschicken"$mailnachricht.=ucfirst($feld).": $wert\n";
          }
          
    $mailnachricht.="\nDatum/Zeit: "date("d.m.Y H:i:s"); 
    $ip=@$REMOTE_ADDR;
    echo 
    "<input type='hidden' value='$ip' />";
          
    // ├œberpr├╝fen ob alle Pflichtfelder gef├╝llt sind
          
    empty($vorname) ? $err[] = "<p>- Bitte den Vornamen angeben.</p>" false;
          empty(
    $email) ? $err[] = "<p>- Bitte die Email-Adresse angeben.</p>" false;
          empty(
    $text) ? $err[] = "<p>- Welchen Wunsch haben Sie? Bitte den Text eingeben.</p>" false;
          
    // wenn nicht, werden die Fehlermeldungen ausgegeben und das "halbgef├╝llte" Formular angezeigt
          
    if(!empty($err)) {
            echo 
    "<p>Bitte korrigieren Sie folgende Fehler:</p>";
            foreach(
    $err as $fehler){
              echo 
    $fehler;
            } 
    ?>
            <form action="<?php echo $_SERVER['kontakt/PHP_SELF']; ?>" method="post">
              <table width="100%" border="0" cellpadding="3" cellspacing="1">
                <tr>
                  <td width="140" align="right" class="style18"><div align="left" class="style22">Nachname:</div></td>
                  <td align="left"><input type="text" name="nachname" value="<?php echo $nachname?>" style="width:100%;" /></td>
                </tr>
                <tr>
                  <td align="right" class="style18"><div align="left" class="style22">Vorname:</div></td>
                  <td align="left"><input type="text" name="vorname" value="<?php echo $vorname?>" style="width:100%" /></td>
                </tr>
                <tr>
                  <td align="right" class="style18"><div align="left">Firma:</div></td>
                  <td align="left"><input type="text" name="firma" value="<?php echo $firma?>" style="width:100%" /></td>
                </tr>
                <tr>
                  <td align="right" class="style18"><div align="left">Postanschrift:</div></td>
                  <td align="left"><input type="text" name="strasse" value="<?php echo $strasse?>" style="width:100%" /></td>
                </tr>
                <tr>
                  <td align="right" class="style18"><div align="left">Telefon:</div></td>
                  <td align="left"><input type="text" name="telefon" value="<?php echo $telefon?>" style="width:100%" /></td>
                </tr>
                <tr>
                  <td align="right" class="style18"><div align="left" class="style22">E-Mail:</div></td>
                  <td align="left"><input type="text" name="email" value="<?php echo $email?>" style="width:100%" /></td>
                </tr>
                <tr>
                  <td align="right" class="style18"><div align="left">Ihre IP Adresse</div></td>
                  <td align="left"><input type="hidden" name="ip" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>" style="width:100%" /></td>
                </tr>
                <tr>
                  <td colspan="2"><textarea rows="12"  style="width:100%" name="text"><?php echo $text?></textarea></td>
                  <td></td>
                </tr>
                <tr>
                  <td colspan="2" align="left" nowrap><input name="reset" type="reset" style="width:49%" value="Formular l&ouml;schen" />
                      <input type="submit" name="abschicken" class="button" value="Formular absenden" style="width:49%" /></td>
                </tr>
              </table>
              <?php    // sind keine Fehler vorhanden, wird die Email versendet
          
    } else {
            
    $mailbetreff="Kontaktformular ".$_SERVER['HTTP_HOST'];
            
    // HIER DIE EMPF─NGER EMAIL-ADRESSE ANPASSEN!!!       
            
    echo (mail("myemail.com"$mailbetreff$mailnachricht"From: $email")) ? "<p>Vielen Dank fŘr Ihre Email.</p>""<p>Ein Fehler ist aufgetreten!</p>"; ;
          }
        
    // das Formular welches als erstes dem Besucher angezeigt wird
        
    } else { ?>
            </form>
            <form action="<?php echo $_SERVER['kontakt/PHP_SELF']; ?>" method="post">
              <table width="100%" border="0" cellpadding="3" cellspacing="1">
                <tr>
                  <td width="140" align="right" class="style18"><div align="left" class="style22">Nachname:</div></td>
                  <td align="left"><input type="text" name="nachname2" value="" style="width:100%;" /></td>
                </tr>
                <tr>
                  <td align="right" class="style18"><div align="left" class="style22">Vorname:</div></td>
                  <td align="left"><input type="text" name="vorname" value="" style="width:100%" /></td>
                </tr>
                <tr>
                  <td align="right" class="style18"><div align="left">Firma:</div></td>
                  <td align="left"><input type="text" name="firma" value="" style="width:100%" /></td>
                </tr>
                <tr>
                  <td align="right" class="style18"><div align="left">Postanschrift:</div></td>
                  <td align="left"><input type="text" name="strasse" value="" style="width:100%" /></td>
                </tr>
                <tr>
                  <td align="right" class="style18"><div align="left">Telefon:</div></td>
                  <td align="left"><input type="text" name="telefon" value="" style="width:100%" /></td>
                </tr>
                <tr>
                  <td align="right" class="style18"><div align="left" class="style22">E-Mail:</div></td>
                  <td align="left"><input type="text" name="email" value="" style="width:100%" /></td>
                </tr>
                <tr>
                  <td align="right" class="style18"><div align="left">Ihre Ip Adresse:</div></td>
                  <td align="left"><input type="hidden"  name="ip" value="" class="style18">
                    <span class="style18"><?php echo $_SERVER['REMOTE_ADDR']; ?></span></td>
                </tr>
                <tr>
                  <td colspan="2"><textarea rows="12"  style="width:100%" name="text"></textarea></td>
                  <td></td>
                </tr>
                <tr>
                  <td colspan="2" align="left" nowrap><input name="reset" type="reset" style="width:49%" value="Formular l&ouml;schen" />
                      <input type="submit" name="abschicken" value="Formular absenden" style="width:49%" /></td>
                </tr>
              </table>
              <!-- bitte lassen Sie diesen Link sichtbar auf Ihrer Seite. Danke! -->
              <?php
        
    }
        
    ?>
            </form>

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    It does. Its a part of $_POST.
    This is invalid: $ip=@$REMOTE_ADDR;. register_globals is gone as of 5.4, and has been disabled by default since 4.2.0. And unless you've created custom environment at the webserver level, this is also invalid: $_SERVER['kontakt/PHP_SELF'].

  • Users who have thanked Fou-Lu for this post:

    gwolff2005 (11-22-2012)

  • #3
    New Coder
    Join Date
    Nov 2012
    Posts
    11
    Thanks
    3
    Thanked 0 Times in 0 Posts
    So what do I need to write/exchange then. As I wrote. It shows it on the site, but it does not post the ip.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Take out this line: $ip=@$REMOTE_ADDR; and it should be fine. You're overwriting the existing $ip with null (and is a good reason why you should evaluate variables instead of relying on variable variables).

  • #5
    New Coder
    Join Date
    Nov 2012
    Posts
    11
    Thanks
    3
    Thanked 0 Times in 0 Posts

    It still does not work

    Hey,
    thanks for the reply. However it still does nto work. It just shows Ip: but then nothing behind that.

    Please help :-)

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    What does it show is in $_POST['ip']?
    Also, which form are you submitting? The second form doesn't have any data in the hidden ip field, only in the text following it. You need to submit the first form to transfer that over or correct the second one. Is there a difference in these two forms?

  • #7
    New Coder
    Join Date
    Nov 2012
    Posts
    11
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Hi Fou-Lu,
    thanks for your help. I am quite a beginner in php. So to be honest I am not sure how to answer you... I really appreciate you helping me. thanks in advance.
    The code is the following now:

    PHP Code:
     <?php
        
    // wenn das Formular ├╝bermittelt wurde
        
    if(isset($_POST['abschicken'])){
          while(list(
    $feld,$wert)=each($_POST)){
            
    // ├╝bermittelte Inhalte "entsch├Ąrfen"
            
    $wert=preg_replace("/(content-type:|bcc:|cc:|to:|from:)/im""",$wert);
            $
    $feld=$wert;
            
    // die ├╝bermittelten Variablen werden zum "Text der Email" zusammengefasst
            
    if($feld!="abschicken"$mailnachricht.=ucfirst($feld).": $wert\n";
          }
          
    $mailnachricht.="\nDatum/Zeit: "date("d.m.Y H:i:s"); 
    echo 
    "<input type='hidden' value='$ip' />";
          
    // ├œberpr├╝fen ob alle Pflichtfelder gef├╝llt sind
          
    empty($vorname) ? $err[] = "<p>- Bitte den Vornamen angeben.</p>" false;
          empty(
    $email) ? $err[] = "<p>- Bitte die Email-Adresse angeben.</p>" false;
          empty(
    $text) ? $err[] = "<p>- Welchen Wunsch haben Sie? Bitte den Text eingeben.</p>" false;
          
    // wenn nicht, werden die Fehlermeldungen ausgegeben und das "halbgef├╝llte" Formular angezeigt
          
    if(!empty($err)) {
            echo 
    "<p>Bitte korrigieren Sie folgende Fehler:</p>";
            foreach(
    $err as $fehler){
              echo 
    $fehler;
            } 
    ?>
            <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
              <table width="100%" border="0" cellpadding="3" cellspacing="1">
                <tr>
                  <td width="140" align="right" class="style18"><div align="left" class="style22">Nachname:</div></td>
                  <td align="left"><input type="text" name="nachname" value="<?php echo $nachname?>" style="width:100%;" /></td>
                </tr>
                <tr>
                  <td align="right" class="style18"><div align="left" class="style22">Vorname:</div></td>
                  <td align="left"><input type="text" name="vorname" value="<?php echo $vorname?>" style="width:100%" /></td>
                </tr>
                <tr>
                  <td align="right" class="style18"><div align="left">Firma:</div></td>
                  <td align="left"><input type="text" name="firma" value="<?php echo $firma?>" style="width:100%" /></td>
                </tr>
                <tr>
                  <td align="right" class="style18"><div align="left">Postanschrift:</div></td>
                  <td align="left"><input type="text" name="strasse" value="<?php echo $strasse?>" style="width:100%" /></td>
                </tr>
                <tr>
                  <td align="right" class="style18"><div align="left">Telefon:</div></td>
                  <td align="left"><input type="text" name="telefon" value="<?php echo $telefon?>" style="width:100%" /></td>
                </tr>
                <tr>
                  <td align="right" class="style18"><div align="left" class="style22">E-Mail:</div></td>
                  <td align="left"><input type="text" name="email" value="<?php echo $email?>" style="width:100%" /></td>
                </tr>
                <tr>
                  <td align="right" class="style18"><div align="left">Ihre IP Adresse</div></td>
                  <td align="left"><input type="hidden" name="ip" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>" style="width:100%" /></td>
                </tr>
                <tr>
                  <td colspan="2"><textarea rows="12"  style="width:100%" name="text"><?php echo $text?></textarea></td>
                  <td></td>
                </tr>
                <tr>
                  <td colspan="2" align="left" nowrap><input name="reset" type="reset" style="width:49%" value="Formular l&ouml;schen" />
                      <input type="submit" name="abschicken" class="button" value="Formular absenden" style="width:49%" /></td>
                </tr>
              </table>
              <?php    // sind keine Fehler vorhanden, wird die Email versendet
          
    } else {
            
    $mailbetreff="Kontaktformular ".$_SERVER['HTTP_HOST'];
            
    // HIER DIE EMPF─NGER EMAIL-ADRESSE ANPASSEN!!!       
            
    echo (mail("myemail.com"$mailbetreff$mailnachricht"From: $email")) ? "<p>Vielen Dank fŘr Ihre Email.</p>""<p>Ein Fehler ist aufgetreten!</p>"; ;
          }
        
    // das Formular welches als erstes dem Besucher angezeigt wird
        
    } else { ?>
            </form>
            <form action="<?php echo $_SERVER['kontakt/PHP_SELF']; ?>" method="post">
              <table width="100%" border="0" cellpadding="3" cellspacing="1">
                <tr>
                  <td width="140" align="right" class="style18"><div align="left" class="style22">Nachname:</div></td>
                  <td align="left"><input type="text" name="nachname2" value="" style="width:100%;" /></td>
                </tr>
                <tr>
                  <td align="right" class="style18"><div align="left" class="style22">Vorname:</div></td>
                  <td align="left"><input type="text" name="vorname" value="" style="width:100%" /></td>
                </tr>
                <tr>
                  <td align="right" class="style18"><div align="left">Firma:</div></td>
                  <td align="left"><input type="text" name="firma" value="" style="width:100%" /></td>
                </tr>
                <tr>
                  <td align="right" class="style18"><div align="left">Postanschrift:</div></td>
                  <td align="left"><input type="text" name="strasse" value="" style="width:100%" /></td>
                </tr>
                <tr>
                  <td align="right" class="style18"><div align="left">Telefon:</div></td>
                  <td align="left"><input type="text" name="telefon" value="" style="width:100%" /></td>
                </tr>
                <tr>
                  <td align="right" class="style18"><div align="left" class="style22">E-Mail:</div></td>
                  <td align="left"><input type="text" name="email" value="" style="width:100%" /></td>
                </tr>
                <tr>
                  <td align="right" class="style18"><div align="left">Ihre Ip Adresse:</div></td>
                  <td align="left"><input type="hidden"  name="ip" value="" class="style18">
                    <span class="style18"><?php echo $_SERVER['REMOTE_ADDR']; ?></span></td>
                </tr>
                <tr>
                  <td colspan="2"><textarea rows="12"  style="width:100%" name="text"></textarea></td>
                  <td></td>
                </tr>
                <tr>
                  <td colspan="2" align="left" nowrap><input name="reset" type="reset" style="width:49%" value="Formular l&ouml;schen" />
                      <input type="submit" name="abschicken" value="Formular absenden" style="width:49%" /></td>
                </tr>
              </table>
              <!-- bitte lassen Sie diesen Link sichtbar auf Ihrer Seite. Danke! -->
              <?php
        
    }
        
    ?>
            </form>
    </div>



    The email I get is then:
    Nachname2: Wolff
    Vorname: Thei
    Firma: consumaam
    Strasse: Brinkeweg
    Telefon: 05209/87986546
    Email: bertie@viogts.de
    Ip:
    Text: test

    Datum/Zeit: 22.11.2012 10:32:14

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    It looks like its using your second form then. I don't know if there's a difference between these ones (I'll have a hard time following it since its not in english), but your problem is here:
    Code:
                <tr>
                  <td align="right" class="style18"><div align="left">Ihre Ip Adresse:</div></td>
                  <td align="left"><input type="hidden"  name="ip" value="" class="style18">
                    <span class="style18"><?php echo $_SERVER['REMOTE_ADDR']; ?></span></td>
                </tr>
    There is no value for the ip input.

    Also, I should mention there if you don't expect that the IP will change, you can just pull it out during the submission instead of passing it through the form.

  • Users who have thanked Fou-Lu for this post:

    gwolff2005 (11-22-2012)

  • #9
    New Coder
    Join Date
    Nov 2012
    Posts
    11
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Hi Fou Lu,
    probably a dumb question. But what do I need then to put between the brackets as value??
    Or what do I need to write in order to pull it out during the submission?

  • #10
    New Coder
    Join Date
    Nov 2012
    Posts
    11
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Hi Fou-Lu,

    i figured it ou. I had the value empty....

    Thnak you so much for your help!

  • #11
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Yep your welcome. You could literally just copy and past the one from higher up in the form, that's why I'm not sure exactly why two forms exist on this one. Its clearly just for representing it if its seeing an error, but its easy enough to change a few things to just use one form (so things like this issue don't occur).

  • #12
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <input type="hidden" name="IP" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>" />
    or the easier way to do it would just be

    [PHP]
    $ip = $_SERVER['REMOTE_ADDR']


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •