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 8717717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:21:51+00:00 2026-06-13T06:21:51+00:00

I need to restrict POST request from specific domain. As far I know, HTTP_REFERER

  • 0

I need to restrict POST request from specific domain. As far I know, HTTP_REFERER checking cannot be a good solution because it can be spoofed. So what can be the good solution when two different websites from different technology and web servers will work together?

  • 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-06-13T06:21:52+00:00Added an answer on June 13, 2026 at 6:21 am

    Heres a method you could try, by adding a hidden field within your form that is session values that are set server side. This way if the form has not originated from your server the session would not have been set and the values would not match.

    Example:

    <?php 
    session_start();
    
    if($_SERVER['REQUEST_METHOD']=='POST'){
        if(isset($_SESSION['security']) && 
           isset($_SESSION['security_key']) && 
           !empty($_POST[$_SESSION['security_key']]) && 
           $_POST[$_SESSION['security_key']] == $_SESSION['security'])
        {
            /* forms post is from domain as session would 
               not have been started and security would not have been set */
            echo 'good';
        }else{
            /* forms post is not from domain */
            echo 'bad';
        }
        $_SESSION['security_key'] = sha1(microtime(true)+1);
        $_SESSION['security'] = sha1(microtime(true));
    }else{
        $_SESSION['security_key'] = sha1(microtime(true)+1);
        $_SESSION['security'] = sha1(microtime(true));
    }
    ?>
    
    <form method="POST" action="">
      <input type="hidden" name="<?=$_SESSION['security_key'];?>" value="<?=$_SESSION['security'];?>"/>
      <p><input type="text" name="Text" size="20"><input type="submit" value="Submit"></p>
    </form>
    

    Alternatively you could use encryption instead of hashing, that way you could check the values:

    <?php 
    session_start();
    define('SECURE_KEY',$_SERVER['SERVER_NAME']);
    
    if($_SERVER['REQUEST_METHOD']=='POST'){
        if(isset($_SESSION['security_key']) && isset($_SESSION['security'])){
            //Decrypt
            list($servername,$userip) = explode('X',decrypt(base64_decode($_SESSION['security'])));
    
            //Check the decrypted values
            if($servername == $_SERVER['SERVER_NAME'] && $userip == $_SERVER['REMOTE_ADDR']){
                /* forms post is from domain as session would
                not have been started and security would not have been set */
                echo 'good';
            }else{
                echo 'bad';
            }
    
        }else{
            /* forms post is not from domain */
            echo 'bad';
        }
    
        $_SESSION['security_key'] = sha1(microtime(true));
        $_SESSION['security'] = base64_encode(encrypt($_SERVER['SERVER_NAME'].'X'.$_SERVER['REMOTE_ADDR']));
    }else{
        $_SESSION['security_key'] = sha1(microtime(true));
        $_SESSION['security'] = base64_encode(encrypt($_SERVER['SERVER_NAME'].'X'.$_SERVER['REMOTE_ADDR']));
    }
    
    function encrypt($string, $key = 'PrivateKey', $secret = 'SecretKey', $method = 'AES-256-CBC') {
        // hash
        $key = hash('sha256', $key);
        // create iv - encrypt method AES-256-CBC expects 16 bytes
        $iv = substr(hash('sha256', $secret), 0, 16);
        // encrypt
        $output = openssl_encrypt($string, $method, $key, 0, $iv);
        // encode
        return base64_encode($output);
    }
    
    function decrypt($string, $key = 'PrivateKey', $secret = 'SecretKey', $method = 'AES-256-CBC') {
        // hash
        $key = hash('sha256', $key);
        // create iv - encrypt method AES-256-CBC expects 16 bytes
        $iv = substr(hash('sha256', $secret), 0, 16);
        // decode
        $string = base64_decode($string);
        // decrypt
        return openssl_decrypt($string, $method, $key, 0, $iv);
    }
    ?>
    
    <form method="POST" action="">
      <input type="hidden" name="<?=$_SESSION['security_key'];?>" value="<?=$_SESSION['security'];?>"/>
      <p><input type="text" name="Text" size="20"><input type="submit" value="Submit"></p>
    </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to restrict the development users from creating new schedules for SQL Agent
I need to restrict users in my application to login from a one computer
I need to restrict the number of customer bo's returned from the database as
I need to restrict respond_to to JSON only, because I am constructing a web
I need to restrict a controller in CI 2 to only run from command
I need to restrict access to my application to only one specific user account.
Good afternoon, I need help to solve the following problem: I need to restrict
I have the program and I need to restrict it. But I don't know
I need to restrict users from opening an Excel (.xls) file with notepad. I
I need to restrict the resulting rows from each table/object depending on my security

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.