fork download
  1.  
  2. <form action="" method="post">
  3. <input type="text" name="url" placeholder="URL">
  4. <input type="submit" name="submit" value="Сократить">
  5. </form>
  6.  
  7. <?php
  8. $chars = array("a", "b", "c", "d", "e", "f", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
  9. if ( isset($_POST['submit']) ) {
  10. $key = implode("", array_rand($chars, 5));
  11. $url_to_cut = $_POST['url'];
  12. $cutted_abs_url = "http://" . $_SERVER['SERVER_NAME'] . "/redirect_test/r/" . $key . ".php";
  13. $cutted_rel_url = "r/" . $key . ".php";
  14. $redirect_script = fopen($cutted_rel_url, "w");
  15.  
  16. fwrite($redirect_script, "<?php header('Location:" . $url_to_cut . "'); ?>");
  17. echo 'Ваша ссылка: <a href="' . $cutted_abs_url . '">' . $cutted_abs_url . '</a>';
  18. }
  19. ?>
Success #stdin #stdout 0.03s 23652KB
stdin
Standard input is empty
stdout
<form action="" method="post">
 	<input type="text" name="url" placeholder="URL">
 	<input type="submit" name="submit" value="Сократить">
</form>