HELP - HTML/PHP Redirect Code

Discussion in 'PHP' started by black.knight, Sep 27, 2008.

  1. #1
    Hi All

    I am looking for an code or script that able me to redirect my visitors per number of visits to three sites

    For example i have 300 visitor per day, i want to redirect 100 of them to Google.com
    and 100 of them to Yahoo.com and 100 of them to MSN.com Automatically
    Please if there is any code or script can do that?
    I really need this..

    Thanks
     
    black.knight, Sep 27, 2008 IP
  2. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    $sites = array(
    'http://www.google.com',
    'http://www.yahoo.com',
    'http://www.msn.com');
    
    header('Location: '.$sites[rand(0,count($sites)-1]);
    PHP:
    This will randomly pick one and redirect. with the laws of averages, it should even out
     
    JAY6390, Sep 27, 2008 IP
  3. imphpguru

    imphpguru Active Member

    Messages:
    439
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #3
    Hi Here is a simple script.

    
    
    <?php
    $count = file_get_contents("counter.txt"); // has the date and the count something like count:date eg. 223:23_02_2008
    $count = split(":",$count);
    $date = $count[0];
    $curr_date = date("d_m_Y");
    if($curr_date != $date)
    	{
    		$count = 0;
    		$date = $curr_date;
    	}
    file_put_contents("counter.txt",$count.":".$date);
    if($count < 100)
    	{
    		header("location:url1");// For hits less than 100;
    	}
    elseif(($count < 200) && ($count > 100))
    	{
    		header("location:url2");	// For hits more than 100;	
    	}
    elseif(($count < 300) && ($count > 200))
    	{
    		header("location:url3"); // For hits more than 200;
    	}
    else
    	{
    		header("location: url4"); // For hits more than 300;
    	}
    ?>
    
    
    PHP:
    You will need php 5 for this. (file_get_contents) works in PHP 5 only. Hope this helps.

    Thanks

    imphpguru


     
    imphpguru, Sep 27, 2008 IP
  4. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Correction: Atleast PHP 4.3.0 but you should by now being PHP 5 at this point.
     
    NatalicWolf, Sep 27, 2008 IP
  5. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #5
    plus theres the compatability functions available at php.net for people on versions before that....but you are right, it should be 5 only now
     
    JAY6390, Sep 27, 2008 IP
  6. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #6
    include and ob_start and ob_getclean for example:). or fread and filesize. But PHP 4 is no longer developed.
     
    NatalicWolf, Sep 27, 2008 IP
  7. imphpguru

    imphpguru Active Member

    Messages:
    439
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #7
    Hi,
    Yeah! PHP 4 is bye bye now. Just wanted to make sure you are in the right version... you can do it using php 4 also by fopen and fread.

    Thanks

    imphpguru
     
    imphpguru, Sep 27, 2008 IP
  8. Pos1tron

    Pos1tron Peon

    Messages:
    95
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I think he was actually on about file_put_contents, that's used and is PHP 5+. Uber easy to port most of it's features back to 4 though :)
     
    Pos1tron, Sep 28, 2008 IP
  9. black.knight

    black.knight Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    imphpguru Thanks your code is work..
    JAY6390 your code is not work, I have created a new php page and i have placed the code that you send me there:

    <?php

    $sites = array(
    'http://www.google.com',
    'http://www.yahoo.com',
    'http://www.msn.com');

    header('Location: '.$sites[rand(0,count($sites)-1]);

    ?>



    But i just see a blank page,
    for example when i open this page i see an white page with no action (a blank page)..
    Can anybody help?
    Is there is something wrong with the code?

    thanks
     
    black.knight, Sep 28, 2008 IP
  10. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #10
    ah oops typo
    change it to

    header('Location: '.$sites[rand(0,count($sites)-1)]);
     
    JAY6390, Sep 28, 2008 IP
  11. black.knight

    black.knight Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Thanks Man,
    It work now ; )
     
    black.knight, Sep 28, 2008 IP
  12. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #12
    cool :cool:
     
    JAY6390, Sep 28, 2008 IP