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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:26:06+00:00 2026-06-08T23:26:06+00:00

So i am trying to wrap my head around this logic. this is code

  • 0

So i am trying to wrap my head around this logic. this is code that is on a form processing script. What i want to do is send form data to one of these urls randomly. I was reading to use the switch case logic, but when i use the code you see below, it submits the form data to all 3 URLS. Is there a way so that it only sends to one of them?

function post_to_url($url, $data) {
$fields = '';
foreach($data as $key => $value) { 
  $fields .= $key . '=' . $value . '&'; 
}
rtrim($fields, '&');

$post = curl_init();

curl_setopt($post, CURLOPT_URL, $url);
curl_setopt($post, CURLOPT_POST, 1);
curl_setopt($post, CURLOPT_POSTFIELDS, $fields);


$result = curl_exec($post);

curl_close($post);
}



return $result;

$x = rand(1,3);

switch ($x) {
    case 1:
        post_to_url("http://examplesite1.com/cgi-bin/maxuseradmin.cgi", $data2);
        break;

    case 2:
        post_to_url("http://examplesite2?fid=6646588e54", $data3);
        break;

    case 3:
        post_to_url("http://examplesite1?fid=2fb44e3888", $data4);
        break;
    }

the $data variables are arrays –Thanks for the help

  • 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-08T23:26:07+00:00Added an answer on June 8, 2026 at 11:26 pm

    You’re posting to all 3 pages, then setting the value of what it returns to $ar1 $ar2 and $ar3.

    Store your options in an array, then call post_to_url() once.

    $urls = array(
        array("http://examplesite1.com/cgi-bin/maxuseradmin.cgi", $data2),
        array("http://examplesite2?fid=6646588e54", $data3),
        array("http://examplesite1?fid=2fb44e3888", $data4)
    );
    
    $x = rand(0,2);
    post_to_url ($urls[$x][0], $urls[$x][1]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to wrap my head around this, using Jquery I want to browse
I am trying to wrap my head around this one this morning. I am
I'm trying to wrap my head around this and I think the easiest way
I have been trying to wrap my head around this issue for the past
I am trying to wrap my head around whether this is possible. My hunch
I can't wrap my head around this for some reason. I'm trying to get
I am trying to wrap my head around database normalization. This is my first
I've been trying to wrap my head around this concept and how to route
I am trying wrap my head around how data is being served to Project
I'm trying to wrap my head around this to make the correct design decisions.

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.