Ошибка с $_SESSION

Решил сделать свой сервис по сокращению URL используя TinyURL API. Есть две странички, на одной инпут где человек вводит длинную ссылку, а на другой в инпуте выводиться короткая ссылка. Сам код: index.php:

<?php
session_start();
$errors = array();
if(isset($_POST['submit'])){
    if(trim($_POST['short']) == ''){
        $errors[] = 'enter the link please';
    }elseif(preg_match("/^(http|https):\/\/cs[0-9]+\.[a-zA-Z0-9]+\.me\/[^.]+/", $_POST['short'])){
        $errors[] = 'incorrect link format';
    }elseif(empty($errors)){
        unset($errors);
        $new_url =  file_get_contents('http://tinyurl.com/api-create.php?url='. $_POST['short']);
        
        $_SESSION['url'] = $new_url;
        
    }else{
        $errors[] = 'error';
    }
}
?>

И сам html

  <form action="shortened.php" method="post">
            <div class="urlform">

                <input type="text" name="short" placeholder="Paste the link here">
                <div class="submitform">
                    <input type="submit" value="Short URL" name="submit">
                </div>

            </div>
        </form>

и shortened.php где должна выводиться короткая ссылка:

<?php
session_start();
?>
        <form action="shortened.php" method="post">
            <div class="urlform">

              <input readonly type="text" class="shortenedlink" name="shortened" value='<?php echo $_SESSION['url']  ?>' >
                <div class="submitform">
                    <input class="copyurl" type="copy" value="Copy URL">
                </div>

            </div>
        </form>

Однако вместо короткой ссылки, в инпуте shortened.php выводиться такая ошибка: <br /><b>Warning</b>: Undefined array key "url" in <b>C:\OpenServer\domains\shortener\shortened.php</b> on line <b>32</b><br />

Сессии у меня на OpenServer работают, скорее всего дело в сохраняемых данных. В чём может быть ошибка?


Ответы (0 шт):