PHP - Vbulletin, Sourcebans 1.4 Connection
Hey Ya'll I'm looking for help on making this actually work...
The code was thrown together a couple tears ago and post'ed on both alliedmods and vbulletin forums..
As far as I know I have yet to find someone fix and make it work properly..
I would be willing to donate a small sum if someone would be willing to help me get this working...
Two things that need to be changed with the current code is -
The steam id is not sorted in the userfield table.. It is now stored in the user table under steam_code
I have a forum and a sb DB up and available for testing if needed..
The code I'm pasting a re-work.. The one attached is the original... I would like either working.. I just need it working!!!!
<?php //THIS CODE IS INTENDED FOR USE AS A VBULLETIN 4 CRON SCRIPT, IT REQUIRES THE VBULLETIN GLOBAL VAR PROVIDED BY CRONMANAGER.PHP - YOU MAY EMULATE THIS FUNCTIONALITY BY INCLUDING THE VBULLETIN GLOBAL.PHP //RECCOMENDED SCHEDULE IS EVERY 30 MINUTES TO 1 HOUR // ############################# VARIABLES ################################ mysql_pconnect("******", "root", "*****"); //MYSQL information for the SourceBans/Vbulletin Database $db_sourcebans = "sourcebans"; //Database name for SourceBans $steamid_custom_field = "field11"; //The custom field id for the users SteamID, it is reccomended that you only let the user set their steamid on signup or you may have people changing their steamid's and giving other people admin. define("DB_PREFIX", "sb"); //Table Prefix for SourceBans $groups_with_admin = array(19,18,13,15,16,17); // Comma delimited list of vBulletin groups with admin. $ban_site_url = "http://98.224.170.160.com/bans"; //URL to the Sourcebans installation, no trailing forward slash $clan_name = "[mFc.] Middle Fingah Click"; // Name of your clan $pm_from_userid=1; //The vBulletin UserID to send the PM from $pm_from_user_text="wtfaatp"; //The vBulletin Username to send the PM from // ######################## SET PHP ENVIRONMENT ########################### mysql_select_db($db_sourcebans); mysql_set_charset('utf8'); require "CServerRcon.php"; //This file can be found in Sourcebans_web/includes/ and must be located in the same folder as this script. error_reporting(E_ALL & ~E_NOTICE); //Prevents "Notices" From showing up if (!is_object($vbulletin->db)) // Checks if the vbulletin database is accessiable, otherwise exit the script. { exit; } $vbulletin->db->hide_errors(); // Hide Database errors from Vbulletin // ############################ FUNCTIONS ################################ function encrypt_password($password, $salt='SourceBans') // If you use a different salt for your sourcebans installation, Change this. { return sha1(sha1($salt . $password)); } function getRandomPassword($length = "") //Returns a random alphanumeric string of the specified length, 32 chars if unspecified { $code = md5(uniqid(rand(), true)); if ($length != "") return substr($code, 0, $length); else return $code; } function AddAdmin($sourcebans_group_web, $sourcebans_group_server, $sourcebans_group_server_name, $sourcebans_group_server_access, $username, $email, $steamid, $userid) { $password = getRandomPassword(8); // Generate a password for the user $res2 = mysql_query("SELECT `aid`, `group_id` FROM ".DB_PREFIX."_admins LEFT JOIN ".DB_PREFIX."_admins_servers_groups ON ".DB_PREFIX."_admins.aid=".DB_PREFIX."_admins_servers_groups.admin_id WHERE user='".mysql_real_escape_string($username)."'") or die(mysql_error()); //A quick query so we can check to see if the admin is already an admin and whether they've been promoted or not $row2 = mysql_fetch_assoc($res2); // Fetch the result from the previous query mysql_query("INSERT INTO ".DB_PREFIX."_admins(user, authid, password, gid, email, srv_group) VALUES ('".mysql_real_escape_string($username)."','".mysql_real_escape_string($steamid)."','".encrypt_password($password)."',".$sourcebans_group_web.",'".mysql_real_escape_string($email)."','".mysql_real_escape_string($sourcebans_group_server_name)."') ON DUPLICATE KEY UPDATE srv_group='".mysql_real_escape_string($sourcebans_group_server_name)."', gid='".$sourcebans_group_web."'") or die(mysql_error()); // Add the admin to the SourceBans database or, if they already exist, update their group data. if(mysql_affected_rows() > 0) //Check if the last query affected any rows, did it change anything or add a new admin? If no, skip. { $res3 = mysql_query("SELECT `aid` FROM ".DB_PREFIX."_admins WHERE user='".mysql_real_escape_string($username)."'") or die(mysql_error()); // Select the users AdminID $row3 = mysql_fetch_assoc($res3);// Fetch the result from the previous query mysql_query("DELETE FROM ".DB_PREFIX."_admins_servers_groups WHERE admin_id='".$row3['aid']."'") or die(mysql_error());//Delete the users admin group data from the table mysql_query("INSERT IGNORE INTO ".DB_PREFIX."_admins_servers_groups(admin_id, group_id, srv_group_id, server_id) VALUES (".$row3['aid'].",".$sourcebans_group_server.",".$sourcebans_group_server_access.", -1)") or die(mysql_error()); //Add back their new data. //This next bit handles the PMs, the promotion/demotion will only work if your "highest power" admin group is the first id and the "lowest power" is the last id. i.e - Managers = GID1, Council = GID2, Admins = GID3, Members = GID4, Recruits = GID5 if(mysql_num_rows($res2) == 0) { SendPM($userid, $username, $sourcebans_group_server_name, $password, 0); //Send the user a message with their password and username telling them that they've been added to the system. } elseif ($sourcebans_group_server > $row2['group_id']) { SendPM($userid, $username, $sourcebans_group_server_name, $password, 1); //Tell the user that they have been promoted in sourcebans. } elseif ($sourcebans_group_server < $row2['group_id']) { SendPM($userid, $username, $sourcebans_group_server_name, $password, 2); //Tell the user that they have been demoted in sourcebans. } } } function SendPM($pm_userid, $pm_username, $pm_group_name, $pm_password, $text) // Send a PM to the user, there is an actual datamanager API in vB for this, but it wasn't working reliable so I fell back on this method { global $vbulletin, $ban_site_url, $clan_name, $pm_from_userid, $pm_from_user_text; switch($text) //The messages, pretty self explanatory which is which. { case 0: $pm_text_title="Added to Sourcebans"; $pm_text="[CENTER][IMG]".$ban_site_url."/images/logos/sb-large.png[/IMG] [/CENTER] [LEFT][FONT=Garamond][SIZE=4]Hello ".$pm_username.", You have been added as a ".$pm_group_name." to the ".$clan_name." admin system. Please find below the details required to login to the admin web panel, you will be able to access in-game admin automatically. Username: [B]".$pm_username."[/B] Password: [B]".$pm_password."[/B] You can use this information to login into your new account at: ".$ban_site_url."/index.php?p=login It is HIGHLY recommended for security reasons that you change your password to something memorable once you login. If you have any questions please contact me about any problems. Many thanks, ".$pm_from_user_text." [/SIZE][/FONT][/LEFT]"; break; case 1: $pm_text_title="Promoted in Sourcebans"; $pm_text="[CENTER][IMG]".$ban_site_url."/images/logos/sb-large.png[/IMG] [/CENTER] [LEFT][FONT=Garamond][SIZE=4]Hello ".$pm_username.", Congratulations! You have been promoted to a ".$pm_group_name." on the ".$clan_name." admin system. Your login details are the same as before. You can use this information to login into your account at: ".$ban_site_url."/index.php?p=login If you have any questions please contact me about any problems. Many thanks, ".$pm_from_user_text." [/SIZE][/FONT][/LEFT]"; break; case 2: $pm_text_title="Demoted in Sourcebans"; $pm_text="[CENTER][IMG]".$ban_site_url."/images/logos/sb-large.png[/IMG] [/CENTER] [LEFT][FONT=Garamond][SIZE=4]Hello ".$pm_username.", We are afraid that you have been demoted to a ".$pm_group_name." on the ".$clan_name." admin system. Your login details are the same as before. You can use this information to login into your account at: ".$ban_site_url."/index.php?p=login If you have any questions please contact me about any problems. Many thanks, ".$pm_from_user_text." [/SIZE][/FONT][/LEFT]"; break; case 3: $pm_text_title="Removed from Sourcebans"; $pm_text="[CENTER][IMG]".$ban_site_url."/images/logos/sb-large.png[/IMG] [/CENTER] [LEFT][FONT=Garamond][SIZE=4]Hello ".$pm_username.", We are afraid that you have been removed from the ".$clan_name." admin system. If you have any questions please contact me about any problems. Many thanks, ".$pm_from_user_text." [/SIZE][/FONT][/LEFT]"; break; } $botpermissions['adminpermissions'] = 6; $pmdm =& datamanager_init('PM', $vbulletin, ERRTYPE_ARRAY); $pmdm->overridequota = true; $pmdm->set('fromuserid', $pm_from_userid); $pmdm->set('fromusername', $pm_from_userid_text); $pmdm->set_info('receipt', $vbulletin->GPC['receipt']); //false $pmdm->set_info('savecopy', $vbulletin->GPC['savecopy']); //false $pmdm->set('allowsmilie', $vbulletin->GPC['allowsmilie']); //true $pmdm->set('title', $pm_text_title); $pmdm->set('message', $pm_text); $pmdm->set_recipients($pm_username, $botpermissions); $pmdm->set('dateline', TIMENOW); $pmdm->pre_save(); if (empty($pmdm->errors)) { $pmdm->save(); } else { echo "<hr><b><font color=red>PM was not sent, Reason:</font></b><pre>"; print_r($pmdm->errors); echo "</pre><hr> "; } unset($pmdm); } // ######################################################################## // ######################### START MAIN SCRIPT ############################ // ######################################################################## $res = $vbulletin->db->query_read("SELECT `username`, `user`.`userid` as userid, `usergroupid`, `membergroupids`, `email`, `".$steamid_custom_field."` FROM ". TABLE_PREFIX ."user LEFT JOIN `". TABLE_PREFIX ."userfield` ON `user`.`userid`=`userfield`.`userid`"); //Select all users from the Vbulletin Database while($row = mysql_fetch_assoc($res)) { // CLEANUP OLD/INVALID ADMINS $res2 = mysql_query("SELECT `aid` FROM ".DB_PREFIX."_admins WHERE user='".$row['username']."'") or die(mysql_error()); //Check if the user has a sourcebans account $row2 = mysql_fetch_assoc($res2); if (mysql_num_rows($res2)>0 && !in_array($row['usergroupid'], $groups_with_admin)) //If yes, and they are not in one of the admin groups defined above then... { $additionaluser=false; for($i = 0; $i < count($user_additional_groups); $i ++) //Check if they are marked as an additional user to any of the admin groups defined above { if (in_array($user_additional_groups[$i], $groups_with_admin)) { $additionaluser=true; break; } } if($additionaluser == false) // If they aren't remove them from SourceBans. { mysql_query("DELETE FROM ".DB_PREFIX."_admins_servers_group WHERE admin_id='".$row2['aid']."'"); mysql_query("DELETE FROM ".DB_PREFIX."_admins WHERE aid='".$row2['aid']."'"); SendPM($row['userid'], $row['username'], "None", "None", 3); //Send a PM telling them that they've been removed from sourcebans } } // PRIMARY USERGROUP ADMIN CONTROL if (in_array($row['usergroupid'], $groups_with_admin)) //If the user is in a primary group defined as an admin, then add/edit them as such. { switch($row['usergroupid']) { case 16: //Group ID from vBulletin //AddAdmin(Sourcebans Web GroupID, Sourcebans Admin GroupID, Sourcebans Admin Group Name (Must be EXACT), Sourcebans Server GroupID, $row['username'], $row['email'], $row[$steamid_custom_field], $row['userid']) AddAdmin(1, 1, "Leaders", 1, $row['username'], $row['email'], $row[$steamid_custom_field], $row['userid']); break; case 18: AddAdmin(1, 2, "Vice-Founders", 1, $row['username'], $row['email'], $row[$steamid_custom_field], $row['userid']); break; case 15: AddAdmin(2, 3, "H-Exec", 1, $row['username'], $row['email'], $row[$steamid_custom_field], $row['userid']); break; case 17: AddAdmin(2, 4, "Admins", 1, $row['username'], $row['email'], $row[$steamid_custom_field], $row['userid']); break; case 13: AddAdmin(2, 6, "Members", 1, $row['username'], $row['email'], $row[$steamid_custom_field], $row['userid']); break; case 19: AddAdmin(2, 5, "Donators", 1, $row['username'], $row['email'], $row[$steamid_custom_field], $row['userid']); break; } continue; } // ADDITIONAL USERGROUP ADMIN CONTROL if (strlen ($row['membergroupids']) > 0){ $user_additional_groups=explode(",", $row['membergroupids']); } for($i = 0; $i < count($user_additional_groups); $i ++) //If the user is in a secondary group defined as an admin, then add/edit them as such, same format as above. { if (in_array($user_additional_groups[$i], $groups_with_admin)) { switch($user_additional_groups[$i]) { case 16: //Group ID from vBulletin //AddAdmin(Sourcebans Web GroupID, Sourcebans Admin GroupID, Sourcebans Admin Group Name (Must be EXACT), Sourcebans Server GroupID, $row['username'], $row['email'], $row[$steamid_custom_field], $row['userid']) AddAdmin(1, 1, "Leaders", 1, $row['username'], $row['email'], $row[$steamid_custom_field], $row['userid']); break; case 18: AddAdmin(1, 2, "Vice-Founders", 1, $row['username'], $row['email'], $row[$steamid_custom_field], $row['userid']); break; case 15: AddAdmin(2, 3, "H-Exec", 1, $row['username'], $row['email'], $row[$steamid_custom_field], $row['userid']); break; case 17: AddAdmin(2, 4, "Admins", 1, $row['username'], $row['email'], $row[$steamid_custom_field], $row['userid']); break; case 13: AddAdmin(2, 6, "Members", 1, $row['username'], $row['email'], $row[$steamid_custom_field], $row['userid']); break; case 19: AddAdmin(2, 5, "Donators", 1, $row['username'], $row['email'], $row[$steamid_custom_field], $row['userid']); break; } continue; } } } //REHASH SERVERS, DOES NOT REQUIRE EDITING $res = mysql_query("SELECT ip, port, rcon FROM ".DB_PREFIX."_servers WHERE enabled=1") or die(mysql_error()); while($row = mysql_fetch_assoc($res)) { if (strlen($row['rcon']) > 0) { $rcon = new CServerRcon($row['ip'], $row['port'], $row['rcon']); if(!$rcon->Auth()) { continue; } $rcon->rconCommand("sm_rehash"); unset($rcon); } } ?>vbulletintosourcebans.php.txt 13.33KB 2 downloads Similar TutorialsHey everyone. So lately I've been searching for someone to do this for me but I figure if I learned it myself it'd be much more helpful to me in the future. I run a gaming clan, and we have a roster. You can view it he http://www.zealotgam...s.php?pageid=15 Obviously, you can see a few things. The default page lists all our staff. That is very easy, and not really the part I need help with. The help begins with the games list you see at the side. When you click a game, it lists all users who have that Game listed as their Main Game in a profile field, and lists other info, such as their rank, In-Game contact (which is another profile field) and join date/last active. The games are also themselves divided into categories. Our code is relatively simple. We keep a manual array of info that keeps these together you can see below: // Define Games and Lists // $gameslist = array(); //SETUP $gamelist[] = array("Game Name","urlshortcode","Name of In-Game Name or Account", "field# for that profile field"); $gameslist[] = array("Battlefield 4 (PS4)", "bf4ps4", "PlayStation ID", "field7"); $gameslist[] = array("Counter Strike: Global Offensive (EU)", "csgoeu", "Steam ID", "field8"); $gameslist[] = array("Counter Strike: Global Offensive (NA)", "csgona", "Steam ID", "field8"); $gameslist[] = array("Elder Scrolls Online (NA)", "esona", "Main Character", "field45"); $gameslist[] = array("League of Legends (EUNE)", "loleune", "Summoner Name", "field12"); $gameslist[] = array("League of Legends (EUW)", "loleuw", "Summoner Name", "field31"); $gameslist[] = array("League of Legends (NA)", "lolna", "Summoner Name", "field32"); $gameslist[] = array("League of Legends (OCE)", "loloce", "Summoner Name", "field47"); $gameslist[] = array("Minecraft", "mc", "Username", "field14"); $gameslist[] = array("Smite (EU)", "smiteeu", "Smite Account", "field22"); $gameslist[] = array("Smite (NA)", "smitena", "Smite Account", "field22"); $gameslist[] = array("Titanfall", "tfall", "Origin ID", "field29"); $gameslist[] = array("WildStar (EU)", "wseu", "Main Character", "field48"); $gameslist[] = array("WildStar (NA)", "wsna", "Main Character", "field48"); $gameslist[] = array("World of Tanks (EU)", "woteu", "WarGaming.NET ID", "field46"); $gameslist[] = array("Other Game", "other", "", ""); // Game Type Categories $gamecats = array(); // ADD the # of the game in the list above (starting from 0) to the appropriate category array number list. $gamecats[] = array("Divisions",array(4,5,6)); $gamecats[] = array("Guilds",array()); $gamecats[] = array("Gaming Groups",array()); $gamecats[] = array("Divisions in Development",array(0,1,2,3,7,8,9,10,11,12,13,14)); $gamecats[] = array("Miscellaneous",array(15)); This gets tedious to keep track of manually, and my admins with no programming experience can barely understand what is happening. The listing of users is very easy, and I do not need any help with that. What I would like to add is a manager in the admin panel where you could save the information listed above to a table such as PREFIX.games. I imagine having several drop down boxes. A mockup is below: I'd then Like a list of games that includes these rows in the table with a [ ] Remove checkbox. I do not know how to add this to the admin panel and would love guidance on how to begin doing this. The sorting would go by Game Status (the second array in my php code) then Alphabetical. This would go a long way in helping my staff edit this list themselves. Any help would be appreciated. Skype: j.c.will my be better to work personally with me. well.. i have vbulletin 4 forum i try to put video player so if i upload mp4 file so i can play video but sad part is its working only at firefox browser can you help me out .. video code looks like this
<vb:if condition="$attachment[attachmentextension] == mp4"> pls i really want that put to work in every browser sadly it works only in firefox somehow.. This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=330163.0 HI fellow programmers, Can i connect a textbox to a field in the MySql using the id of the text box? If yes, can u show me a small example. Thanks RAM Hi! I got the following problem... I have a SQL 2005 Server in a VPN. For security reasons,internet access to the database server is only possible for VPN members. Now i want to connect to the openvpn Server from my webserver in order to connect to the database for some webreports. How can i achieve this using php? thanks Hi All, I have a landing page that I use, but often my sql database is too busy or gets overwhelmed and then the landing page just stalls and traffic is lost. Here it is: Code: [Select] <?php //ini_set("display_errors",1); if(!$src) $src = $q; define("__EXEC_", 1); include("config.php"); include("custom.php"); function lsp_visit_find($__val, &$__uid) { global $u; global $db; $l_campaign = array("campaign_id"=>"", "url"=>"", "cost"=>"0.00", "name"=>"-", "ad_keyword"=>"", "mapped_keyword"=>""); $l_visit = array(); $q = $_GET['q']; $src = $_GET['src']; // for STAGE #1 (visit definition): get cost, ad keyword, mapped keyword. $l_campaign['name'] = "info"; $l_campaign['mapped_keyword'] = "$q"; $l_campaign['ad_keyword'] = "$src"; $l_campaign['cost'] = ".02"; // get referer (campaign URL). if no campaign found, - create it! if (!empty($l_campaign['name'])) { $r = mysql_query("select campaign_id,name from campaign where name='$l_campaign[name]'"); if (!mysql_affected_rows($db)) { $r = mysql_query("insert into campaign(name,cost, creation_date,last_update_date) values('$l_campaign[name]',$l_campaign[cost], unix_timestamp(),unix_timestamp())"); $l_campaign['campaign_id'] = mysql_insert_id($db); } else { $w = mysql_fetch_assoc($r); $l_campaign = array_merge($l_campaign,$w); } } // check, whether we had visits from this IP for this keywords within 2 minutes. // if we have one, get its ID, otherwise - create new! $visit_id=""; if (!empty($l_campaign['ad_keyword']) && !empty($l_campaign['mapped_keyword']) ) { $ip = get_real_ip(); $r = mysql_query("select visit_id,uid,campaign_id,ad_keyword,mapped_keyword from visit where ip='$ip' and ad_keyword='$l_campaign[ad_keyword]' and mapped_keyword='$l_campaign[mapped_keyword]' and currtime>=from_unixtime(".(time()-120).") limit 1"); if (!mysql_affected_rows()) { $__uid = md5($ip.time().$l_campaign['campaign_id']); $x = mysql_query("insert into visit(ip,uid,cost,currtime,campaign_id,ad_keyword,mapped_keyword) values('$ip','$__uid',$l_campaign[cost],now(),$l_campaign[campaign_id],'$l_campaign[ad_keyword]','$l_campaign[mapped_keyword]')"); $visit_id = mysql_insert_id($db); } else { $l_visit = mysql_fetch_assoc($r); $visit_id = $l_visit['visit_id']; $__uid = $l_visit['uid']; } return $visit_id; } } $db = mysql_connect(__CFG_HOSTNAME, __CFG_USERNAME, __CFG_PASSWORD); mysql_select_db(__CFG_DATABASE, $db); $u = isset($_GET['u'])? $_GET['u'] : 2; $uid = ""; $visit_id = lsp_visit_find($_REQUEST['l'], $uid); if (!empty($visit_id)) { setcookie("x_uid", base64_encode($visit_id."QQ".$uid), time() + 3600); } global $q; mysql_close($db); $q = $_GET['q']; $src = $_GET['src']; header("Location: http://www.mydomain.com/search/?q=$q"); exit(); ?> My question is how do I code it so that if after 5 seconds or so, or the connection can't be made, it just terminates the connection and auto loads the header redirect at the bottom of the page? Thanks! Hi Guys, need a little help and drawn a blank. The code that is not working is below $result = $conn->query("SELECT * FROM MK_migration_details WHERE mig_bid='".$_SESSION['bid']."'"); I can confirm the $_SESSION['bid'] is working as echo's out on another part of the page. and the above $result works when i manually type the search criteria like below. $result = $conn->query("SELECT * FROM MK_migration_details WHERE mig_bid='300101'"); Basically no result turn up on the page. Any ideas or advise how I can diagnose? Fatal error: Call to undefined function mysql_connect() in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 10 Hallo I am beginner and starting to learn php I got this message when I want to connect with server. Can I get some suggestion what to do? Thanks On some occasions I need to connect to a second and third database in the same script (maybe 5% of scripts have at least a second connection). Usually I would just select the new database. However, my host requires different users to be created for each database. What is the best way to do this? Close current connection (say db1) and open new (say db2) OR keep all open, creating 2nd and 3rd connections. I am happy with the design of my database, and don't want to merge all these tables into one db. Overall I am still happy with my host, so I'd rather not change. Hi, I'm trying to write my first MVC framework for my college project and faced this problem: i have main framework class, and have this loader class, that loads view files and libraries. Now, how can I do that when I load library, I could reach it from my main class? For example: in main class goes this code: Code: [Select] public $load; function __construct ( ) { $this->load = new Loader; } function someFunction ( ) { $this->load->library('someLibrary'); // and now reach the library like this $this->someLibrary->functionInLibrary(); } The idea is from codeigniter, so if anyone has used this framework will understand my question. Hi,
I'm trying to write a better PHP code to create and manage my website.
I would like to start a MVC approach with PHP, using OOP. So I can manage the updates in a better way. For example, to begin my project, I would try with the shipping cost of our products, using a Class without merge the PHP and HTML code.
Something like this:
$shippingcost=new ShippingCost(); $shippingcost->state="Italy"; $shippingcost->get(); // here I have an array with cost, discount, time ecc.And If I need it in JSON, I write: $shippingcost->get("JSON"); // here I have the JSON with cost, discount, time ecc.I wrote the Class in this way: class ShippingCost { public $state; private $arrayReturned; public function __construct() { $this->stato="Italy"; // the default state } public function __destruct() { } public function get($format="array") { $this->arrayReturned=array( "cost" => 3.99, "costDiscounted" => 7.99, "discount" => "50%" ); if (strtolower($formato)=="json") { $this->arrayReturned=json_encode($this->arrayReturned); } return $this->arrayReturned; } }It works well, but I need to get the values from a MySQL db. How can pass the MySQL connection to the Class? I'm not able to do this. Thanks in advance and have a great 2015. Rob. Hello, Does anyone know how may i detect the Connection type by user IP? Broadband etc. I'm writing a quick little script to grab some information from Stickam.com, specifically using the "API" they have set up to get a user id from a provided username, and a username from a provided userid. These are both publically accessible pieces of information, so I'm not getting into anything I shouldn't, I'm just using the publically accessible API instead of scraping the HTML. For some reason I can't explain though, I can't seem to get the contents of the page using PHP. Here's my code: Code: [Select] $username = @$_GET['username']; if(!$username) { die("no username"); } $url = "http://www.stickam.com/servlet/ajax/getLiveUser?uname=".$username; $html = file_get_contents($url, false, $context); echo "<pre>"; echo $html; echo "</pre>"; But everytime I load this page on my server, I get this response: Warning: file_get_contents(http://www.stickam.com/servlet/ajax/getLiveUser?uname=[username]) [function.file-get-contents]: failed to open stream: Connection timed out in [file] on line 7 I can load it just fine on my Apache server running on my personal computer, and in my browser (both IE9 and Firefox), but not on my website. I've tried mimicking the headers that my browser sends and creating a stream context to send with the file_get_contents() call, but so far nothing seems to work. Any ideas? I was not expecting this but when I managed to connect to a chatroom and close out firefox.... The user stayed in the chatroom. This user should of pinged out by now but it's staying online. How do I end this connection? So far I turned off my internet, and blocked all access to the site. It seems that a class can't inherit an object as attribute? I'm trying to make my UpperNavigation class access the $this -> db attribute which is a mysqli connection. Is this possible? If not, how do I manage my connection in other classes? Code: [Select] class Connection{ public $state = false; public $db; public $db_table_names; function __construct($name){ include('dbconfig.php'); $this -> db = new mysqli($dbconfig[$name]['server'], $dbconfig[$name]['username'], $dbconfig[$name]['password'], $dbconfig[$name]['database']); $this -> state = true; $this -> db_table_names = $db_table_names; $this -> db -> query("SET NAMES 'UTF8'"); } function close(){ if($this -> state == true){ $this -> state = false; $this -> db -> close(); unset($this -> db); } } } This is my attempt of accessing Connection::$db connection. Code: [Select] class UpperNavigation extends Connection{ public $all_parents_sorted; public function printUpperNavigation(){ echo '<a href=\''.$this -> current_page.'\'>'.$this -> title . '</a>'; } public function printSearchBar(){ echo '<input type=\'text\' value=\'Search by name...\' onfocus="if(this.value == \'Search by name...\'){this.value = \'\';}" onblur="if(this.value == \'\'){this.value = \'Search by name...\';}"/>'; } public function fetchAllParents($sp_id){ $latest_id = $sp_id; if(isset($this -> db)){ echo 'yes'; }else{ echo 'no'; } $query = 'SELECT default_name, type, sp_id FROM ' . $this -> db_table_names['sport'] . ' WHERE sp_id = "' . $sp_id . '"'; $result = $this -> db -> query($query); // THIS IS THE PROBLEM } } I've been trying to find a good, up-to-date source on how to secure the authentication credentials for my db connection. I've done some PHP coding and would like to learn more. There's plenty information available, but I often find books inevitably have typos in the code. Also most of the online tutorials are either at least several years old or deal more with user login security. User authentication is one thing, but what are the best ways to secure the connection to the database itself? Obviously your basic newbie method of unencrypted host, username, password, and database stored in a connectvar file is just open invitation--or maybe not since it doesn't present a challenge to a hacker. Some say to encrypt the credentials with something like MD5 and store them in .htaccess. Other sources say not to use MD5. Any advice on where to find some good resources on this? Cheers! hi everyone I have a question... does creating a connection to mysql takes time depeding on the database size? Lets say that in my entire project I will be connection to 4 databases so I created a config.php which looks like this: Code: [Select] $hostname = "localhost"; $username = "root"; $pword = ""; $con1 = @mysql_connect($hostname,$username,$pword,true); @mysql_selectdb("databasename1",$con1); $con2 = @mysql_connect($hostname,$username,$pword,true); @mysql_selectdb("databasename2",$con2); $con3 = @mysql_connect($hostname,$username,$pword,true); @mysql_selectdb("databasename3",$con3); $con4 = @mysql_connect($hostname,$username,$pword,true); @mysql_selectdb("databasename4",$con4); so, this file is included in every pages, I put this on the top. Basically every page request it will open 4 connection and the script will only use 2 connection and another page will only 1 and so on..... this style is very convenient as for I am not creating a connection in every page.. But my concern is will it effect the performance of my system? Tnx in advance..... Ok, the database I have been working on the past few days is located on my websites server (1&1) and today I am trying to get a connection to it on a website that is on a different server, but I am getting my echo statement of saying it can't find the database even though I changed it from "localhost" to the physical address of the database. Any ideas? <?php class UserQuery { public function Adduser($id,$username,$email,$password) { $conn = new Config(); $sql =("INSERT INTO test.user (id, username, email, password) VALUES ('$id', '$username', '$email',$password)"); $conn->exec($sql); } }
getting an "exec doesnt exist " error, saying exec doesnt exist in my db file. it doesnt need to exist does it ? anyone any idea why ?
I have an app that connects to a source safe server to perform a command via shell_exec(). I had used exec(), but shell_exec seems to work better since I am on Linux. The command connects to the server and tells it to promote a file to the next level. On Windows this ran without a hitch, but on Linux I gat an error that reads: Quote Socket error when reading request from [172.20.22.1]: 3537808 ; Socket closed. I am told that the reason for this error is that PHP broke the connection to the server before the server completed the job and was able to shutdown properly. The only way I have found around this is to place a sleep(3) to the script. This is really not ideal since that means that there is at least 3 seconds between each command, which can really extend the time it takes to perform if there are numerous files. If PHP breaks the connection before the program can close it will leave the program open and PHP cannot perform any more commands to the server since it is stuck on the last command. If too many are given the machine will lock up due to resources being eaten up. I'm wanting to know if there is a way to tell PHP to not let go of a connection so quickly. I tried "nohup", but that does not help. I am new to Linux and am at a loss of what my options are beyond the sleep() method. I really feel that there has to be a better way or setting that can be manipulated to fix this issue altogether. Thanks in advance for any help. Cy |