How to do PHP Manual Redirect

Discussion in 'PHP' started by tlbuckingham, Jul 24, 2008.

  1. #1
    I currently have a website than I have been redirecting on another one of my websites with the following PHP Script:

    <?php
    header('Refresh: 10; url=http://abc.com');
    echo 'You will be redirected in 10 seconds';
    ?>


    I would like to make it were the use has to manually click a link to be redirected.

    For example after a set amount of time (in seconds) I woul like the "Click Here Now" to appear which would take them to the website of my choice.

    Anyone know how to do this?
     
    tlbuckingham, Jul 24, 2008 IP
  2. ToddMicheau

    ToddMicheau Active Member

    Messages:
    183
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    58
    #2
    You could do this with Javascript, something like:

    
    <div id="countdown"></div>
    <script type="text/javascript">
    	var theLink = "http://google.com";
    	var theMessage = "Click here to leave.";
    	var timeToLeave = 5;
    	var count = 0;
    	var timer;
    	timer=setTimeout("countDown()",1000);
    	function countDown(){
    		document.getElementById("countdown").innerHTML = (timeToLeave - count) + " seconds until you may leave.";
    		count = count + 1;
    		if(count == timeToLeave){
    			document.getElementById("countdown").innerHTML='<a href="' + theLink + '">' + theMessage + '</a>';
    		}else{
    			timer=setTimeout("countDown()",1000);
    		}
    	}
    </script>
    
    PHP:
    Tested and working if that's what you need.

    Hope that helps,
    ~Todd
     
    ToddMicheau, Jul 24, 2008 IP