How do i use GET requests using cURL?

This is my code:

And here is what it returns:
image

And here is what the original API returns:
image

After your curl_close($curl), remove the var_dump(). Then you can type this to return just the number:

$number_fromjson = json_decode($resp);
$number = $number_fromjson['favoritesCount'];
echo $number;
1 Like

Now it doesn’t works anymore.


Try this after your curl_close instead.

$number_fromjson = json_decode($resp, true); 
$number = $number_fromjson["favoritesCount"]; 
echo $number;

The problem with the code I originally provided is it was being converted into an object instead of an associative array. It no longer has that problem and should be working, I tested it.

2 Likes

It works!!!
Finally, how do I import the content of the txt file (php) into my html dashboard?

You can do that two ways:

  1. Remove echo $number; and include the file in your admin dashboard and just use the $number whenever needed (preferred) or
  2. Use $favorites_number = file_get_contents("https://api.bloxstargames.cf/gba/v1/favorites.php"); and assign it to a variable, such as favorites_number, like I did above. This is easier, but not really preferred.

But it’s html not php so php functions doesn’t works on html because html is static and php is dynamic

Then just change the file extension to php and do what I said. There’s no easy and efficient way to do that with html.

And if i do that i will also need to remove the html tag or just add the php tags and then the html tags?

(Again sorry but i am a php learner lol)

Just change the extension. If you remove any html tags, you may break your code.

So this should like this:

In the first picture, you need to put <?php (and a space) before $favorites_number and ?> at the end of the line. like this:

<?php $favorites_number = file_get_contents("https://api.bloxstargames.cf/gba/v1/favorites.php"); ?>

For it to display the number, you need to put <?= so it will actually display the number and then ?>. like this:

<h6><?=$favorites_number?></h6>
1 Like

No, you need the <?php and ?> tags.

You really should have a basic knowledge of PHP before attempting something like this.

1 Like

It doesn’t show up
image

How are you displaying the output without using echo ??

<?php
$favorites_number = file_get_contents("https://api.bloxstargames.cf/gba/v1/favorites.php");
echo $favorites_number; ?>
1 Like

It’s still not working

image

It seems that Cloudflare blocks the requests. I have Strict ssl enabled and Bot fight mode enabled. What to do? When i use pastebin the request works.

Because
image

Use option 1.

So i will have to put the code from favorites.php into index.php?

No. Read about how to use an include and then you will understand.

https://www.php.net/manual/en/function.include.php

1 Like