在PHP中,如何传递session id和file_get_contents函数?

Why does this code cause the website to get stuck:

$id = session_id();
$url = 'https://www.website.com/dev/appointment?id='. $id .  
'';
$data = file_get_contents($url);

while everything goes well as planned when replacing $id with the actual session id like:

$id = session_id();
$url = 'https://www.website.com/dev/appointment?     
id=j8e3onreb4m71fljpcd9mesfr9';
$data = file_get_contents($url);

The PHP file accessed by the aforementioned URL starts with:

<?php
if(isset($_GET['id'])) session_id($_GET['id']);
session_start();

You have to call session_start() before you call session_id, else $id will be empty

session_start();
$id = session_id();
$url = 'https://www.website.com/dev/appointment?id='. $id;