willdk Posted October 31, 2009 Share Posted October 31, 2009 Everybody knows how to redirect page A to page B. But can you control how many times the redirect can be used? Example; 100 visitors visit page A, and you "tell" the script to only redirect 50 to page B. 51 through xxx is redirected to another location. Quote Link to comment https://forums.phpfreaks.com/topic/179774-solved-is-this-technical-possible/ Share on other sites More sharing options...
Mchl Posted October 31, 2009 Share Posted October 31, 2009 I see no reason why it wouldn't be possible. Quote Link to comment https://forums.phpfreaks.com/topic/179774-solved-is-this-technical-possible/#findComment-948486 Share on other sites More sharing options...
willdk Posted October 31, 2009 Author Share Posted October 31, 2009 I see no reason why it wouldn't be possible. I'm very curious HOW you make something like this, how do you START. I have searched for existing scripts, but there aren't. If someone visits a redirect, his visit get lost. So you can't count this. And if you CAN count this, how do you tell the script to stop redirect the visitors to page B. I need a plan, because I have no idea. Quote Link to comment https://forums.phpfreaks.com/topic/179774-solved-is-this-technical-possible/#findComment-948489 Share on other sites More sharing options...
Alex Posted October 31, 2009 Share Posted October 31, 2009 You could store the number of users redirected in a flat-file. $num = file_get_contents('counter.txt'); file_put_contents('counter.txt', $num + 1); if($num <= 50) header('Location: a.html'); else header('Location: b.html'); Quote Link to comment https://forums.phpfreaks.com/topic/179774-solved-is-this-technical-possible/#findComment-948490 Share on other sites More sharing options...
Mchl Posted October 31, 2009 Share Posted October 31, 2009 One of the ways would be to store the number of visits into a file. Script would work like this (psudocode) read number of visits from file (if > 50) { redirect to B }else { increase number of visits by 1 and save to file redirect to A } Quote Link to comment https://forums.phpfreaks.com/topic/179774-solved-is-this-technical-possible/#findComment-948491 Share on other sites More sharing options...
Gayner Posted October 31, 2009 Share Posted October 31, 2009 You could store the number of users redirected in a flat-file. $num = file_get_contents('counter.txt'); file_put_contents('counter.txt', $num + 1) if($num <= 50) header('Location: a.html'); else header('Location: b.html'); Perfect! Quote Link to comment https://forums.phpfreaks.com/topic/179774-solved-is-this-technical-possible/#findComment-948493 Share on other sites More sharing options...
willdk Posted November 1, 2009 Author Share Posted November 1, 2009 @AlexWD and Mchl Thank you very much for explaining this to me. I didn't know it would be that simple. I actually expected a "No! Not possible..." Quote Link to comment https://forums.phpfreaks.com/topic/179774-solved-is-this-technical-possible/#findComment-948499 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.