luke777 Posted October 20, 2008 Share Posted October 20, 2008 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. Link to comment https://forums.phpfreaks.com/topic/129301-quick-question-im-sure-will-be-solved-in-no-time/ Share on other sites More sharing options...
kenrbnsn Posted October 20, 2008 Share Posted October 20, 2008 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 Link to comment https://forums.phpfreaks.com/topic/129301-quick-question-im-sure-will-be-solved-in-no-time/#findComment-670331 Share on other sites More sharing options...
luke777 Posted October 20, 2008 Author Share Posted October 20, 2008 If im honest, i didnt actually code the script. I had it made. It does the job pretty well from a users point of view. But if it looks messy at all id appreciate suggestions on how to tidy it up. Thanks Luke. Link to comment https://forums.phpfreaks.com/topic/129301-quick-question-im-sure-will-be-solved-in-no-time/#findComment-670336 Share on other sites More sharing options...
luke777 Posted October 20, 2008 Author Share Posted October 20, 2008 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. ??? Link to comment https://forums.phpfreaks.com/topic/129301-quick-question-im-sure-will-be-solved-in-no-time/#findComment-670347 Share on other sites More sharing options...
kenrbnsn Posted October 20, 2008 Share Posted October 20, 2008 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 Link to comment https://forums.phpfreaks.com/topic/129301-quick-question-im-sure-will-be-solved-in-no-time/#findComment-670364 Share on other sites More sharing options...
luke777 Posted October 20, 2008 Author Share Posted October 20, 2008 Woah, its done! and tested! your a genuis Thank you very much KEN Link to comment https://forums.phpfreaks.com/topic/129301-quick-question-im-sure-will-be-solved-in-no-time/#findComment-670378 Share on other sites More sharing options...
luke777 Posted October 20, 2008 Author Share Posted October 20, 2008 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! :-\ Link to comment https://forums.phpfreaks.com/topic/129301-quick-question-im-sure-will-be-solved-in-no-time/#findComment-670382 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.