php echo htmlspecialchars werkt niet ?

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Johannes davidian

johannes davidian

21/07/2022 20:34:48
Quote Anchor link
Hallo,
ik heb deze code toegevoegd in mij contact-form:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">  


wanneer ik heb de contact form ingevulled en submit button geklikt ik krijg de home pagina en de email wordt niet verzonden.

ik zie deze uitlegging over deze code in w3school:
The $_SERVER["PHP_SELF"] is a super global variable that returns the filename of the currently executing script.

en plus deze uitlegging :

he htmlspecialchars() function converts special characters to HTML entities. This means that it will replace HTML characters like < and > with &lt; and &gt;. This prevents attackers from exploiting the code by injecting HTML or Javascript code (Cross-site Scripting attacks) in forms.

mij vraag is nu :
wat is het fout hier dat ik krijg home pagina plus mij email wordt niet verzonden?
is er een oplossing voor deze probleem ? of ik moet negeren deze code helemaal.

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">  


dank u wel
 
PHP hulp

PHP hulp

20/04/2024 08:30:15
 
- Ariën  -
Beheerder

- Ariën -

21/07/2022 20:59:56
Quote Anchor link
Ik vermoed dat je GET parameters gebruikt in je URL?
Je kan het attribuut ook gewoon leeglaten, dan verwijst hij naar de huidige URL:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
action=""
 
Johannes davidian

johannes davidian

21/07/2022 21:06:06
Quote Anchor link
maar dan zou htmlspecialchars geen invloed hebben of wel?
dank u wel
 
- Ariën  -
Beheerder

- Ariën -

21/07/2022 21:37:42
Quote Anchor link
Met htmlspecialchars() maakt je schadelijke tekens, zoals XSS wel onschadelijk!
Het is veilig, maar je kan het attribuut ook gewoon leeg houden als het om dezelfde bestandsnaam gaan.
 
Johannes davidian

johannes davidian

21/07/2022 21:40:55
Quote Anchor link
dank u wel
 
Jan Koehoorn

Jan Koehoorn

22/07/2022 15:32:07
Quote Anchor link
Aanvulling: als je pagina's HTML5 zijn, is het beter om het action attribuut helemaal weg te laten. Dit valideert:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>PHPHulp Question</title>
</head>
<body>
    <form method="post">
        <input type="text" name="email">
        <input type="submit" value="submit me">
    </form>
</body>
</html>

En dit niet:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>PHPHulp Question</title>
</head>
<body>
    <form method="post" action="">
        <input type="text" name="email">
        <input type="submit" value="submit me">
    </form>
</body>
</html>
 
Johannes davidian

johannes davidian

22/07/2022 15:37:30
Quote Anchor link
dank u wel .
ik wist dat action="" had helemaal geen betekenis.
dank u wel for tip
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.