false, 'error' => 'URL parameter is missing.'], 400);
}
$instagramUrl = trim($_GET['url']);
$parsedUrl = parse_url($instagramUrl);
// More robust validation: check host and path
if (
!$parsedUrl ||
!isset($parsedUrl['host']) ||
!preg_match('/(www\.)?instagram\.com$/', $parsedUrl['host']) ||
!isset($parsedUrl['path']) ||
strlen($parsedUrl['path']) < 2 // Path must be more than just "/"
) {
send_json_response(['success' => false, 'error' => 'Invalid Instagram URL format.'], 400);
}
// === 2. cURL REQUEST TO INSTAGRAM ===
// Initialize cURL session
$ch = curl_init();
// Set cURL options
curl_setopt($ch, CURLOPT_URL, $instagramUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return the transfer as a string
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Follow redirects
curl_setopt($ch, CURLOPT_TIMEOUT, 15); // Set a timeout of 15 seconds
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Bypasses SSL cert verification. Useful for some server configs.
// **CRUCIAL**: Use a realistic User-Agent to mimic a real browser visit
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36');
// Execute the request
$html = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// Check for cURL errors
if (curl_errno($ch)) {
$curl_error = curl_error($ch);
curl_close($ch);
send_json_response(['success' => false, 'error' => 'Failed to fetch the Instagram page. cURL error: ' . $curl_error], 500);
}
curl_close($ch);
// === 3. PROCESS THE RESPONSE ===
if ($http_code !== 200) {
if ($http_code === 404) {
send_json_response(['success' => false, 'error' => 'Post not found. The link may be broken or the post has been deleted.'], 404);
}
send_json_response(['success' => false, 'error' => 'Failed to access the post. It might be private or require a login. (Status code: ' . $http_code . ')'], 403);
}
if (empty($html)) {
send_json_response(['success' => false, 'error' => 'Received an empty response from Instagram.'], 500);
}
// === 4. DATA EXTRACTION (MULTI-METHOD APPROACH) ===
$videoUrl = null;
$thumbnailUrl = null;
$description = null;
$author = null;
if (preg_match('/
Instagram Video Downloader
Download high-quality videos, reels, and stories from Instagram for free. Paste the link below and save your favorite content instantly!
Why Choose InstaGrabHQ?
High-Quality Downloads
Save videos in their original, high-definition (HD) quality without any loss.
Fast and Easy to Use
Our simple interface allows you to download videos in just a few clicks. No technical skills needed.
Safe and Secure
Your privacy is our priority. We don't track your downloads or store your data.
Completely Free
Download as many Instagram videos as you want, with no limits and no hidden fees.
How It Works in 3 Easy Steps
1
Copy the URL
Open Instagram, find the video or Reel you want to download, and copy its link.
2
Paste the Link
Come back to InstaGrabHQ and paste the copied URL into the input box above.
3
Download Video
Click the "Download" button, and your video will be ready to save to your device.
Frequently Asked Questions
Is downloading Instagram videos legal?
Downloading videos is generally legal for personal use. However, you should always respect copyright laws and not reuse or distribute downloaded content without the creator's permission.
Do I need to install any software?
No, InstaGrabHQ is a fully online tool. You don't need to install any software or browser extensions. It works on any device with a web browser.
Can I download videos from private accounts?
No. Our tool cannot access content from private Instagram accounts as we respect user privacy. You can only download videos from public posts.
Are the downloaded videos watermarked?
No, all videos are downloaded without any watermark, in the highest quality available from the public post.