Jump to content

Link-Uri Afisate Aleator (Random) Cu Php


Recommended Posts

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

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

$l[0][1]='Random 1';
$l[0][2]='titlu 1';

$l[1][1]='Random 2';
$l[1][2]='Titlu 2';

$l[2][1]='Random 3';

$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';
$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
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.

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.

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.