테스트 사이트 - 개발 중인 베타 버전입니다

관련링크 2번째에 랜덤으로 링크 뿌려주기 채택완료

파워스피드2 1년 전 조회 1,966

setup.php 는 아래처럼

link_1 = "https://link1.com"; link_2 = "https://link2.com"; link_3 = "https://link3.com"; link_4 = "https://link4.com"; link_5 = "https://link5.com"; link_6 = "https://link6.com"; link_7 = "https://link7.com"; link_8 = "https://link8.com"; link_9= "https://link9.com"; link_10 = "https://link10.com";

 

A사이트에 올려두고

 

B사이트에서 A사이트의 주소를 랜덤으로 관련 링크2에 넣어줄수 있는 방법이 있을까요? 새로고침 할때마다 주소는 랜덤으로 계속 바뀌게요.

 

1번 사이트에 링크주소를 여려개 올린다.

 

2번 사이트에서 1번사이트에 링크를 랜덤하게 가져와 관련링크 2번째 란에 넣어준다.

 

링크값은 새로고침 할때마다 랜덤하게 바뀐다. 

 

https://joytv77.store/newmv/%EC%84%9C%EC%9A%B8%EC%9D%98-%EB%B4%84/

(예시 사이트 입니다)

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

답변 4개

채택된 답변
+20 포인트
1년 전

curl을 이용해서 링크를 가져오는 것이 정상절차인데 자바스크립트를 이용해도 됩니다

setup.php

https://link1.com",         "https://link2.com",         "https://link3.com",         "https://link4.com",         "https://link5.com",         "https://link6.com",         "https://link7.com",         "https://link8.com",         "https://link9.com",         "https://link10.com"];

shuffle($linkarr); echo "link ='{$linkarr[0]}'";     

 

===============view에서

           

$view['link'][2] = "link2"; $view['link_href'][2] = "link2"; $view['link_hit'][2] =0;//----------추가                 for ($i=1; $i<=count($view['link']); $i++) {                    ?>                    

                       
                                                      
                       
로그인 후 평가할 수 있습니다

답변에 대한 댓글 7개

파워스피드2
1년 전
<------- id 추가 이부분에는 어떤 아이디를 넣어줘야 하느ㄴ건지요?
파워스피드2
1년 전
https://gogumatv.store/movie/%EB%8A%91%EB%8C%80%EC%9D%98-%EC%9C%A0%ED%98%B9/

크론탭 파싱으로 불러온 내용이 링크1에 적용이 되고 링크2는 아이디 추가 라고만 뜨는데요;;
균이
1년 전
--------------하단 자바스크립트 부분 어디에 넣었나요?
파워스피드2
1년 전
관련링크 끝 밑에 넣었습니다.
파워스피드2
1년 전
[code]

