I made a script with the PHP Teamspeak Framework to check if a user is online.
I want to get input from the URL, so index.php?in=myname
My script:
<?php
global $input;
$input = $_GET["in"];
function OnlineTS() {
require_once("/ts3/libraries/TeamSpeak3/TeamSpeak3.php");
$ts3_VirtualServer = TeamSpeak3::factory("serverquery://ts.mydomain.com:10011/?server_port=9987");
global $input;
if ($input != "") {
$client = $ts3_VirtualServer->clientGetByName($input);
echo "<h2>" . $input . ' is online on teamspeak in channel "' . $ts3_VirtualServer->channelGetById($client['cid']) . '"</h2>';
}
}
OnlineTS();
?>
trying index.php?in=myname (who is online) doesn't work.
Can I get some help?
Try:
$input = $_REQUEST["in"];
echo $input;
Related
I have this code that access a api and gets the data and outputs it on my site, but I'm having a problem with the arrays and etc. I was wondering how can I access that data needed.
My problem is in:
foreach($entrieszz as $statSummaryzz)
{ $gamemodematchhistoryfellowPlayerslolsearch = $statSummaryzz->fellowPlayers->teamId; }
and its giving me error: Trying to get property of non-object
The data im trying to access:
Trying to get games->fellowPlayers->teamId and also games->fellowPlayers->championId
This is what I have:
<?php
$apiKey = 'e9044828-20e3-46cc-9eb5-545949299803';
$summonerName = 'tamini';
$new = rawurlencode($summonerName);
$news = str_replace(' ', '', $summonerName);
$str = strtolower($news);
// get the basic summoner info
$result = file_get_contents('https://euw.api.pvp.net/api/lol/euw/v1.4/summoner/by-name/' . $new . '?api_key=' . $apiKey);
$summoner = json_decode($result)->$str;
$id = $summoner->id;
// var_dump($summoner);
?>
<?php
$clawzzeyu = file_get_contents('https://euw.api.pvp.net/api/lol/euw/v1.3/game/by-summoner/' . $id . '/recent?api_key=' . $apiKey);
$gazazzeyu = json_decode($clawzzeyu);
$entrieszz = $gazazzeyu->games;
usort($entrieszz, function($accc,$bccc){
return $bccc->createDate-$accc->createDate;
});
foreach($entrieszz as $statSummaryzz){
$gamemodematchhistoryfellowPlayerslolsearch = $statSummaryzz->fellowPlayers->teamId;
}
?>
In your json sample there isn't teamId but only team
could be need
foreach($entrieszz as $statSummaryzz){
$gamemodematchhistoryfellowPlayerslolsearch = $statSummaryzz->fellowPlayers->team;
}
I have a basic online visitors counter. I get it from here. It works verry well but I have a issue. I use it on online game and I have multiple servers. I use it for server online counter. I did add counter pages to the servers via iframe and it counts very well.
But the problem is, I want to display that numbers on index (index.php) page. But when I use :
<?php include("server1.php");?>
it counts index page users as well. I don't want this. How can I make it don't count IP's from index.php?
Here, my codes
Counter (server1.php)
<?php
$dbfile = "game/database/1.db"; // path to data file
$expire = 100; // average time in seconds to consider someone online before removing from the list
if(!file_exists($dbfile)) {
die("Error: Data file " . $dbfile . " NOT FOUND!");
}
if(!is_writable($dbfile)) {
die("Error: Data file " . $dbfile . " is NOT writable! Please CHMOD it to 666!");
}
function CountVisitors() {
global $dbfile, $expire;
$cur_ip = getIP();
$cur_time = time();
$dbary_new = array();
$dbary = unserialize(file_get_contents($dbfile));
if(is_array($dbary)) {
while(list($user_ip, $user_time) = each($dbary)) {
if(($user_ip != $cur_ip) && (($user_time + $expire) > $cur_time)) {
$dbary_new[$user_ip] = $user_time;
}
}
}
$dbary_new[$cur_ip] = $cur_time; // add record for current user
$fp = fopen($dbfile, "w");
fputs($fp, serialize($dbary_new));
fclose($fp);
$out = sprintf("%03d", count($dbary_new)); // format the result to display 3 digits with leading 0's
return $out;
}
function getIP() {
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
elseif(isset($_SERVER['REMOTE_ADDR'])) $ip = $_SERVER['REMOTE_ADDR'];
else $ip = "0";
return $ip;
}
$visitors_online = '0'+CountVisitors();
?>
<?=$visitors_online;?>
Iframe (I use it on server pages)
<iframe name="visitors" src="../1.php" width="1" hidden="true" height="1" frameborder="0" scrolling="no"></iframe>
php include (index.php)
Server 7 - Online Players:<?php include("7.php");?>
make a server2.php with this code
<?php
$dbfile = "game/database/1.db"; // path to data file
$expire = 100;
if(!file_exists($dbfile)) {
die("Error: Data file " . $dbfile . " NOT FOUND!");
}
if(!is_writable($dbfile)) {
die("Error: Data file " . $dbfile . " is NOT writable! Please CHMOD it to 666!");
}
function CountVisitors() {
global $dbfile, $expire;
$cur_time = time();
$dbary_new = array();
$dbary = unserialize(file_get_contents($dbfile));
if(is_array($dbary)) {
while(list($user_ip, $user_time) = each($dbary)) {
if(($user_time + $expire) > $cur_time) {
$dbary_new[$user_ip] = $user_time;
}
}
}
$out = sprintf("%03d", count($dbary_new)); // format the result to display 3 digits with leading 0's
return $out;
}
$visitors_online = '0'+CountVisitors();
?>
<?=$visitors_online;?>
and use it like server1.php
I have a community site, where people can put up pages, and the url generates from their name. e.g. My Business, becomes my-business. I want to create a way, that if there is another My Business, it will check and make the url my-business-2, my-business-3, etc.
function check_url($url) {
$qry = mysqli_query($this->con, "SELECT * FROM businesses WHERE url LIKE '$url%'");
if(mysqli_num_rows($qry)>0) {
$slugs = array();
while($row = mysqli_fetch_array($qry)) $slugs[] = $row['url'];
if(in_array($url, $slugs)) {
$max = 1;
while(in_array(($url . '-' . ++$max ), $slugs)) $url .= '-' . $max;
}
}
return $url;
}
This is my function, but this still wont work, as if there is a business called My Bus, it will make it my-bus-2, when it would have been unique at my-bus. I have experimented with other functions too, but this one is the closest I got. Can anyone tell me one that works perfectly?
So form my understanding, you are trying to avoid inserting/generating duplicate URL. Output will be something like this -
www.example.com/my-business
www.example.com/my-business-1
www.example.com/my-business-2
www.example.com/my-business-3
...
Try using this function -
function check_url($base_url, $new_url='', $num=0) {
if($new_url == '') {
$new_url = $base_url;
}
$qry = mysqli_query($this->con, "SELECT * FROM businesses WHERE url = '$new_url'");
if(mysqli_num_rows($qry) > 0) {
while($row = mysqli_fetch_array($qry)) {
$num++;
check_url($base_url, $base_url . '-' . $num, $num);
}
}
return $url;
}
Basically, this function will check the database until it finds a valid URL. Each time it will increment the number and recursively call the same function to generate new/valid URL.
Simple and basic!
#SpritsDracula has working code, but his function will query your database each time it executes. That being said, the recursion is a nice concept. Here is a piece of code that will save your the multiple database calls.
function check_url($url) {
$qry = mysqli_query($this->con, "SELECT * FROM businesses WHERE url LIKE '$url%'");
if(mysqli_num_rows($qry)>0) {
$baseUrl = $url;
$slugs = [];
while($row = mysqli_fetch_array($qry)) $slugs[] = $row['url'];
$max = 1;
while(in_array($url, $slugs)) {
$url = $baseUrl . "-" . $max++;
}
}
return $url;
}
I have the following snippet:
$post_ids = array("307781172646235_739219686169046");
$quoted_post_ids = array();
foreach ($post_ids as $id) {
$quoted_post_ids[] = '"' . $id . '"';
}
$fql = urlencode(
"SELECT attachment FROM stream WHERE post_id IN(" . implode(',', $quoted_post_ids) . ")"
);
$all_photos_url = 'https://graph.facebook.com/fql?q=' . $fql . '&access_token=' . "XXXXXXXX";
$all_photos_result = drupal_http_request($all_photos_url);
$all_photos = json_decode($all_photos_result->data);
dpm($all_photos);
$actual_post = NULL;
foreach ($all_photos->data as $k => $post) {
$actual_post = array();;
foreach ($post->attachment->media as $photo) {
if (isset($photo->photo)) {
$photo_url = 'https://graph.facebook.com/' . $photo->photo->fbid;
$photo_result = drupal_http_request($photo_url);
$photo_info = json_decode($photo_result->data);
if (isset($photo_info->images[0])) {
$candidate_pic_url = $photo_info->images[0]->source;
if (!empty($candidate_pic_url) && valid_url($candidate_pic_url)) {
if (!isset($actual_post['picture_big'])) {
$actual_post['picture_big'] = array();
}
$actual_post['picture_big'][] = $candidate_pic_url;
$actual_post['picture_metadata'][] = $photo_info;
}
}
usleep(500);
}
}
dpm($actual_post);
}
The dpm() is just a Drupal-specific debug helper that outputs the variable. So the issue is that if I execute it at localhost, or on a staging server, it works, but on production, I do not have the image always via the graph API. Sometimes, I have, sometimes i does not have. It's a shared hosting at Gandi (https://www.gandi.net/hosting/simple) . Is it possible that the shared hosting itself becomes rate-limited?
Update:
On production, the second HTTP request gives: "Application request limit reached" OAuth Exception
I am trying to work this function in wordpress theme the way where I can get value only what I want and not all to gather. I am not much familiar with using array in function so I need you expert help to make it works and I would really appreciate that.
Here is my code
function gallery_artist($arg=null, $arg2=null, $arg3=null){
global $png_gallery_meta;
$png_gallery_meta->the_meta();
$gallery = get_post_meta(get_the_ID(), $png_gallery_meta->get_the_id(), TRUE);
$gallery_value = $gallery['image_artist'];
$artist_info = $gallery_value;
$string = $artist_info;
$artist = substr($string, 0, stripos($string, "/") );
// getting first name and last name from user id
$author_first_name = get_userdata(basename($string))->first_name;
$author_last_name = get_userdata(basename($string))->last_name;
$author_full_name = $author_first_name . ' ' . $author_last_name;
$user_id = '<a href=" ' . get_author_posts_url(basename($string)) . ' " title="more submissions of ' . $author_first_name .' '. $author_last_name . ' " >' . $artist . '</a>';
$arg = $author_first_name;
echo $arg;
$arg2 = $author_last_name;
echo $arg2;
$arg3 = $user_id;
echo $arg3;
}
After than I want to use this function to get any value I want and not unnecessary to render all three to gather. Means if I want only first name than I pass value only for that and it will render only first name so on..
Here how I want to use something. but you can suggest any code and type of function I have no issue.
<?php call_user_func_array('gallery_artist', array('first_name','last_name','artist_id') ) ?>
Big Big thanks to you all..
Try replacing the bottom section with this:
if(!is_null($arg))
{
$arg = $author_first_name;
echo $arg;
}
if(!is_null($arg2))
{
$arg2 = $author_last_name;
echo $arg2;
}
if(!is_null($arg3))
{
$arg3 = $user_id;
echo $arg3;
}