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 7883893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:39:18+00:00 2026-06-03T04:39:18+00:00

First time trying to use JSON. Here is my checklink.php : function url_exists($url) {

  • 0

First time trying to use JSON.
Here is my checklink.php :

function url_exists($url) {
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_NOBODY, true);
    curl_exec($ch);
    $retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    // $retcode > 400 -> not found, $retcode = 200, found.
    if ($retcode == 400){
    return "false";
    }else{
    return "true";
    }
    curl_close($ch);
}
$response = array( 
  'location' => $location, 
  'status' => $status 
);
$rr = url_exists($response['location']);
echo json_encode( $rr );

JS part :

function UrlExistsNew(url, callback) {
  $.getJSON('checklink.php', { location: url }, function ( data ) {
  callback.apply( null, data.status );
});
}
...
UrlExistsNew($(this).val(), function(status){
        if(status === "false") $(element).css('background-color','#FC0');
      }); 
...

It seems the php page is not returning result to json query.

Edit : Note that I forgot to install curl and enable it in my server. I Hope no one miss this.

  • 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-06-03T04:39:20+00:00Added an answer on June 3, 2026 at 4:39 am

    OK, After doing test and trials for 8 hours. I finally got this working. Thanks a lot to Vytautas. He teached me a lot. Mostly how to debug.

    For anyone who wants to check broken links using JSON + PHP + CURL :

    1. First of all, Check if you have curl installed and enabled in your server.
    2. Those who don’t understand curl : If there is a response from your url, there will be a status code (like 200 or 404). If the url entered is blank, invalid or anything like that, It will return status code 0
    3. If you can’t get the proper response from php page, use FireBug (Console Tab) to check the headers and responses. Also use breakpoint to see if variables are passing correctly.

    Here is the php code :

    function url_exists($url) {
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_NOBODY, true);
    
        if(curl_exec($ch) === false) // These 2 line here are for debugging.
            die('Curl error: ' . curl_error($ch));
    
        $retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        return $retcode;
    }
    $response = array(
      'status' => url_exists($_GET['location'])
    );
    echo json_encode($response)
    

    I was doing 2 thing wrong in php. I should have used $_GET['location'] instead of $location And the other was $response instead of using a second variable.

    And the js function :

    function UrlExistsNew(url, callback) {
      $.getJSON('checklink.php', { location: url }, function ( data ) {
      callback.call( null, data.status );
    });
    }
    

    Another thing I was doing wrong in js was passing callback to the function. I should have used callback.call instead of callback.apply

    Simple usage :

    UrlExistsNew($(this).val(), function(status){
            if(status === 404) $(element).css('background-color','#FC0');
          }); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use the PHP json_encode function to encode some JSON to send
this is my first time trying to use document classes in AS3 and im
I'm trying to use an event listener for the first time. All samples I've
I am trying to use the Google generated API library for the first time
First time trying to use the password protected visibility option on a Wordpress page,
I am trying to use generic for the first time and trying to typecast
first of all, thanks for your time. I'm trying to use jqGrid to make
This is my first time trying to use the XMLRPC::Client library to interact with
I am trying to use the Django include tag for the first time and
I am trying to use the Spirit library for the first time. I am

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.