Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7636909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:48:16+00:00 2026-05-31T07:48:16+00:00

I have 2 codes written with PHP <?php error_reporting(1); function url_exists($url) { $ch =

  • 0

I have 2 codes written with PHP

<?php
error_reporting(1);

function url_exists($url) 
{
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HEADER, TRUE);
    curl_setopt($ch, CURLOPT_NOBODY, TRUE);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    $status = array();
    preg_match('/HTTP\/.* ([0-9]+) .*/', curl_exec($ch) , $status);
    return ($status[1] == 200);
}

echo "EX:".url_exists("http://www.google.com");

?>

and

<?php
error_reporting(1);

$ch = curl_init("www.yahoo.com");  
curl_setopt($ch, CURLOPT_TIMEOUT, 2);  
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
$data = curl_exec($ch);  
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);  
curl_close($ch);  
if($httpcode>=200 && $httpcode<300)
{  
    echo "Found@";  
} 
else 
{  
    echo "Not found";  
}  

?>

None of this of above works? WHY??? Yesterday worked pretty good, why PHP cannot be explain some times?

I have curl extension on from php.ini … i tried on 3 different servers …

What i’m doing wrong? Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T07:48:18+00:00Added an answer on May 31, 2026 at 7:48 am
    echo "EX:".url_exists("http://www.google.com");
    

    will always echo EX: because url_exists returns a boolean. Try:

    echo "EX:" . (url_exists("http://www.google.com") ? 'true' : 'false');
    

    Maybe this works?

    $ch = curl_init("http://www.example.com/favicon.ico");
    curl_setopt($ch, CURLOPT_NOBODY, true);
    curl_exec($ch);
    $retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    // $retcode > 400 -> not found, $retcode = 200, found.
    curl_close($ch);
    

    Source https://stackoverflow.com/a/982045/956397

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using php and i have written codes to allow a user upload
I have written a PHP function to take a video embed code that has
I have this code: <?php ini_set('display_errors', true); error_reporting(E_ALL); include ../../../wp-load.php; $groups = array(); if
I have a function, 'redirect_to()' written on php script that is called after a
I have a code snippet written in PHP that pulls a block of text
I have some code I've written in PHP for consuming our simple webservice, which
Our website code is written in PHP. We have very little testing in regards
I have written simple code to get content from xml file to php. $xml
I have written jQuery code, in files Main.html and ajax.php . The ajax.php file
I have a prototype website written in PHP. Lately i've rewritten code to separate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.