Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7159063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:10:07+00:00 2026-05-28T13:10:07+00:00

I am working on the security issues for my web application. And i have

  • 0

I am working on the security issues for my web application. And i have to deal with the CSRF. Gone through many refrences but some of them uses Cookie while other uses SESSION .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:10:07+00:00Added an answer on May 28, 2026 at 1:10 pm

    For CSRF prevention you need to store a shared token on both the client and the server, so when the client makes a request, their submitted value can be compared with your known value.

    For the client side you could use a cookie, or a hidden form field (personally I prefer the hidden field – so I don’t pile up cookies for every form in the clients browser).

    On the server you could use the session (where the session id is stored in a cookie anyway) or store it in a database (although you’d probably need to use the session to identify the record that belongs to the client).

    Here’s some very basic example CSRF prevention code for you.

    session_start();
    
    if (isset($_POST) && isset($_POST['csrf'])) {
        var_dump($_POST, $_SESSION);
        if ($_POST['csrf'] == $_SESSION['CSRF_FORM1']) {
            print 'You win cookies!';
        }
        else {
            print 'You win a bucket of vomit!';
        }
    }
    
    $_SESSION['CSRF_FORM1'] = md5(microtime());
    
    ?>
    <form action="" method="post">
        <input type="hidden" name="csrf" value="<?php print $_SESSION['CSRF_FORM1']; ?>" />
        <input type="submit" value="Good form Jack!" />
    </form>
    
    <form action="" method="post">
        <input type="hidden" name="csrf" value="badValue" />
        <input type="submit" value="Bad form Jack!" />
    </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working on securing a web application using spring-security 3.0. I have
I have a problem with SSRS Report Manager web application(but again I see this
Our web application uses Windows Integrated Authentication (aka NTLM Auth) for security. It's working
I have a java web application that use spring security for log in users,
I'm working on a security project in Javascript (something I honestly have not used),
The system I am currently working on requires some role-based security, which is well
We have recently implemented htmlpurifier in our web-based application. Earlier we used to have
I have a pretty big web application that I created last year using ASP.NET
All, I am trying to add Spring Security(3.0.7) to my web application(Spring 3.0.6, Tiles
I have a applet that runs with no issue in asp.net web application ...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.