Jump to content

Quick Question I'm sure will be solved in no time :)


luke777

Recommended Posts

Hi there,

 

I have this php script and it sends out a specifyed number of visitors to each site that i specify.

 

<?php
$urls=http://www.google.com||2,http://www.yahoo.co.uk||3";
$urls=explode(",",$urls);
$i=0;
foreach($urls as $url){
$url=explode('||',$url);
$sites[$i]['url']=$url[0];
$sites[$i]['hits']=$url[1];
$i++;
}
$omg=file_get_contents('test.omg');
$handle=fopen('test.omg','w+');
if(!$omg){
  foreach($sites as $site){
  $stats[]=0;
  }
} else{
$stats=unserialize($omg);
}

    for($i=0;$i<=count($sites)-1;$i++){
    $rand[]=$i;
    }
shuffle($rand);
foreach($rand as $i){
  if($stats[$i]<$sites[$i]['hits']){
  $stats[$i]++;
  $stats=serialize($stats);
  fwrite($handle,$stats,strlen($stats)); 
  header("Location: {$sites[$i]['url']}");
  exit;
  }
}
ftruncate($handle,0);
header("location: test.php"); // all hits set, reload and start over
?>

 

As it is the script works great. But what I need is for the urls to be in a list not a big long thing that makes me have to scroll sideways for ages.

 

I tryed "<<<HERE" function in php, i read up about.

 

<?php

 

 

$urls=<<<HERE

http://www.google.com||2,

http://www.yahoo.co.uk||3

HERE;

$urls=explode(",",$urls);

$i=....................: test.php"); // all hits set, reload and start over

?>

 

But it didnt work like that :(

 

Is there anyway I just get the list of urls flowing downwards?

 

It would make things sooo much easier for me because I got tons going across the page.

Why don't you just code the sites as an array in the first place?

<?php
$sites = array(array('url'=>'http://www.google.com','hits'=>2),
                   array('url'=>'http://www.yahoo.co.uk','hits'=>3));
?>

 

Ken

 

 

I just tested the script like you suggested

 

<?php
$sites=array(array('url'=>'http://www.google.com','hits'=>2),
                   array('url'=>'http://www.yahoo.co.uk','hits'=>3));
$urls=explode(",",$urls);
$i=0;
foreach($urls as $url){
$url=explode('||',$url);
$sites[$i]['url']=$url[0];
$sites[$i]['hits']=$url[1];
$i++;
}
$omg=file_get_contents('test.omg');
$handle=fopen('test.omg','w+');
if(!$omg){
  foreach($sites as $site){
  $stats[]=0;
  }
} else{
$stats=unserialize($omg);
}

    for($i=0;$i<=count($sites)-1;$i++){
    $rand[]=$i;
    }
shuffle($rand);
foreach($rand as $i){
  if($stats[$i]<$sites[$i]['hits']){
  $stats[$i]++;
  $stats=serialize($stats);
  fwrite($handle,$stats,strlen($stats)); 
  header("Location: {$sites[$i]['url']}");
  exit;
  }
}
ftruncate($handle,0);
header("location: test.php"); // all hits set, reload and start over
?>

 

And all the hits just go to yahoo everytime the script is run.

 

???

 

Remove this section of code

<?php
$urls=explode(",",$urls);
$i=0;
foreach($urls as $url){
$url=explode('||',$url);
$sites[$i]['url']=$url[0];
$sites[$i]['hits']=$url[1];
$i++;
}
?>

since it's not needed when you pre-populate the $sites array.

 

Ken

the script at the moment stores info like:

 

"a:3:{i:0;i:1;i:1;i:0;i:2;i:2;}" in test.omg

 

Which is kinda messy and i can't keep track of it at all.

 

Is there anyway i could make that go down in a list also? and have the site url next to it so i can track how many have been sent throughout the day.

 

I cant track it the way it is, is there any php code i could change to make it display like this, is it hard to do?

 

Iv read half way through my php/mysql book but so far theres nothing on this, all i have read is about loops and arrays and even they are kinda confusing :(

 

I really do appreciate you helping this newbie, thanks alot!    :-\

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.