You are here
Home > Hacking > Cross-Site Request Forgery (CSRF) Prevention in PHP

Cross-Site Request Forgery (CSRF) Prevention in PHP

Hello, friends today we are going to learn Cross-Site Request Forgery (CSRF) Prevention in PHP by using random token in each request. In Cross-Site Request Forgery (CSRF) attack the victim unintentionally sends web request that takes advantage of their logged in session on a particular site to leak server data, change session state or to manipulate user’s account. To prevent CSRF attack a unique, secret, unpredictable CSRF token is generated by the server-side and transmitted to the client-side in such a way that it is included in a subsequent HTTP request made by the client and if request made without token then that request will be treated as illegitimate request and action will not be performed. So, Here is the example code :-

config.php

index.php

Output

CSRF-Prevention-1

CSRF-Prevention-2

NetBeans Project Download

Thank you for stopping by

Please don’t forget share if you like it

Rajesh Kumar Sahanee
I am a passionate Java Developer and I like Computer Programming. I love to do some interesting experiments and listening music in my free time.
https://www.zatackcoder.com

Comments

zatackcoder
Top

  Â