I was wondering how to log stuff from http.Fetch to a webpage with PHP. I'm trying to make a suggestions system for something I'm having tested and I want it to be logged to a page. Any ideas how I would do this.
(FYI, I have minimal knowledge of PHP)
If you're using a MySQL database with the server connecting to the same one that is used by the web-server you could simply insert suggestions into a MySQL table, then simply fetch them and list them in PHP or in game...
If you do want to use the PHP route, you'd set up an HTML page with a form. What ever you name the elements of the form will be in ( if you set the form method to post instead of get whereas post is behind the scenes and get is ?x= ... &y= ... &z= ... in urls ) you'd have php code in either the same page ( if you have the webserver configured to parse php in .html, or it is a .php file ) or a separate file ( with the form pointing to it ) to read the form data such as:
[code]<?php
// Assuming we used the names in the url explanation above in a form GET, we'd use:
$x = $_GET[ 'x' ];
$y = $_GET[ 'y' ];
$z = $_GET[ 'z' ];
// If we used a form POST method, then change _GET to _POST. Also, before you insert, be sure to escape the data
?>[/code]
That would be insert; you could have that shown to players in game by creating an HTML or DHTML panel and pointing to the url.
For displaying, you'd need to query the data source ( MySQL, TXT flat file, etc ) and display it in a PHP file...
It may be easier to have a suggestions system simply built using Lua.
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/http/Post]http.Post[/url]
[Lua]
http.Post( "http://somedomain.com/file.php", { test = "Hello" } )
[/lua]
[Code]
<?php
echo $_POST[ 'test' ]
?>
[/code]
[editline]10th December 2014[/editline]
Then use fetch to retrieve the suggestions.
remember to use $_GET with fetch
Now how would I log these onto the page as just separate elements without MySQL?
If you keep it in-game you could store it in SQLite database, or you could store data in a file. You can also store data in a flat-file using PHP too.
My site with the PHP tuts isn't up at the moment ( I plan on reviving it and adding my Lua tuts ) but here are some for Lua with files: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/files/creating_files_with_numerically_incrementing_titles_and_saved_index.lua.html[/url]
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/blacklist_names/sv_blacklist_names_newline_file_format.lua.html[/url]
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/blacklist_names/sv_blacklist_names.lua.html[/url]
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/simple_slay_next_round/sv_slaynr.lua.html[/url]
[QUOTE=Acecool;46683136]If you keep it in-game you could store it in SQLite database, or you could store data in a file. You can also store data in a flat-file using PHP too.
My site with the PHP tuts isn't up at the moment ( I plan on reviving it and adding my Lua tuts ) but here are some for Lua with files: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/files/creating_files_with_numerically_incrementing_titles_and_saved_index.lua.html[/url]
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/blacklist_names/sv_blacklist_names_newline_file_format.lua.html[/url]
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/blacklist_names/sv_blacklist_names.lua.html[/url]
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/simple_slay_next_round/sv_slaynr.lua.html[/url][/QUOTE]
I'd use the file method, but I don't have access to the server's data folder nor do I want to have to have tons of files be deleted and redownloaded for every suggestion, which I why I wanted help with what I asked for in the begining
can u elaborate on "suggestions"
You wouldn't need to create many files.. you could create one ( and the data folder should be accessible ) and save suggestions in JSON format with info such as player name / steam / suggestion and you could pull it to read while you're on the server.
If you want it web based I gave help on _POST and _GET vars and how they're named in relation to the form fields. If you did use http.Fetch ( you'd set the url to [url]http://www.example.com/form_page.php?first_var=first_value_urlencoded&second_var=second_value_urlencoded&third=x[/url] ... follow the pattern with ? being first delimiter and & being all others -- $_GET[ 'first_var' ] == "first_value_urlencoded" and so on )
or
http.Post with post values being $_POST[ 'first_var' ]; ...
PHP form handlers are very straight forward; it just depends on how you want to store the data, and retrieve the data. You could store them in a flat-file, or in the database provided your server has MySQL module activated. Upload this file ( and remove it after getting data ):
[code]<?php
phpinfo( INFO_MODULES );
?>[/code]
for just modules... or:
[code]<?php
phpinfo( );
?>[/code]
for the entire information sheet.
We've provided "suggestions" and we recognize that you have minimal experience with PHP but we won't create the entire thing for you ( that wheel exists in many forms of examples and finished solutions online for both MySQL and Flat-File implementations ).
We have been providing viable solutions for your server to be implemented in Lua ( for the entire system so you'd need to be in your server to view suggestions or have access to rcon to output the data OR for the form which could be made using vgui elements and sent using http.Fetch or http.Post OR having the system entirely on your website with the game loading the page using HTML or DHTML elements ) because you wanted a suggestions form for your server which could be implemented in many ways; you could have a form completely in vgui elements, and in HTML for those that browse your site with a single php form get/post page to log the info.
Regardless of the implementation solution, you're still going to need to either learn the language or hire someone.
Sorry, you need to Log In to post a reply to this thread.