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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:05:05+00:00 2026-06-09T08:05:05+00:00

strange problem, i’m opening a connection with fsockopen() to a page, that page has

  • 0

strange problem, i’m opening a connection with fsockopen() to a page,
that page has a header(location:xx) to the same page (i’m just refreshing the script), but it’seems that the redirect isn’t working…

obviously everything is working if i’m replicating it with a browser…

some code:

CONNECTION PAGE:

$socketcon = fsockopen($_SERVER['HTTP_HOST'],80,$errorno,$errorstr,10);
if($socketcon) {
    $socketdata = "GET http://www.example.com/test2.php HTTP/1.0\r\nHost: ".$_SERVER['HTTP_HOST']."\r\nConnection: Close\r\n\r\n";
    fwrite($socketcon,$socketdata); 
    fclose($socketcon);
}

CONNECTED PAGE (test2.php):

<?
//other code (working fine)

if($_GET["AAA"]){

     //REDIRECT WORKED !

} else {
     header("location:test2.php?AAA=1");   //same page but with a get param
}
?>

the REDIRECT WORKED part never get executed…

any suggestions ?

EDIT: the connection MUST be asynchronous

  • 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-09T08:05:06+00:00Added an answer on June 9, 2026 at 8:05 am

    Consider Is making asynchronous HTTP requests possible with PHP? which is a similar question.

    Using exec()-family functions might be a good bet if you don’t need return values; you can just call curl appended by & and it’ll run in the background.

    If you really, truly want to do this in PHP, you can either: spawn a new process (using pcntl_fork()) or handle redirects yourself.

    To handle redirects you’ll need to:

    1. Determine what your response code is by looking at the first three characters read from the stream. A 200 means sucess, anything in the 300s means partial success.
    2. Once you’ve found a 302 (or 307) in the first three characters, search for a location header. This will match the regex /\s*location:\s*(.+)$/m, I believe.
    3. Validate that the URL you have from the location field matches your expectations and is trustworthy. It should be an absolute URL, but you’ll need to check it for a safe server, safe port, safe URL and safe parameters. parse_url() may come in handy, but does not check for potential security issues.
    4. Open a new connection to the new URL matched above (or, if it’s the same host and you’re using HTTP 1.1 with Keep-Alive, reuse your connection) to send the appropriate data.
    5. Deal with any results/clean-up as required.

    You can see this is very complex. This will also be recursive. What you’re really talking about doing is writing a rudimentary HTTP parser in PHP. This is not a good idea – use cURL and find some other way to make it asynchronous.

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

Sidebar

Related Questions

Strange problem that just starting to happen on a SL/WCF RIA Services project that
Very strange problem with my iPhone App. We have an App that has been
I have a strange problem on ipv6 connection. I write down a simple client
I'm having a strange problem that I can't work out and wonder if anybody
A strange problem occurred yesterday on a production system which has been running fine
I've a very strange problem, i try to disable a toggle button for just
I have a strange problem: I have a CSV file that I read correctly
strange problem with php on windows... my application loads a 'core' file that loads
I have a strange problem that I've never encountered before, I have data in
I have a strange problem that I can't get my head around: I have

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.