<?php if(isset($view['link'][1]) && $view['link'][1]) { ?>

<!-- 관련링크 시작 { -->
<li class="d-table-row border-top border-bottom">
<div class="d-none d-sm-table-cell text-center px-3 py-2 nw-6">
링크
</div>
<div class="d-table-cell px-3 py-2">
<?php

//링크
$cnt = 0;

$view['link'][2] = "link2"; $view['link_href'][2] = "link2"; $view['link_hit'][2] =0;//----------추가
for ($i=1; $i<=count($view['link']); $i++) {
?>
<div class="d-flex my-1">
<div class="px-0">
<i class="fa fa-link" aria-hidden="true"></i>
</div>
<div class="pl-3 flex-grow-1 text-break-all">
<a href="<?php echo $view['wr_link2'][$i] ?>" target="_blank" id="link<?php echo $i?>">
<?php echo get_text($view['link'][$i]) ?>
<?php if($view['link_hit'][$i]) { ?>

<div class="d-flex my-1">
<div class="px-0">
<i class="fa fa-link" aria-hidden="true"></i>
</div>
<div class="pl-3 flex-grow-1 text-break-all">
<a href="<?php echo $view['wr_link2'][$i] ?>" target="_blank">
<?php echo get_text($view['wr_link2'][$i]) ?>
<?php if($view['link_hit'][$i]) { ?>
<span class="count-plus orangered"><?php echo $view['link_hit'][$i] ?></span>
<span class="sr-only">회 연결</span>
<?php } ?>
</a>
</div>
</div>
<?php
}
}
?>
</div>
</li>
<!-- } 관련링크 끝 -->

<script src="http://***.kr/setup.php"></script>
<script>
$("#link2").attr("href", link);
$("#link2").text(link)
</script>

[/code]

어디가 잘못된걸까요?;;
균이
1년 전
주소창에 직접 http://***.kr/setup.php <--접속하면
link='https://link3.com' <-- 이런 모양으로 보여야 됩니다
파워스피드2
1년 전
오타가 있었네요. 되긴 됩니다. 되는데 링크1과 링크2가 같이 나오는데 이건 어떯게 수정으 해야 하죠?ㅠ.ㅠㅠ.

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

저렴한 웹호스팅 중에는 php 의 file_get_contents 나 curl 을 허용해 주지 않는 데가 꽤 있습니다.

그러니 사이트를 랜덤으로 안전하게 튕기려면

프론트에서 자바스크립트로 튕기는 것이 코드는 길지만 더 효과가 확실합니다. 

즉 저 변수들을 js 파일안에 심어 놓고 불러와야 안전하지 php 파일에 심어 놓으면 cutl 등이 막혀 있으면 당연히 안 될 것입니다.

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

파워스피드2
1년 전
일단 호스팅은아니구요 통큰아이 서버사용하고 있습니다.

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

이렇게만 뜨고 아무런것도 출력이 되질 않네요.ㅠ.ㅠ

로그인 후 평가할 수 있습니다

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

1년 전

A-site setup.php

</p>

<p><?php

$wrap = [

    'links' => [

        "<a href="https://link1.com"," target="_blank" rel="noopener noreferrer">https://link1.com",</a>

        "<a href="https://link2.com"," target="_blank" rel="noopener noreferrer">https://link2.com",</a>

        "<a href="https://link3.com"," target="_blank" rel="noopener noreferrer">https://link3.com",</a>

        "<a href="https://link4.com"," target="_blank" rel="noopener noreferrer">https://link4.com",</a>

        "<a href="https://link5.com"," target="_blank" rel="noopener noreferrer">https://link5.com",</a>

        "<a href="https://link6.com"," target="_blank" rel="noopener noreferrer">https://link6.com",</a>

        "<a href="https://link7.com"," target="_blank" rel="noopener noreferrer">https://link7.com",</a>

        "<a href="https://link8.com"," target="_blank" rel="noopener noreferrer">https://link8.com",</a>

        "<a href="https://link9.com"," target="_blank" rel="noopener noreferrer">https://link9.com",</a>

        "<a href="https://link10.com"," target="_blank" rel="noopener noreferrer">https://link10.com",</a>

    ]

];</p>

<p> </p>

<p>echo json_encode($wrap);

?></p>

<p>

 

B-site

</p>

<p><?php

$content = file_get_contents('<a href="http://A-site.com/setup.php');" target="_blank" rel="noopener noreferrer">http://A-site.com/setup.php');</a>

if ($content !== false) {

    $data = json_decode($content, true);

    $links = $data['links'];

    $link = mt_rand(0, count($links) - 1);

    echo $links[$link];

}

?></p>

<p>

로그인 후 평가할 수 있습니다

답변에 대한 댓글 14개

파워스피드2
1년 전
B-site는 view.skin.php 어디에 입력을 해야 하는건가요?
배르만
1년 전
B-site view.skin.php 의 소스를 알수 없으므로
어디에 어떤방식으로 적용을 해야 하는지는 본인이 판단해야 합니다.
파워스피드2
1년 전
게시판 관련링크 쪽에 랜덤링크를 보여주게 하려고 합니다.
[code]
<!-- 관련링크 시작 { -->
<li class="d-table-row border-top border-bottom">
<div class="d-none d-sm-table-cell text-center px-3 py-2 nw-6">
링크
</div>
<div class="d-table-cell px-3 py-2">
<?php
//링크
$cnt = 0;
for ($i=1; $i<=count($view['link']); $i++) {
if ($view['link'][$i]) {
$cnt++;
?>
<div class="d-flex my-1">
<div class="px-0">
<i class="fa fa-link" aria-hidden="true"></i>
</div>
<div class="pl-3 flex-grow-1 text-break-all">
<a href="<?php echo $view['link_href'][$i] ?>" target="_blank">
<?php echo get_text($view['link'][$i]) ?>
<?php if($view['link_hit'][$i]) { ?>
<span class="count-plus orangered"><?php echo $view['link_hit'][$i] ?></span>
<span class="sr-only">회 연결</span>
<?php } ?>
</a>
</div>
</div>
<?php
}
}
?>
</div>
</li>
<!-- } 관련링크 끝 -->
[/code]
뷰스킨 에서 관련링크에 삽입을 하고 싶습니다.
배르만
1년 전
다음 예시코드를 참조해 적절히 가공하면 될것 같습니다.
[code]
<?php
$content = file_get_contents('http://A-site.com/setup.php');

$other_links = [''];

if ($content !== false) {
$data = json_decode($content, true);
$other_links = $data['links'];
// $other_link = mt_rand(0, count($other_links) - 1);
// echo $other_links[$other_link];
}
?>

<!-- 관련링크 시작 { -->
<li class="d-table-row border-top border-bottom">
<div class="d-none d-sm-table-cell text-center px-3 py-2 nw-6">
링크
</div>
<div class="d-table-cell px-3 py-2">
<?php
//링크
$cnt = 0;
for ($i=1; $i<=count($view['link']); $i++) {
if ($view['link'][$i]) {
$cnt++;

if ($i == 2) {
$other_link = mt_rand(0, count($other_links) - 1);
$view['link_href'][$i] = $other_links[$other_link];
$view['link'][$i] = $other_links[$other_link];
}
?>
<div class="d-flex my-1">
<div class="px-0">
<i class="fa fa-link" aria-hidden="true"></i>
</div>
<div class="pl-3 flex-grow-1 text-break-all">
<a href="<?php echo $view['link_href'][$i] ?>" target="_blank">
<?php echo get_text($view['link'][$i]) ?>
<?php if($view['link_hit'][$i]) { ?>
<span class="count-plus orangered"><?php echo $view['link_hit'][$i] ?></span>
<span class="sr-only">회 연결</span>
<?php } ?>
</a>
</div>
</div>
<?php
}
}
?>
</div>
</li>
<!-- } 관련링크 끝 -->
[/code]
파워스피드2
1년 전
<a href="<?php echo $view['link_href'][$i] ?>
이부분이 링크 부분인거 같은데 여길 어떻게 고쳐야 할질 모르겠네요.ㅠ.ㅠ
배르만
1년 전
다음처럼 주석처리를 하면 2번째 링크만이 아닌 모든 링크가 교체됩니다.
[code]
//if ($i == 2) {
$other_link = mt_rand(0, count($other_links) - 1);
$view['link_href'][$i] = $other_links[$other_link];
$view['link'][$i] = $other_links[$other_link];
//}
[/code]
파워스피드2
1년 전
[code]
<?php
$content = file_get_contents('https://site.com/setup.php');

$other_links = [''];

if ($content !== false) {
$data = json_decode($content, true);
$other_links = $data['links'];
// $other_link = mt_rand(0, count($other_links) - 1);
// echo $other_links[$other_link];
}
?>
<!-- 관련링크 시작 { -->
<li class="d-table-row border-top border-bottom">
<div class="d-none d-sm-table-cell text-center px-3 py-2 nw-6">
링크
</div>
<div class="d-table-cell px-3 py-2">
<?php
//링크
$cnt = 0;
for ($i=2; $i<=count($view['link']); $i++) {
if ($view['link'][$i]) {
$cnt++;

//if ($i == 2) {
$other_link = mt_rand(0, count($other_links) - 1);
$view['link_href'][$i] = $other_links[$other_link];
$view['link'][$i] = $other_links[$other_link];
// }
?>
<div class="d-flex my-1">
<div class="px-0">
<i class="fa fa-link" aria-hidden="true"></i>
</div>
<div class="pl-3 flex-grow-1 text-break-all">
<a href="<?php echo $view['link_href'][$i] ?>" target="_blank">
<?php echo get_text($view['link'][$i]) ?>
<?php if($view['link_hit'][$i]) { ?>
<span class="count-plus orangered"><?php echo $view['link_hit'][$i] ?></span>
<span class="sr-only">회 연결</span>
<?php } ?>
</a>
</div>
</div>
<?php
}
}
?>
</div>
</li>
<!-- } 관련링크 끝 -->
[/code]

아무런 내용도 출력이 되지 않습니다.ㅠ.ㅠ
셋업파일 주소부분은 제대로 넣고 했는데 아무것도 출력이 되지 않습니다.ㅠ.ㅠ
배르만
1년 전
먼저 기존 링크가 존재 하는지 확인이 필요할것 같고
[code]
if (count($view['link']) > 0) {
echo 'link count ' . count($view['link']);
} else {
echo 'link count 0';
}
[/code]

다른곳에서 가져오는 방식 대신 다음처럼 확인해볼수도 있습니다.
[code]
//$content = file_get_contents('http://A-site.com/setup.php');

//$other_links = [''];
$other_links = [
"https://link1.com",
"https://link2.com",
"https://link3.com",
"https://link4.com",
"https://link5.com",
"https://link6.com",
"https://link7.com",
"https://link8.com",
"https://link9.com",
"https://link10.com",
];

//if ($content !== false) {
// $data = json_decode($content, true);
// $other_links = $data['links'];
// // $other_link = mt_rand(0, count($other_links) - 1);
// // echo $other_links[$other_link];
//}
[/code]
파워스피드2
1년 전
링크1에는 기존링크가 들어가 있습니다. 그래서 링크2에 랜덤으로 링크를 출력하고 싶습니다.ㅠ.ㅠ 아 초보자에 삶이란 너무 힘드네요.ㅠ.ㅠ
파워스피드2
1년 전
[code]
<?php

//$content = file_get_contents('http://A-site.com/setup.php');

//$other_links = [''];
$other_links = [
"https://link1.com",
"https://link2.com",
"https://link3.com",
"https://link4.com",
"https://link5.com",
"https://link6.com",
"https://link7.com",
"https://link8.com",
"https://link9.com",
"https://link10.com",
];

//if ($content !== false) {
// $data = json_decode($content, true);
// $other_links = $data['links'];
// // $other_link = mt_rand(0, count($other_links) - 1);
// // echo $other_links[$other_link];
//}
?>


<!-- 관련링크 시작 { -->
<li class="d-table-row border-top border-bottom">
<div class="d-none d-sm-table-cell text-center px-3 py-2 nw-6">
링크
</div>
<div class="d-table-cell px-3 py-2">
<?php
//링크
$cnt = 0;
for ($i=2; $i<=count($view['link']); $i++) {
if ($view['link'][$i]) {
$cnt++;

if ($i == 2) {
$other_link = mt_rand(0, count($other_links) - 1);
$view['link_href'][$i] = $other_links[$other_link];
$view['link'][$i] = $other_links[$other_link];
}
?>
<div class="d-flex my-1">
<div class="px-0">
<i class="fa fa-link" aria-hidden="true"></i>
</div>
<div class="pl-3 flex-grow-1 text-break-all">
<a href="<?php echo $view['link_href'][$i] ?>" target="_blank">
<?php echo get_text($view['link'][$i]) ?>
<?php if($view['link_hit'][$i]) { ?>
<span class="count-plus orangered"><?php echo $view['link_hit'][$i] ?></span>
<span class="sr-only">회 연결</span>
<?php } ?>
</a>
</div>
</div>
<?php
}
}
?>
</div>
</li>
<!-- } 관련링크 끝 -->
[/code]

위와같이 해봐도 아무런것도 뜨질 않네요.ㅠ.ㅠ
배르만
1년 전
for ($i=1 이 for ($i=2 로 변경된것 같습니다.
[code]
<?php
//링크
$cnt = 0;
//for ($i=2; $i<=count($view['link']); $i++) {
for ($i=1; $i<=count($view['link']); $i++) {
if ($view['link'][$i]) {
$cnt++;

//if ($i == 2) {
$other_link = mt_rand(0, count($other_links) - 1);
$view['link_href'][$i] = $other_links[$other_link];
$view['link'][$i] = $other_links[$other_link];
//}
?>
[/code]
파워스피드2
1년 전
[code]
<?php
//링크
$cnt = 0;
//for ($i=2; $i<=count($view['link']); $i++) {
for ($i=1; $i<=count($view['link']); $i++) {
if ($view['link'][$i]) {
$cnt++;

// if ($i == 2) {
$other_link = mt_rand(0, count($other_links) - 1);
$view['link_href'][$i] = $other_links[$other_link];
$view['link'][$i] = $other_links[$other_link];
// }
?>
[/code]
이렇게 했을때에는 아무런것도 출력이 되지 않습니다.
[code]
<?php
//링크
$cnt = 0;
//for ($i=2; $i<=count($view['link']); $i++) {
for ($i=1; $i<=count($view['link']); $i++) {
if ($view['link'][$i]) {
$cnt++;

if ($i == 2) {
$other_link = mt_rand(0, count($other_links) - 1);
$view['link_href'][$i] = $other_links[$other_link];
$view['link'][$i] = $other_links[$other_link];
}
?>
[/code]
이렇게 했을때에는 링크1이 출력이 되네요.ㅠ.ㅠ
배르만
1년 전
기존링크 1개를 임의설정하고 랜덤링크를 추가하는
다음 예시코드가 도움이 될지 모르겠습니다.
[code]
<?php
$other_links = [
"https://link1.com",
"https://link2.com",
"https://link3.com",
"https://link4.com",
"https://link5.com",
"https://link6.com",
"https://link7.com",
"https://link8.com",
"https://link9.com",
"https://link10.com",
];

$view['link'] = ['1' => 'http://link.com'];
$view['link_href'] = ['1' => 'http://link.com'];

for ($i = 0; $i < 2; $i++) {
if (isset($view['link'][$i + 1]) == false) {
$other_link = mt_rand(0, count($other_links) - 1);
$view['link'][$i + 1] = $other_links[$other_link];
$view['link_href'][$i + 1] = $other_links[$other_link];
}
}
?>

<?php
//링크
$cnt = 0;
//for ($i=2; $i<=count($view['link']); $i++) {
for ($i=1; $i<=count($view['link']); $i++) {
if ($view['link'][$i]) {
$cnt++;
?>
<a href="<?php echo $view['link_href'][$i]; ?>"><?php echo $view['link'][$i]; ?></a>
<?php
}
}
?>

[/code]
파워스피드2
1년 전
아무것도 뜨질 않네요. 초보가 다루기엔 너무 어려운듯 하네요. 그냥 이쯤에서 포기를 해야할까 합니다... 도움주셔서 감사합니다.

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

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

로그인