
<form action="" method="post">
 	<input type="text" name="url" placeholder="URL">
 	<input type="submit" name="submit" value="Сократить">
</form>

 <?php
 	$chars = array("a", "b", "c", "d", "e", "f", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"); 
 	if ( isset($_POST['submit']) ) {
 		$key = implode("", array_rand($chars, 5));
 		$url_to_cut = $_POST['url'];
 		$cutted_abs_url = "http://" . $_SERVER['SERVER_NAME'] . "/redirect_test/r/" . $key . ".php";
 		$cutted_rel_url = "r/" . $key . ".php";
 		$redirect_script = fopen($cutted_rel_url, "w");

 		fwrite($redirect_script, "<?php header('Location:" . $url_to_cut . "'); ?>");
 		echo 'Ваша ссылка: <a href="' . $cutted_abs_url . '">' . $cutted_abs_url . '</a>';
 	}
 ?>