Enjoy an ad free experience by logging in. Not a member yet?
Register .
11-22-2012, 02:37 PM
PM User |
#1
New to the CF scene
Join Date: Nov 2012
Posts: 9
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ö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ö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>
11-22-2012, 03:10 PM
PM User |
#2
God Emperor
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,645
Thanks: 4
Thanked 2,450 Times in 2,419 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:
11-22-2012, 03:18 PM
PM User |
#3
New to the CF scene
Join Date: Nov 2012
Posts: 9
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.
11-22-2012, 04:42 PM
PM User |
#4
God Emperor
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,645
Thanks: 4
Thanked 2,450 Times in 2,419 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).
11-22-2012, 05:34 PM
PM User |
#5
New to the CF scene
Join Date: Nov 2012
Posts: 9
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 :-)
11-22-2012, 05:40 PM
PM User |
#6
God Emperor
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,645
Thanks: 4
Thanked 2,450 Times in 2,419 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?
11-22-2012, 05:49 PM
PM User |
#7
New to the CF scene
Join Date: Nov 2012
Posts: 9
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ö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ö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>
Quote:
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
11-22-2012, 05:57 PM
PM User |
#8
God Emperor
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,645
Thanks: 4
Thanked 2,450 Times in 2,419 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:
11-22-2012, 06:10 PM
PM User |
#9
New to the CF scene
Join Date: Nov 2012
Posts: 9
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?
11-22-2012, 06:42 PM
PM User |
#10
New to the CF scene
Join Date: Nov 2012
Posts: 9
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-22-2012, 07:09 PM
PM User |
#11
God Emperor
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,645
Thanks: 4
Thanked 2,450 Times in 2,419 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).
11-25-2012, 12:00 AM
PM User |
#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']
Jump To Top of Thread
Thread Tools
Rate This Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT +1. The time now is 04:25 AM .
Advertisement
Log in to turn off these ads.