채택완료

location 두 URL로 순차적으로 실행되게 할수 있을까요?

2024-04-18 (목) 17:05:52 21,822

$redirect_url = "https://www.test.com/oms/odorAnls/insertSensorOu.do";

header("Location: " . $redirect_url . "?FARM=" . $FARM . "&SENSOR=" . $SENSOR . "&VALUE=" . $VALUE);

header("Location: " . $redirect_url . "?FARM=" . $FARM . "&SENSOR=" . $SENSOR2 . "&VALUE=" . $VALUE2);

이렇게 하면 하나만 실행 되던지 FAIL

하나를 주석처리하면 SUCCESS

두 곳에 순차적으로 실행되게 소스수정 안될까요?

|

답변 5개 / 댓글 5개

채택된 답변
+20 포인트
Copy
<?php
function send_url($url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_exec($ch);
    curl_close($ch);
}

 

$redirect_url = "https://www.test.com/oms/odorAnls/insertSensorOu.do";
// header("Location: " . $redirect_url . "?FARM=" . $FARM . "&SENSOR=" . $SENSOR . "&VALUE=" . $VALUE);
// header("Location: " . $redirect_url . "?FARM=" . $FARM . "&SENSOR=" . $SENSOR2 . "&VALUE=" . $VALUE2);

 

send_url($redirect_url . $redirect_url . "?FARM=" . $FARM . "&SENSOR=" . $SENSOR . "&VALUE=" . $VALUE);
send_url($redirect_url . $redirect_url . "?FARM=" . $FARM . "&SENSOR=" . $SENSOR2 . "&VALUE=" . $VALUE2);
?>

답변에 대한 댓글 4개

소스를 주신데로 넣었는데 아무런 반응이 없는데요?
둘중 하나도 실행이 안되는듯합니다.
호출이 정확히 되었는지 여부는 호출을 받는쪽에서 확인해볼수 있습니다.
호출 하는쪽에서 어떠한 반응이 있어야 한다면 인위적으로 만들어볼수 있습니다.
네 다시한번 확인해서 처리해보고 이야기 드리겠습니다.
<?php
// cURL 핸들 생성
$ch1 = curl_init();
$ch2 = curl_init();

// 첫 번째 URL 요청
curl_setopt($ch1, CURLOPT_URL, 'https://example.com/redirect1');
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch1, CURLOPT_FOLLOWLOCATION, true);

// 두 번째 URL 요청
curl_setopt($ch2, CURLOPT_URL, 'https://example.com/redirect2');
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, true);

// cURL 요청 실행
$response1 = curl_exec($ch1);
$response2 = curl_exec($ch2);

// 에러 확인
if (curl_errno($ch1) !== 0) {
echo "cURL 에러 1: " . curl_error($ch1);
}

if (curl_errno($ch2) !== 0) {
echo "cURL 에러 2: " . curl_error($ch2);
}

// cURL 핸들 닫기
curl_close($ch1);
curl_close($ch2);

// 응답 출력
echo "첫 번째 URL 응답: " . $response1 . "\n";
echo "두 번째 URL 응답: " . $response2 . "\n";
?>

AI가 만들어준 소스로 일단 해결했습니다.
도움주셔서 감사합니다.

원하시는것이... 대략 이런 형태 일듯하네요.

테스팅은 안했습니다. 디버깅 하세요.

Copy
<?php

$redirect_url = "https://www.test.com/oms/odorAnls/insertSensorOu.do";

$redirect_url1 = $redirect_url."?FARM=".$FARM."&SENSOR=".$SENSOR."&VALUE=".$VALUE;

$redirect_url2 = $redirect_url."?FARM=".$FARM."&SENSOR=".$SENSOR2."&VALUE=".$VALUE2;

?>

<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js'></script>

<script>

function send_data(d1,d2=false){

    $.ajax({

            url: d1,

            type: "GET",

            success: function(result) {

                if(d2 != false) location.href = d2;

            }

    })

}

$(document).ready(function() {

    const Url1 = '<?=redirect_url1?>';

    const Url2 = '<?=redirect_url2?>';

    send_data(Url1,Url2);  

})

</script>

이동전 페이지에서 iframe를 이용해서 b페이지 열고 1초후 a페이지로 이동 시켜보세요.

2024-04-18 (목) 20:32:53

'불가' 일 듯 합니다.

A 페이지에서 B 페이지로 리다이렉트 되는 순간부터,

그 이후 처리는 B 페이지 처리입니다.

안녕하세요.

아래의 내용을 한번 참고해 보시겠어요?

1. 첫번째 리다이렉트 페이지

Copy
<?php
$redirect_url = "https://www.example.com/first-redirect.php";
header("Location: " . $redirect_url . "?FARM=" . urlencode($FARM) . "&SENSOR=" . urlencode($SENSOR) . "&VALUE=" . urlencode($VALUE));
exit;
?>

2. 첫번째 리다이렉트를 처리하는 페이지

Copy
<!DOCTYPE html>
<html>
<head>
    <title>Redirecting...</title>
    <script type="text/javascript">
        setTimeout(function() {
            window.location.href = "https://www.test.com/oms/odorAnls/insertSensorOu.do?FARM=<?php echo urlencode($_GET['FARM']); ?>&SENSOR=<?php echo urlencode($_GET['SENSOR2']); ?>&VALUE=<?php echo urlencode($_GET['VALUE2']); ?>";
        }, 1000); // 1000ms = 1초 후 두 번째 URL로 리다이렉트
    </script>
</head>
<body>
    Redirecting...
</body>
</html>

답변에 대한 댓글 1개

한페이지에서 처리되어야 합니다.

답변을 작성하려면 로그인이 필요합니다.