Jump to content

Link-Uri Afisate Aleator (Random) Cu Php


gaby

Recommended Posts

Pentru inceput aveti nevoie de fisierul linkrotator.php care sa contina:


<?php
$cate=3; //cate link-uri vrei sa afiseze
$despartitor='<br /><hr />'; //despartitor

$l[0][0]='http://site.ro';
$l[0][1]='Random 1';
$l[0][2]='titlu 1';

$l[1][0]='http://link2.ro';
$l[1][1]='Random 2';
$l[1][2]='Titlu 2';

$l[2][0]='http://link3.ro';
$l[2][1]='Random 3';
$l[2][2]='Titlu';

$l[3][0]='http://link4.ro';
$l[3][1]='Random 4';
$l[3][2]='Titlu 4';

//$l[numar link][0]= 'link';
//$l[numar link][1]= 'Ce sa afiseze';
//$l[numar link][2]= ' titlu ';

if($cate > count($l)) // verificam sa fie mai multe linkuri decat trebuie afisate
echo 'Sunt prea putine link-uri';
else
{
$r=array(); // construim array-ul cu link-urile extrase
while(count($r) < $cate) // cat timp in array sunt mai putine decat ai nevoie
{
$random=rand(0,count($l)-1); // generam un numar random intre 0 si numarul link-urilor
if(!in_array($random,$r)) // daca nu se afla in array
$r[]=$random; //il adaugam
}

for($i=0;$i<=count($r)-1;$i++) // scriem toate link-urile random extrase
{
$rnd=$r[$i];
echo '<a href="'.$l[$rnd][0].'" title="'.$l[$rnd][2].'">'.$l[$rnd][1].'</a>';
if($i != count($r)-1) echo $despartitor; // daca nu este ultimul link afisam despartitorul

}
}
?>
[/code] Iar pentru afisare, veti folosii codul:
[code]<?php include "linkrotator.php"; ?>

in pagina in care doriti sa apara link-urile afisate aleator.

Succes :pct2: !

Te-ai inregistrat? Ne-ar placea sa te prezinti.

Cum pot sustine forumul?
Cumpara de la eMag folosind acest link.
--------------------
oG2BN9d.gifse1WdXd.gifQG6MtmI.gifRHYjDzD.gifG5p1wui.gif

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.