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

  • Home
  • SEARCH
  • 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 6944943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:22:21+00:00 2026-05-27T13:22:21+00:00

I am working on creating API keys with php. I got a bit of

  • 0

I am working on creating API keys with php. I got a bit of it but I want to store a function in a variable. But instead it echos all the time. I want that the function should be stored in a variable and when the variable is echoed its function should be echoed. My codes are:

Client:

function get_cat($id){
    // Initialising authorisation to access api keys        
    $ch = curl_init("http://localhost/api/category.php?id=".$id);
    curl_setopt($ch, CURLOPT_COOKIE, "log=".$_SESSION['log']);
    // Executing script to set login session
    curl_exec($ch);
    // Closing curl connection session
    curl_close($ch);
}

Server:

    // Fetching data from database
    $query = mysql_query("SELECT * FROM cat WHERE id={$id}", $con) or die("Sorry Cannot Connect: ".mysql_error());
    echo json_encode(mysql_fetch_assoc($query));

Client:

$api = new API('test', 'test');
$res = $api->get_cat(2);

Now even if I assign the function in the $res variable it echos. Is there anyway to stop it? Because I want the users to store the function in a variable and use that variable to display those contents inside it anywhere they want.

  • 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-27T13:22:21+00:00Added an answer on May 27, 2026 at 1:22 pm

    By default curl will add the contents to stdout eg the page buffer unlees you request it to return from the curl_exec.

    Try this:

    function get_cat($id){
        // Initialising authorisation to access api keys        
        $ch = curl_init("http://localhost/api/category.php?id=".$id);
        curl_setopt($ch, CURLOPT_COOKIE, "log=".$_SESSION['log']);
        curl_setopt($ch, CURLOPT_HEADER, 0); //2 Not inc the http headers
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
        // Executing script to set login session
        $html = curl_exec($ch);
        // Closing curl connection session
        curl_close($ch);
        return $html;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on creating an immutable class. I have marked all the properties
I'm working on creating a call back function for an ASP.NET cache item removal
I'm working on creating a REST API. Lets say the resource I'm serving is
I am creating Email client using JavaMail API. Everything is working fine like I
I am working Calendar API (Java). My specific requirement is I want to add
I've been working on a framework in AS3 that I want to release, but
I am working on creating a RESTful API that supports cross-domain requests, JSON/JSONP support,
I'm currently working with Sharepoint 2010 and Sharepoint API on creating a document library
I'm currently working on creating a new C# project that needs to interact with
I am working on creating a daemon in Ruby using the daemons gem. I

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.