관련링크 2번째에 랜덤으로 링크 뿌려주기 채택완료
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개
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개
크론탭 파싱으로 불러온 내용이 링크1에 적용이 되고 링크2는 아이디 추가 라고만 뜨는데요;;
<?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]
어디가 잘못된걸까요?;;
link='https://link3.com' <-- 이런 모양으로 보여야 됩니다
댓글을 작성하려면 로그인이 필요합니다.
저렴한 웹호스팅 중에는 php 의 file_get_contents 나 curl 을 허용해 주지 않는 데가 꽤 있습니다.
그러니 사이트를 랜덤으로 안전하게 튕기려면
프론트에서 자바스크립트로 튕기는 것이 코드는 길지만 더 효과가 확실합니다.
즉 저 변수들을 js 파일안에 심어 놓고 불러와야 안전하지 php 파일에 심어 놓으면 cutl 등이 막혀 있으면 당연히 안 될 것입니다.
답변에 대한 댓글 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개
어디에 어떤방식으로 적용을 해야 하는지는 본인이 판단해야 합니다.
[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]
뷰스킨 에서 관련링크에 삽입을 하고 싶습니다.
[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]
이부분이 링크 부분인거 같은데 여길 어떻게 고쳐야 할질 모르겠네요.ㅠ.ㅠ
[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]
<?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]
아무런 내용도 출력이 되지 않습니다.ㅠ.ㅠ
셋업파일 주소부분은 제대로 넣고 했는데 아무것도 출력이 되지 않습니다.ㅠ.ㅠ
[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]
<?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]
위와같이 해봐도 아무런것도 뜨질 않네요.ㅠ.ㅠ
[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]
<?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이 출력이 되네요.ㅠ.ㅠ
다음 예시코드가 도움이 될지 모르겠습니다.
[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]
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인