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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:16:23+00:00 2026-05-16T21:16:23+00:00

I’m developing an application for a client’s website. Here’s the story, this company uses

  • 0

I’m developing an application for a client’s website.
Here’s the story, this company uses an application/HDD called synology that is basically an HDD box connected to the internet and gives access to files to clients with pre-created accounts.
This interface is written in CGI and I have no access to the box (different network and location from the website).

What we wanna do is allow a login form from the main website (I’m building) bypassing (at least to the users :D) the application login form.

I obviously can’t do a jQuery ajax request to different domains, it won’t work. So what I did is

1) Form on the website working with jQuery:

$("#login_submit").click(function(){
    var username= $("input#login_username").val();
    var passwd= $("input#login_passwd").val();
    var post_string = "username=" + username + "&passwd=" + passwd ;
    $.ajax({
        type : "POST",
        url: "login.php",
        data : post_string,
        success: function(response){

            if (response){
                $('.result').html("OK");
                window.location = "http://XX.XX.net:5000/webman/index.cgi";
             }
             else {
                 $('.result').html("INVALID");
             }
        }
    })
    return false;
}

2) Call a login.php page on submit passing user and password via POST, the PHP page makes a HTTP POST request to the remote synology server and gives me a response in JSON apparently (?) that I convert to a PHP array so that I can see if the “success” key is true or false,
if true the jquery code will print an OK message and redirect to the remote sylonogy server where I can access my data-logged in!

<?php
function do_post_request($url, $data, $optional_headers = null)
{
  $params = array('http' => array(
              'method' => 'POST',
              'content' => $data
            ));
  if ($optional_headers !== null) {
    $params['http']['header'] = $optional_headers;
  }
  $ctx = stream_context_create($params);
  $fp = @fopen($url, 'rb', false, $ctx);
  if (!$fp) {
    throw new Exception("Problem with $url, $php_errormsg");
  }
  $response = @stream_get_contents($fp);
  if ($response === false) {
    throw new Exception("Problem reading data from $url, $php_errormsg");
  }
  return $response;
}

if ($_SERVER['REQUEST_METHOD'] == "POST"){
    $username = $_POST["username"];
    $passwd = $_POST["passwd"];

    $response =json_decode(do_post_request($url = "http://XX.XX.net:5000/webman/login.cgi", $data = "username=".$username."&passwd=".$passwd), true);

            if($response["success"]){
                $send = true;
            }
            else {
                $send = false;
            }
        echo  $send;
}

The problem here is that the login.cgi page is supposed to set a session cookie for that server but using that PHP request it just won’t. It will give a response but it won’t set the cookie to the browser. Do you have any idea what I can do to imitate a POST browser request and set the cookie while maintaining that jquery function? maybe I should set some headers?
If make a simple form to that login.cgi as “action” the session cookie is but the user will of course remain on that page that I can’t change since I have no access to it.

  • 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-16T21:16:23+00:00Added an answer on May 16, 2026 at 9:16 pm

    Use stream_get_meta_data() to extract the HTTP headers returned from the server<->synology requests. If the rest of your code is working properly with the proper synology urls/parameters, the headers returned from the login request should contain the session cookie necessary to authenticate further requests on the synology box.

    You can then store this in the session file for the server<->user communications, and haul it out for subsequent requests.

    comment followup:

    yes, exactly. The curl-initiated requests are done purely server-side and will not involve the client at all. While you CAN retrieve the synology session/access cookie via curl, there’s no way to send that cookie to the client such that it’ll look like it came from the synology box directly.

    For instance, let’s pretend the synology response cookie header looks like this:

    Set-Cookie: sessionID=blahblahblah; path=/; domain=synologybox.com
    

    You extract the session ID and forward it to the client:

    setcookie("sessionID", 'blahblahblah', 360000, '/');
    

    then the client will store it as having come from yourserver.com, not synologybox.com. Also, you wouldn’t be able to set the domain via the setcookie call:

    setcookie("sessionID", 'blahblahblah', 360000, '/', 'synologybox.com')
    

    This won’t work, as the server<->client request is coming from yourserver.com, which is nowhere near the same as synologbox.com.

    Without any access to the synology box to hack in extra authentication facilities, you’re most likely stuck having to build an entire proxy version of the synology interface.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.