Jump to content

about PHP sdk


SkatCh

Recommended Posts

hi guys :) please i need some help , i have a simple question how can add players names inside my website using php sdk i know how to use callRemote , i add this and it's working fine i can see 'done' in my debugString but what i need to do to finish the php file.

addEventHandler("onResourceStart", getRootElement(), 
function(theMap) 
    local playerList = getPlayersName() 
    if playerList then 
        callRemote("My website", returnFunction, playerList) 
    end 
end) 
  
function returnFunction(value) 
    if value ~= "ERROR" then 
       outputDebugString("done") 
    end 
end 
  
function getPlayersName() 
    local playerslist = {} 
    for i,p in ipairs (getElementsByType("player")) do 
        local thep = string.gsub(getPlayerName(p), "#%x%x%x%x%x%x", "") 
        table.insert(playerslist,tostring(thep)) 
    end 
    return playerslist 
end 

Link to post
callRemote ( 'http://www.yoursite.com/example.php/' .. toJSON ( playerNamesTable ), function ( value ) 
     if ( value == 'ok' ) then -- A var from your website meaning that worked. 
         outputDebugString ( 'Player list sent successfully.' ) 
     end 
end) 

But... You'll need to do a php script to receive and read the data.

Link to post
bro i'm asking about the php part i already told you that my script is working fine , juts my question is what i need to type inside the php file.
  
  
$table = json_decode(str_replace("/example.php/","",$_SERVER["PHP_SELF"])); 
-- then you can whatever you want =D. 
  

Link to post

sorry i don't undrestand can you explane to me.

this is my script ;

- server side

addEventHandler("onResourceStart", getRootElement(), 
function(theMap) 
    local playerList = getPlayersName() 
    if playerList then 
        callRemote("My website", returnFunction, playerList) 
    end 
end) 
  
function returnFunction(value) 
    if value ~= "ERROR" then 
       outputDebugString("done") 
    end 
end 
  
function getPlayersName() 
    local playerslist = {} 
    for i,p in ipairs (getElementsByType("player")) do 
        local thep = string.gsub(getPlayerName(p), "#%x%x%x%x%x%x", "") 
        table.insert(playerslist,tostring(thep)) 
    end 
    return playerslist 
end 

and what i need to add inside the PHP

Link to post
sorry i don't undrestand can you explane to me.

this is my script ;

- server side

addEventHandler("onResourceStart", getRootElement(), 
function(theMap) 
    local playerList = getPlayersName() 
    if playerList then 
        callRemote("My website", returnFunction, playerList) 
    end 
end) 
  
function returnFunction(value) 
    if value ~= "ERROR" then 
       outputDebugString("done") 
    end 
end 
  
function getPlayersName() 
    local playerslist = {} 
    for i,p in ipairs (getElementsByType("player")) do 
        local thep = string.gsub(getPlayerName(p), "#%x%x%x%x%x%x", "") 
        table.insert(playerslist,tostring(thep)) 
    end 
    return playerslist 
end 

and what i need to add inside the PHP

Hm, what i posted is just a way to get the table inside the PHP( in that case $table ).

Link to post

You don't really need to use the PHP SDK to display players who are online. All you'd need to do is dbConnect and dbExec to truncate (clear) the table and insert all online players every now and then. The website can then use PDO or Mysqli to access the database and retrieve the online players, and write them to the HTML code.

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...