Jump to content

How can i do this? simple mod on a php script... so i thought..


luke777

Recommended Posts

I have this script to send out a specfied number of hits to my partner sites, once all the hits are sent the statsmain.omg storage file resets itself and starts sending the specfied hits over again..

 

I am trying to make it so that once all the hits have been sent to the specified sites any hits thereafter just go back to my local homepage.

 

 

I am linking to the script from banners on my site and it is becoming overclicked and reseting too often on certain days when traffic is higher.

 

I have set a cron job on my server to blank the statsmain.omg file every day at 00:00 and I would like this to be the only time the script does reset itself!

 

 

Right so here are the contents:

 

Sites.php

<?php
//Here I define my sites
$sites=array(array('url'=>'http://www.ask.com','hits'=>40),
                   array('url'=>'http://www.yahoo.com','hits'=>10),
                   array('url'=>'http://www.google.com','hits'=>200));

?>

 

 

Out.php

<?php
require_once("sites.php");

//Script that loads data from sites.php

$omg=file_get_contents('statsmain.omg');
$handle=fopen('statsmain.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: out.php"); // all hits set, reload and start over
?>

 

statsmain.omg

//storage file
a:4:{i:0;i:2;i:1;i:1;i:2;i:2;i:3;i:0;}

 

I tryed by changing this

 

header("location: out.php"); // all hits set, reload and start over

 

to this

 

 

header("location: mywebsite.com"); // all hits set, reload and start over

 

All that seems to be doing is loading mywebsite.com on the last hit after all the specified hits have been sent, then it resets back to the beginning, sending out to partner sites

 

I hope I have explained clearly enough  ???

 

And really hope someone cleverer than me, can help me.

 

Im a beginner to php coming to the end of my book now so I should learn a little more soon although the book is titled "Absolute beginner"

 

If you can help, id really appreciate it thank you! :(

 

Luke

 

 

 

When I removed the ftrunicate part and changed the "location: moregames.php" to "location: /", that just makes the last/first (whichever way you look at it) hit be sent to the local websites homepage, then after that the script continues sending to partner sites again.

 

I need it so that once all hits are sent, any thereafter go to the homepage of my local site not just the 1 at the end.

 

Luke  ???

  • 2 weeks later...

How about this?

 

<?php
require_once("sites.php");

//Script that loads data from sites.php

$omg=file_get_contents('statsmain.omg');
$handle=fopen('statsmain.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));
  fclose($handle);
  header("Location: {$sites[$i]['url']}");
  exit;
  }
}
//if all set, save original stats
fwrite($handle,$omg,strlen($omg));
fclose($handle);
header("location: out.php"); // all hits set, reload and start over
?>

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.