PDA

View Full Version : the HTTP_GET (Website side)


Shaneisace
08/08/2012, 01:25 AM
Hello there everyone could someone explain to me how the website side works I've seen people use it for Radio Stations and other cool things.

But on the SA-MP Wiki it doesn't really show much detail on the website side as i've understood how it works Script side but i want to make it on file on my webhost

Example I'm thinking of making a music station that brings a list so i can update it without re-starting the server

but i'm confused on how to grab this information from a .php if someone could help get me started that would be great example of what i want to do is below:

test.php?listsongs=1 i want to make it like that but unsure how to start it.

I've have knowledge with PHP just not even to make it like the URL above :s

Can someone help me get started (I'm not asking you to make me one just start one) thanks for reading.

AustinJ
08/08/2012, 03:07 AM
For the php side of the script you wound't really need a get varible to be ran though the url. Just have your php page list your stations.

So in Pawn you would call your page via HTTP(0, HTTP_GET, "yourdomain.com/yourscript.php", "", "HttpResult");
Then you want to make the 'HttpResult' public callback.public HttpResult(index, response_code, data[])
{
// data[] is your PHP script ouputed source code.
}

Hope that is enough information to get you started.

Shaneisace
08/08/2012, 03:21 AM
For the php side of the script you wound't really need a get varible to be ran though the url. Just have your php page list your stations.

So in Pawn you would call your page via HTTP(0, HTTP_GET, "yourdomain.com/yourscript.php", "", "HttpResult");
Then you want to make the 'HttpResult' public callback.public HttpResult(index, response_code, data[])
{
// data[] is your PHP script ouputed source code.
}

Hope that is enough information to get you started.

i understand that but I'm confused on how to use like this test.php?listsongs=1 and after it lists it when they click on one i can show information using the same php like test.php?listsongs=%d&info do you get where I'm going with it?

AustinJ
08/08/2012, 03:29 AM
You would call a php page with a get variable like such new string[128];
format(string, 128, "yourdomain.com/yourscript.php?listfor=%i", stationid);
HTTP(0, HTTP_GET, string, "", "HttpResult");

And for the php page you would do something like this. if(isset($_GET["listfor"])) // List Songs
{
$stationid = $_GET["listfor"];
}
else // List Stations
{

}

Shaneisace
08/08/2012, 03:47 AM
You would call a php page with a get variable like such new string[128];
format(string, 128, "yourdomain.com/yourscript.php?listfor=%i", stationid);
HTTP(0, HTTP_GET, string, "", "HttpResult");

And for the php page you would do something like this. if(isset($_GET["listfor"])) // List Songs
{
$stationid = $_GET["listfor"];
}
else // List Stations
{

}

Thanks this is what i'm sort of thing i was looking for :) Now i can take time to learn it cheers

AustinJ
08/08/2012, 04:08 AM
Your welcome, I didn't want to tell you how to do it in great detail since that would ruin the fun of learning & scripting it :)

Shaneisace
08/08/2012, 04:17 AM
Your welcome, I didn't want to tell you how to do it in great detail since that would ruin the fun of learning & scripting it :)

Its coming back to me now, if i do test.php i got it to return "Something went wrong" but if i do test.php?Listsongs=1 it returns "Line 1" even though this is just done by the Web Browser lol :P

I would REP you but i don't have 50 posts :(

EDIT: Never mind it said i reped you lol

EDIT: I get response error 6 now, i guess it means "HTTP_ERROR_MALFORMED_RESPONSE" do you know what that means?

AustinJ
08/08/2012, 04:28 AM
What is shown in the web browser is the value of data[]. If you write click a page and do view source that is what data[] will be, from what I understand. Taking this into effect if you are going to use a web host with ads this may not work since the code for the ads will be returned to the data[] string also.

EDIT: As for `HTTP_ERROR_MALFORMED_RESPONSE` I have no clue to what that means out of my many years of scripting web based languages.

Shaneisace
08/08/2012, 04:44 AM
well the only thing sent as Data[] will be "Line 1" as its just a blank .php with the PHP code

here's the code

<?
if (isset($_GET['listsongs'])) // List Songs
{
echo "Line 1";

}
else // List Stations
{
echo "Something went wrong";
}
?>

AustinJ
08/08/2012, 04:59 AM
Hmm... I am not sure why. I haven't really used the http functions in pawn before so I am not 100% sure about them. I know at one point I had a script and my php page echoed out a line to the console saying that it executed and when there was an ad on the page I saw the ad's code along with my echo'ed output,

Shaneisace
08/08/2012, 05:02 AM
Hmm... I am not sure why. I haven't really used the http functions in pawn before so I am not 100% sure about them. I know at one point I had a script and my php page echoed out a line to the console saying that it executed and when there was an ad on the page I saw the ad's code along with my echo'ed output,

Maybe it's something i'll have to search on :P also i don't have ads on my webhost so it can't be that problem :P, well thanks for the help so far anyway :)