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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:30:36+00:00 2026-05-20T17:30:36+00:00

I am trying to login to a form which has a hidden hash field.

  • 0

I am trying to login to a form which has a hidden hash field. The problem is when I curl the page to get the hash, and when I include it as the post value in my next curl call (to the same page), the hash is not valid anymore since the succeeding curl cal is like the page refreshed already and it regenerated a new hash.

So how do I get the hash without simulating a refreshed page?

here is my sample code:

<?php
$la = new LoginAuth('http://site.tld/auth.php', 'username', 'password');
$result = $la->auth(0);
echo $result;

class LoginAuth
{
  public $url;
  public $usr;
  public $pwd;
  public $status;
  private $last_url;

  public function __construct($url, $usr, $pwd)
  {
    $this->url = $url;
    $this->usr= $usr;
    $this->pwd= $pwd;
  }

  public function get_hash()
  {
    $output = $this->curl($this->url, $this->last_url);
    $hash = $this->match('!<input.*?name="hash".*?value="(.*?)"!ms', $output, 1);
    return $hash;
  }

  public function auth($server)
  {
    $hash = $this->get_hash();
    $auth_data = 'username=' . $this->usr . '&password=' . $this->pwd . '&server=' . $server . '&hash=' . $hash;
    $output = $this->curl($this->url, $this->last_url, $auth_data);
    $this->status = $output;
    return $output;
  }

  private function curl($url, $referer = null, $post_param = null)
  {
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (iPhone; U; CPU iPhone OS 2_2_1 like Mac OS X; en-us) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.1.1 Mobile/5H11 Safari/525.20");

    if($referer)
      curl_setopt($ch, CURLOPT_REFERER, $referer);

    if(!is_null($post_param))
    {
      curl_setopt($ch, CURLOPT_POST, true);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $post_param);
    }

    $html = curl_exec($ch);
    $this->last_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
    curl_close($ch);
    return $html;
  }

  private function match($regex, $str, $out_ary = 0)
  {
    return preg_match($regex, $str, $match) == 1 ? $match[$out_ary] : false;
  }
}
/* End of file auth.php */
/* Location: ./auth.php */
  • 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-20T17:30:37+00:00Added an answer on May 20, 2026 at 5:30 pm

    The server is probably sending you a Set-Cookie header for a session id. It will store the hash someplace locally, and then compare the one you submit to that one IF you supply the session cookie back to it.

    You’ll need to read the session cookie out of the get_hash() response, and then submit it back in your auth() call.

    I’d fire up firebug and check out the headers being sent back and forth when you do it by hand, there may be some other important ones as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to post to the login form of an application on another subdomain
Trying to create an automatic login to a webpage which takes HTTP POST input
I am trying to redirect Spring Security to a custom login page which GWT
I am new to zend. I am trying to create login form using zend
I'm playing around with the physics login form from Doug Mccune's blog I'm trying
Im trying to create a iPhone Objective C login page using PHP/MySQL to authenticate.
I have a page which displays a form that a logged-in user can use
I'm trying to make a form to login users into my webpage using mysql
I am trying to get the selected card number that has logged in via
I'm currently trying out Silverlight with RIA Services. I'm implementing a simple login form.

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.