Autor Beitrag
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: So 17.07.05 13:52 
Wenn in einer HTML-Datei ein Formular mit einer Textarea ist, welches per POST verschickt wird, kommen Anführungszeichen als \" an. Wie kann ich aus \" wieder " machen?
Hier mal ein Beispielcode:

ausblenden Senden.html
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
<html>
 <head>
  <title>Senden</title>
 </head>
 <body>
  <form action="Empfang.php" METHOD=POST name="formular">
   <textarea name="text">"Test"</textarea>
   <input type="submit">
  </form>
 </body>
</html>


ausblenden Empfang.php
1:
2:
3:
4:
<?php
  $zeile=$_POST["text"];
  echo $zeile;
?>


(Ausgabe: \"Test\")

Wieso macht er das? Und wie kann man das Abstellen?

P.S.: Ich benutze Apache 2.0.48 mit PHP 5.0.4

Moderiert von user profile iconChristian S.: code-Tags hinzugefügt.

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
DaRkFiRe
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 526

WinXP Home & Professional
C, C++, Delphi
BeitragVerfasst: So 17.07.05 14:09 
$zeile = strreplace("\\\"","\"",$zeile);

aus \\\" wird dann \"
und aus \" wird "

Das wird ersetzt - et voilà.

_________________
Lang ist der Weg durch Lehren - kurz und wirksam durch Beispiele! Seneca
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: So 17.07.05 14:17 
Das wird vor allem aus Sicherheitsgründen gemacht.

Stell dir vor, dein Eintrag in die DB lautet:
ausblenden Quelltext
1:
mysql_query("INSERT INTO my_gb (name, text) VALUES ('". $name ."', '". $text ."')");					

Das könnte dann so aussehen:
ausblenden Quelltext
1:
mysql_query("INSERT INTO my_gb (name, text) VALUES ('GTA-Place', 'Hallo')");					

Aber auch so:
ausblenden Quelltext
1:
2:
3:
4:
mysql_query("INSERT INTO my_gb (name, text) VALUES ('Hacker', 'bla')");
$sql = mysql_query("SELECT * FROM forum_user");
while ($result = mysql_fetch_assoc($sql))
  echo($result['user_name'] .' - '. $result['user_pw']);

(was gehighlightet ist, ist der im GB (oder sonstwo) eingetragene Text)

Und was würde der Hacker bekommen? Alle User + Passwörter. Und das wollen wir ja nicht.
Deswegen werden ', ", etc. geparst.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
StefanH
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1144

Win XP
D5 Standard, D7 Pers, D2005 Pers
BeitragVerfasst: So 17.07.05 14:32 
user profile iconjakobwenzel hat folgendes geschrieben:
Wenn in einer HTML-Datei ein Formular mit einer Textarea ist, welches per POST verschickt wird, kommen Anführungszeichen als " an. Wie kann ich aus " wieder " machen?


mit stripslashes($_POST['text']) :)

_________________
"Als es noch keine Computer gab, war das Programmieren noch relativ einfach."(Edsger W. Dijkstra)
"Ich bin nicht von Sinnen, sondern ich rede wahre und vernünftige Worte." (Paulus)
jakobwenzel Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: So 17.07.05 14:36 
Auf die Idee mit str_replace bin ich auch schon gekommen, sogar mit den gleichen Parametern, aber es hat irgendwie nicht funktioniert. Aber das mit Stripslashes geht! Danke!! :D

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.