I'm trying to get all clients database id, but I've been unable to using foreach etc as it always returns the value as NULL.
I need to get a foreach with the database ids and put it in an array
$userchannel = $clients->cid->clientList["client_database_id"];
After some fiddling i managed to get this to work, please verifiy. If you have questions regarding the code. Feel free to ask them.
What i've done in basic is modifing the existed code from the examples shown in the teamspeak php framework site. I used the Android user list for the most code. From there on its just trying and debugging ;)
this code will print the database id of the user together with the username. (Ofcourse from this point you can do everything you want with it.)
Also, maybe take a quick look at the api documentation for the php framework. It has alot of useful coding tips and tricks.
https://docs.planetteamspeak.com/ts3/php/framework/
edit (07-01-17)
Something I also noticed, make sure the query user has enough rights, for ease I made mine server admin query (grants access to all options, Please be aware that this could be insecure in a active site!)
<?php
// load framework files
require_once("libraries/TeamSpeak3/TeamSpeak3.php");
try {
// connect to local server, authenticate and spawn an object for the virtual server on port 9988
$ts3_ServerInstance = TeamSpeak3::factory("serverquery://###:#######:##/?server_port=9987");
$selected_sid = $ts3_ServerInstance->serverList();
$ts3_VirtualServer = $ts3_ServerInstance->serverGetById($selected_sid);
/* walk through list of clients */
echo "<table class=\"list\">\n";
echo "<tr>\n" .
" <th>DB id</th>\n" .
" <th>Nickname</th>\n" .
"</tr>\n";
foreach($ts3_VirtualServer->clientList() as $client) {
echo "<tr>\n" .
" <td>" . $client['client_database_id'] . "</td>" .
" <td>" . htmlspecialchars($client) . "</td>" .
"</tr>\n";
}
echo "</table>\n";
}
catch(Exception $e) {
/* catch exceptions and display error message if anything went wrong */
echo "<span class='error'><b>Error " . $e->getCode() . ":</b> " . $e->getMessage() . "</span>\n";
}
I managed to fix it.
$ts3_VirtualServer->channelGetById(152) // 152 is the channel ID
Related
Background Information
I'm trying to figure out how to query our active directory server for information about users / groups via a php web application. (let's call it the "widget app". Ultimately, I'm going to use this information to try to "see" what fields / data is available in AD to check / use as a part of authentication besides just username and password. For example, I only want to allow people in specific AD groups ... etc.
I'm using this as an example:http://php.net/manual/en/ldap.examples-basic.php
Problem
Unfortunately, I'm getting zero results... even when I use my AD username as the filter.
this is what my results look like:
Connecting ...connect result is Resource id #26
Binding ...Bind result is 1
Searching for (sn=myusername*) ...Search result is Resource id #27
Getting entries ...
Data for 0 items returned:
What I've tried so far:
We have another web application that's running on the same web server as the widget app. This other application is set up so that apache will prompt for AD credentials. I know it works because when I try to authenticate myself on this secondary application, my AD credentials are authenticated and i'm given the authorization I need to use the application.
So I started to poke around the apache conf and tried to make sure my PHP code is using the same values.
The Code
Here's the PHP code that's currently failing:
public function ldap_test() {
echo "<h3>LDAP query test</h3>";
echo "Connecting ...";
$ds=ldap_connect("10.11.11.1111"); // must be a valid LDAP server!
echo "connect result is " . $ds . "<br />";
if ($ds) {
echo "Binding ...";
//$r=ldap_bind($ds);
$r=ldap_bind($ds,"CN=testvalue1,OU=Services,OU=Accounts,DC=td,DC=ab,DC=org", "somepasswordvalue");
// read-only access
echo "Bind result is " . $r . "<br />";
echo "Searching for (sn=myusername*) ...";
// Search surname entry
$sr=ldap_search($ds, "CN=testvalue1,OU=Services,OU=Accounts,DC=td,DC=ab,DC=org", "somepasswordvalue", "(sAMAccountName=myusername*)");
echo "Search result is " . $sr . "<br />";
echo "Number of entries returned is " . ldap_count_entries($ds, $sr) . "<br />";
echo "Getting entries ...<p>";
$info = ldap_get_entries($ds, $sr);
echo "Data for " . $info["count"] . " items returned:<p>";
for ($i=0; $i<$info["count"]; $i++) {
echo "dn is: " . $info[$i]["dn"] . "<br />";
echo "first cn entry is: " . $info[$i]["cn"][0] . "<br />";
echo "first email entry is: " . $info[$i]["mail"][0] . "<br /><hr />";
}
echo "Closing connection";
ldap_close($ds);
} else {
echo "<h4>Unable to connect to LDAP server</h4>";
}
}
Apache configuration that I used to build my PHP code: (this config works and properly prompts me for my AD credentials and authenticates properly)
<AuthnProviderAlias ldap ldap-test>
AuthLDAPBindDN "CN=testvalue1,OU=Services,OU=Accounts,DC=td,DC=ab,DC=org"
AuthLDAPBindPassword somepasswordvalue
AuthLDAPURL "ldap://10.11.11.111/ou=Accounts,dc=td,dc=ab,dc=org?sAMAccountName?sub?(objectClass=*)"
AuthLDAPMaxSubGroupDepth 5
</AuthnProviderAlias>
This is the first time I've tried to do AD authentication in PHP and I'm not the one who manages our AD implementations so I'm fairly green.
If you have any suggestions for me please feel free.
Thanks
The problem was that I was filtering by a common name. Notice this:
AuthLDAPBindDN "CN=testvalue1,OU=Services,OU=Accounts,DC=td,DC=ab,DC=org"
So to fix it , i just had to remove this from the filter and it worked.
AuthLDAPBindDN "OU=Services,OU=Accounts,DC=td,DC=ab,DC=org"
I'm probably missing something obvious; I'm trying to get the date from the returned data from setting up a subscription with Braintree Payments. My code is as follows:
$result1 = Braintree_Subscription::create($subscriptionData);
if ($result1->success) {
echo("Subscription ID: " . $result1->subscription->id . "<br />");
echo("Transaction ID: " . $result1->subscription->transactions[0]->id . "<br />");
echo("Type: " . $result1->subscription->transactions[0]->amount . "<br />");
//next line has error!!!!!!
echo("Date: " . $result1->subscription->billingPeriodEndDate . "<br />");
The first three "echo's" return what they are supposed to without problem. If I try and get any date value e.g: billingPeriodEndDate, billingPeriodStartDate, createdAt, updatedAt the page just fails, (nothing more is displayed) but there is no error. Error reporting is switched on. Any help appreciated.
If I remove the line where the error is and add the following below
echo "<ul>";
foreach ($result1 AS $item) {
echo "<li>" . $item . "</li>";
}
Then I can see the entire contents of the array. But I still cannot pull the bit I need out. The date is in the format:
billingPeriodEndDate=Friday, 01-Jan-16 00:00:00 UTC,
As it contains a comma that may be the problem...?
Thanks
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.
The date attributes return a DateTime object. Try formatting the date, you may be getting a Object of class DateTime could not be converted to string error.
echo("Date: " . $result1->subscription->billingPeriodEndDate->format('Y-m-d H:i:s') . "<br />");
Let me know if that helps!
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.
Without knowing the exact error I would guess that there is no default timezone set. Try setting one and see if it works.
date_default_timezone_set("America/Chicago")
I'm looking to create a formatted product list from an SQL database. My aim is to have a store on my website with a series of small boxes containing some shorthand information about each product, that when clicked will open a pop-up containing detailed information. (I have a working Javascript/JQuery code to create the pop-ups.)
Here is the PHP code so far, simply to get the information from the database and display it on a webpage...
(I've been using XAMPP to provide an environment for me to test the code in)
<?php
mysql_connect("localhost", "root", "") or die (mysql_error ());
mysql_select_db("Database1") or die(mysql_error());
$strSQL = "SELECT * FROM Products";
$rs = mysql_query($strSQL);
while($row = mysql_fetch_array($rs)) {
echo $row['Brand'] . " " . $row['ProductName'] . " " . $row['Image'] . "<br />";
}
mysql_close();
?>
I want the echoed line to be displayed in a divider, with a divider generated for each record in the SQL database (say I have 10 products available, there would be ten dividers, and 10 different boxes on the webpage). The divider's class is "ProductBox".
echo "<div class=\"ProductBox\">"; $row['Brand'] . " " . $row['ProductName'] . " " . $row['Image'] . "</div>";
This was the closest I have come to a solution, which was simply managing to write a code with no syntax errors - alas, nothing actually displays on the webpage.
If I'm going about this entirely the wrong way please tell me - I'm fairly sure I need to use a SQL database to dynamically update stock on a live website, but if I need to implement a different programming language or whatever then just tell me what you think would work and help me with a solution.
You have an extra semicolon in your code
echo "<div class=\"ProductBox\">"; $row['Brand'] . " " . $row['ProductName'] . " " . $row['Image'] . "</div>";
Replace with
echo "<div class=\"ProductBox\">". $row['Brand'] . " " . $row['ProductName'] . " " . $row['Image'] . "</div>";
mysql_fetch_array needs to be used like this (see PHP Doc):
while($row = mysql_fetch_array($rs, MYSQL_ASSOC)) {
}
or you could just use "mysql_fetch_assoc" instead.
HOWEVER, if you're new to PHP, I HIGHLY RECOMMEND that you get started on the right foot. mysql_query functions are soon to be deprecated. DON'T USE THEM. Most recommend using "PDO" for querying your database. Here's a great tutorial to teach you: http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers
Also, as mentioned, you have an extra semi-colon.
Dont forget these basics markups :
`<HTML>
<HEAD>
</HEAD>
<BODY> put in here your divs
</BODY>
</HTML>`
I posted a couple days ago and I could not insert an additional record into a MySQL database I setup. I corrected the syntax, but the database will not update again. Basically, I have a couple forms in HTML that carry sessions over to the next pages until the PHP is processes on the final page to INSERT into the database. It worked twice (I have 2 records in the database now), but it won't insert any additional records. It worked fine a couple days ago. The only changes I made to anything was that I added a search feature that accesses the same database with the same user, but the connection is closed at the end of that script as well. Here is the code I am using to INSERT into the database (I know it isn't the best coding job, I'm still learning).
<?php
$con = mysql_connect("localhost","my_username","mypassword");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("dgibbo1_imaging", $con);
// Here too, please mysql_real_escape_string() all parameters
mysql_query("INSERT INTO imaging (os,MAC,Model,AntiVirus,Browser,Email,Connectivity,Sound,Ports) VALUES ('".$_SESSION['imaging2']."','".$_SESSION['imaging3']."','".$_SESSION['imaging4']."','".$_SESSION['antivirus']."','".$_SESSION['browser']."','".$_SESSION['email']."','".$_SESSION['connectivity']."','".$_SESSION['sound']."','".$_SESSION['ports']."')");
OR die("Could not update: ".mysql_error());
mysql_close($con);
?>
The name of the database is imaging. The columns are setup as:
id (This is the primary key field)
os
MAC
Model
AntiVirus
Browser
Email
Connectivity
Sound
Ports
I just find it odd that it inserted records without any problems until I tried it again today. Is it possible that it has something to do with my code for the search?
The search is a simple form on another page and processes this form:
<?php
$con = mysql_connect("localhost","my_user","mypassword");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("dgibbo1_imaging", $con);
// Always escape parameters injected into SQL queries
$result = mysql_query( "SELECT * FROM imaging WHERE MAC LIKE '%"
. mysql_real_escape_string ( $search, $con )
. "%'"
);
echo "<table border='1'>
<tr>
<th>MAC</th>
<th>Model</th>
<th>AntiVirus</th>
<th>Email</th>
<th>Browser</th>
<th>Connectivity</th>
<th>Sound</th>
<th>Ports</th>
</tr>";
while($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['MAC'] . "</td>";
echo "<td>" . $row['Model'] . "</td>";
echo "<td>" . $row['AntiVirus'] . "</td>";
echo "<td>" . $row['Email'] . "</td>";
echo "<td>" . $row['Browser'] . "</td>";
echo "<td>" . $row['Connectivity'] . "</td>";
echo "<td>" . $row['Sound'] . "</td>";
echo "<td>" . $row['Ports'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
Meanwhile, the search will pull up the 2 existing records successfully every time, but I can't add new records and I'm wondering if it has something to do with this.
Thanks for any suggestions. I know my syntax probably isn't the best, so any suggestions from this site are always appreciated.
Try creating a separate php file and hard coding the values into it. Run that and see what happens. your search form shouldnt interfere with another form.
edit any errors when using the form? any errors when inserting to another table?
I saw your post, and it all looks "right". What I'd suggest is to add some logging instead of DIE and look at what MySQL is saying about those insert statements:
$sql = "INSERT INTO imaging ....";
mysql_query($sql);
if(mysql_errno()) {
$message = mysql_error() . "\n" . $sql . "\n";
$fp = fopen('c:\mylogifle.txt', 'a');
fwrite($fp, $message);
fclose($fp);
}
AND...as everyone has mentioned, encode those strings - assuming that the SQL is actually being executed, and you "know" it works, there's a very high possibility that some punctuation in one of the values is interfering with the SQL, like an unexpected comma somewhere that confuses MySQL
I have indexed a site using Nutch and now I am searching the index using the Zend Lucene library.
I've actually pulled the Zend libraries into Codeigniter but it is all Zend doing the work.
I can display the title, score and url fine but I can't find the name of the field to display the content from the page.
So far I have the following code
$index = new Zend_Search_Lucene('C:\nutch\nutch-0.9\my-search\index');
$query = $this->input->post('searchQuery');
$hits = $index->find($query);
echo "<p>Index contains " . $index->count() . " documents.</p>";
echo "<p>Search for '" . $query . "' returned " . count($hits) . " hits</p>";
foreach ($hits as $hit)
{
echo "<h4>" . $hit->title . "</h4>";
echo "<p><b>Score:</b> " . sprintf('%.2f', $hit->score) . "</p>";
echo "<p><b>Url:</b> " ."<a href='" . $hit->url . "'>" . $hit->url. "</a></p>";
}
Can anyone help out with the name of the field to display the content or a content summary?
Thanks
I don't know the nutch index format, but whenever I need to check a lucene index I use Luke - Lucene Index Toolbox
It allows you to open an index directory, browse fields and run queries. Very helpful if you're using an unfamiliar index.