Basically if user came from Site A to your Site B he should go to Site C:
Do you owns Site A? If so, when a user clicks on a link that points to Site B you should write the URL like this http://www.siteB.com/?fromsiteA=1
Another way is using PHP. What you do is use the HTTP_REFERER like this:
$previous_url = $_SERVER['HTTP_REFERER'];
Then you take the appropriate action in regards to what $previous_url contains.