Getting Null Error when I am trying to run using PHP Curl

I am trying the following using PHP Curl

ini_set(‘display_errors’, ‘1’);

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => ‘https://api.openai.com/v1/images/generations’,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => ‘’,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => ‘POST’,
CURLOPT_POSTFIELDS =>‘{
“prompt”: “Need two tigers with puppy”,
“n”: 1,
“size”: “1024x1024”
}’,
CURLOPT_HTTPHEADER => array(
‘Content-Type: application/json’,
‘Authorization: Bearer sk-UWGEEW@ksdk##@UoebT3BlbkFJveMcC99999f682hjsd
),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

var_dump($response);

but i am getting following result only

bool(false)

please help, but when run the above code in Postman then it’s working but it’s not working using PHP

I don’t have an answer for you, but I do have two recommendations in order of importance. :wink:

  1. Redact your auth token immediately
  2. Use a code block with indentation to help readers understand your code better.

He does not need to do that because he added some random noise to his key so its just noise and not his actual API key.

:slight_smile:

2 Likes

I’m glad this is the case, but a hacker at Blackhat Las Vegas once showed me how to use a key with random changes to determine the actual key. I was stunned, not because he did it, but because he did it in 11 seconds.

Well, that is a nice CYA reply @bill.french :slight_smile:

There is no risk in how @chetanprakashsharma obfuscated his key and he did what any prudent person would have done.

HTH

:slight_smile:

I can accept that, but will everyone who is less informed get a false sense that it’s okay to include their keys openly? After all, a good number of people in this community are new to APIs and auth tokens, right?

I think you are pushing a non-issue and you should let it rest @bill.french , TBH.

There is nothing technically wrong in what @chetanprakashsharma posted and he added random noise as he deemed appropriate.

I do the exact same thing all the time and I have many decades of cybersecurity experience.

OBTW . It was trivial to look at what @chetanprakashsharma posted to see that he masked out his key as he deemed appropriate.

HTH

:slight_smile:

3 Likes

Hi @chetanprakashsharma

If you search the forums, you will see a number of PHP examples.

For example, here is one related to fine-tuning which you can easily modify to apply toward your image completion request:

HTH

:slight_smile: