Problem with HTTP Funtion
#1

related to this tutorial: https://sampforum.blast.hk/showthread.php?tid=188241

so I don't know what I've done wrong, however I guess I did something wrong...
my score is somehow not being saved in the window...

I needed to create the file ([HSA]Sgt.txt) on my own as it didn't do anything automatically... so my server IP is 217.18.70.196, therefore I used this IP in the get.php file....
what's wrong?

get.php
Код:
<?php
        if($_SERVER['REMOTE_ADDR'] == '217.18.70.196'){
        if(!isset($_GET['user'])) return false;
 
        if(isset($_GET['score']))
        {
                $file = fopen($_GET['user'] . '.txt', 'w');
                fwrite($file, $_GET['score']);
                fclose($file);
        }

?>
image3.php
Код:
<?php
	header('Content-type: image/png');
	$image = imagecreatefrompng('hsalogo.png');
	$file = fopen($_GET['user'] . '.txt', 'r');
	$score = fread($file, filesize($_GET['user'] . '.txt'));
	fclose($file);
	$black = imagecolorallocate($image, 0, 0, 0);
	imagettftext($image, 15, 0, 15, 45, $black, 'Carnevalee Freakshow.ttf', $_GET['user']);
	imagettftext($image, 15, 0, 30, 60, $black, 'Carnevalee Freakshow.ttf', 'Score: ' . $score);
	imagepng($image);
	imagedestroy($image);
?>
and sa-mp code:
Код:
forward UpdatePlayerImage(playerid);

public OnPlayerUpdate(playerid)
{
    UpdatePlayerImage(playerid);
    return 1;
}

public UpdatePlayerImage(playerid)
{
	new string[256], pname[MAX_PLAYER_NAME];
	GetPlayerName(playerid, pname, sizeof(pname));
	new score = GetPlayerScore(playerid);
	format(string, sizeof(string), "http://sgt-site.tk/hsa/get.php?user=%s&score=%d", pname, score);
	HTTP(-1, HTTP_HEAD, string, "", "");
}
Reply
#2

noone?
Reply
#3

You can't use www.blabla.tk/shitshit with a .tk domain as far as I know...
Reply
#4

grr... that is stupid -.-
Reply
#5

sry for double post, but:
would it work if I used a .co.nr redirection instead to the .tk instead?
Reply
#6

Well for one thing you're actually missing a closing bracket in there, which means the code won't run since there will be an error.

PHP код:
<?php
if($_SERVER['REMOTE_ADDR'] == '217.18.70.196')
{
    if(!isset(
$_GET['user'])) return false;
 
    if(isset(
$_GET['score']))
    {
        
$file fopen($_GET['user'] . '.txt''w');
        
fwrite($file$_GET['score']);
        
fclose($file);
    }
}
?>
I also don't know what the above user means about a .tk domain but I've tried going directly to this http://sgt-site.tk/hsa/get.php?user=1&score=1 and it worked fine, asides from the fact that I'm not on the remote address needed to execute the code, the page is there. So I don't see why the SA-MP http client would have a problem there.
Reply
#7

hm i had this bracket on before... when I posted this message I thought it's one too much so I removed it lol..
I added it again now, however it still doesn't work..
It just doesn't updates the score...
Reply
#8

I would advise doing some debugging with the variables in the PHP code to make sure that all of the variables are being passed as intended.

PHP код:
echo 'Request IP: '.$_SERVER['REMOTE_ADDR'].'<br>User: '.$_GET['user'].'<br>Score: '.$_GET['score']; 
Reply
#9

at which file?
at the image it would be senseless as I know that the score doesn't work...
at the get.php it won't work neither as it will bet my IP and not the server's
Reply
#10

Quote:
Originally Posted by Sascha
Посмотреть сообщение
at which file?
at the image it would be senseless as I know that the score doesn't work...
at the get.php it won't work neither as it will bet my IP and not the server's
In the get.php file, so you can debug the script. You need to put it before any of the checks are done, that is how you debug code.

PHP код:
<?php
echo 'Request IP: '.$_SERVER['REMOTE_ADDR'].'<br>User: '.$_GET['user'].'<br>Score: '.$_GET['score'];  
if(
$_SERVER['REMOTE_ADDR'] == '217.18.70.196')
{
    if(!isset(
$_GET['user'])) return false;
 
    if(isset(
$_GET['score']))
    {
        
$file fopen($_GET['user'] . '.txt''w');
        
fwrite($file$_GET['score']);
        
fclose($file);
    }
}
?>
Then visit the page and make sure everything is in order, particularly the IP part. Also the poster above me made a good point, you need to be sure that your hosting provider actually supports the use of PHP.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)