-
Posts
557 -
Joined
-
Last visited
Never
Posts posted by unidox
-
-
I have an array such as:
Array
(
[0] => :
[1] => 353
[2] => SGS|Bot-1
[3] => =
[4] => #a
[5] => :SGS|Bot-1
[6] => +SGS|Bot
[7] => SGS|Ryan`AFK
[8] => @a|TaCo
[9] => SGS|Pat
[10] => @U|Pat
[11] => @ChanServ
)
How do I go through that array, and remove a "+" or a "@" from each index only if it has one in the beginning.
Thanks
-
-
I have an array like this:
$array[$row] = array ( 'name' = $name, 'discount' = $discount, 'price' = $price );
Now, I have about 200 of those in that array, and im trying to sort by the discount, highest 1st. How would I go about doing that? Thanks.
-
Can I ask how I can improve it?
-
What do you mean by floored?
-
Could I use a global?
-
Well, the db is already declared inside index.php:
<?php session_start( ); // exit ( $_SESSION['userId'] ); include ("../config.php"); include ("../core/coreClass.php"); include ("../core/dbClass.php"); include ("../core/userClass.php"); define (IN_SCRIPT, true); $coreClass = new coreClass ( ); $dbClass = new dbClass ( $host, $username, $password, $table ); $userClass = new userClass ( ); if ( !$userClass->checkLoggedIn( ) ) { $currentPage = "login"; } elseif ( $coreClass->getGET("page") && file_exists ( "pages/".$coreClass->getGET("page").".php" ) ) { $currentPage = $coreClass->getGET("page"); } else { $currentPage = "home"; } include ( "processors/".$currentPage.".php" ); include ( "pages/".$currentPage.".php" ); ?>
-
dbClass:
<?php class dbClass { private $last_error; private $last_query; private $row_count; public $owner_email; public $db_host; public $db_username; public $db_password; public $db_table; public $site_dir; public $prefix; private $link; function __construct( $host, $username, $password, $table ) { $this->db_host = $host; $this->db_username = $username; $this->db_password = $password; $this->db_table = $table; $this->connect(); } function connect () { $this->link = mysql_connect($this->db_host, $this->db_username, $this->db_password); if (!$this->link) { $this->last_error = mysql_error(); return false; } if (!$this->select_table()) { return false; } return $this->link; } function select_table() { if (!mysql_select_db($this->db_table)) { $this->last_error = mysql_error(); return false; } return true; } function sql($table, $sql) { $this->last_query = "Table: " . $table . "Query: " . $sql; $row = mysql_query("SELECT * FROM `" . $prefix . $table . "` " . $sql . "") or die ( mysql_error ( ) ); if (!$row) { $this->last_error = mysql_error(); return false; } $this->row_count = mysql_num_rows($row); return $row; } function get_row($result, $type="MYSQL_BOTH") { if (!$result) { $this->last_error = "Invalid resource identifier passed to get_row() function."; return false; } if ($type == 'MYSQL_ASSOC') $row = mysql_fetch_array($result, MYSQL_ASSOC); if ($type == 'MYSQL_NUM') $row = mysql_fetch_array($result, MYSQL_NUM); if ($type == 'MYSQL_BOTH') $row = mysql_fetch_array($result, MYSQL_BOTH); if (!$row) return false; return $row; } function insert_sql($table, $sql1, $sql2) { $this->last_query = "Table: " . $table . "Query: " . $sql1 . " | " . $sql2; $row = mysql_query("INSERT INTO `" . $this->prefix . $table . "` (" . $sql1 . ") VALUES (" . $sql2 . ")") or die(mysql_error()); if (!$row) { $this->last_error = mysql_error(); return false; } return true; } function update_sql($table, $sql) { $this->last_query = "Table: " . $table . "Query: " . $sql; $row = mysql_query("UPDATE `" . $this->prefix . $table . "` " . $sql . ""); if (!$row) { $this->last_error = mysql_error(); return false; } return true; } function escape_sql($data) { return mysql_real_escape_string($data); } function print_last_error() { return $this->last_error; } function print_last_query() { return $this->last_query; } } ?>
Function being used inside userClass:
public function getData ( $userId, $rowName ) { $query = dbClass::sql ( "users", "WHERE `id` = '$userId'" ); if ( mysql_num_rows( $query ) == 1 ) { $row = dbClass::get_row( $query ); } else { return "Error: No rows in query."; } return $row[$rowName]; }
-
Ok, so I can do two things to my understanding:
1)
Use $dbClass->sql instead of dbClass::sql
2)
Change $this->last_query to $last_query
Am I right?
-
I have just started picking up PHP again, so my OOP skills are a bit rusty. I keep getting this error:
Fatal error: Using $this when not in object context in C:\wamp\www\core\dbClass.php on line 93
That line is:
$this->last_query = "Table: " . $table . "Query: " . $sql;
I am calling an sql function inside dbClass from userClass:
$query = dbClass::sql ( "users", "WHERE `id` = '$userId'" );
Any ideas what I am doing wrong? Thanks
-
Never mind, im a moron haha. I used == instead of =
-
$sql="REPLACE INTO `findmefollow` ('grpnum', 'strategy', 'grptime', 'grppre', 'grplist', 'annmsg_id', 'postdest', 'dring', 'needsconf', 'remotealert_id', 'toolate_id', 'ringing', 'pre_ring') VALUES
('$_POST[grpnum]','ringall','$_POST[grptime]','$_POST[grppre]',$grplist,'0','$_POST[postdest]','','','0','0','Ring','$_POST[pre_ring]')";
-
I am making a CMS, and I have a /core/ folder, which contains all my classes for logging in and what not. Now, i am trying to use a class that sets a login session, inside the /admin/ directory. I dont know why, but the sessions are being set. Any ideas?
index.php in /admin/:
<?php session_start( ); // exit ( $_SESSION['userId'] ); include ("../config.php"); include ("../core/coreClass.php"); include ("../core/dbClass.php"); include ("../core/userClass.php"); define (IN_SCRIPT, true); $coreClass = new coreClass ( ); $dbClass = new dbClass ( $host, $username, $password, $table ); $userClass = new userClass ( ); if ( !$userClass->checkLoggedIn( ) ) { $currentPage = "login"; } elseif ( $coreClass->getGET("page") && file_exists ( "pages/".$coreClass->getGET("page").".php" ) ) { $currentPage = $coreClass->getGET("page"); } else { $currentPage = "home"; } @include ( "processors/".$currentPage.".php" ); include ( "pages/".$currentPage.".php" ); ?>
Here is the function that is being called (I know its returning true) This is inside /core/:
public function loginUser ( $username, $password ) { $username = coreClass::clean( $username ); $password = coreClass::encrypt( coreClass::clean( $password ) ); $query = dbClass::sql ( "users", "WHERE `username` = '$username' AND `password` = '$password' AND `isActive` = '1'" ); if ( mysql_num_rows( $query ) == 1 ) { $row = dbClass::get_row( $query ); $_SESSION['userId'] == $row['id']; $_SESSION['isLogged'] == 1; $_SESSION['isAdmin'] == $row['isAdmin']; $_SESSION['userLevel'] == $row['accessLevel']; return true; } else { return false; } }
-
Looking for something like virustotal.com, or novirsthanks.org
I dont know if it needs to be in php, or what.
I also, dont know a price, but I am flexible. If you can do it, or know of a script, PM me with an offer.
-
I have a cron that runs every 5 min, that adds information about my server into a db. I have a graph that graphs the last 6 hours (360 min). How do I have the cron remove any expired data from the database? (Greater than 30 min ago.).
Any help appreciated. Thanks
-
I need a query script/class that I can use to query the following:
Server Online/Offline
Server Title
Server Players
Server Max Players
Server Map
Server Players with score and player name
I need these to support all hl1 and hl2 games, and also killing floor servers. Future games will also be added so you will also be getting more work soon after completion.
PM me with offers.
-
What im trying to do is, search for "srv_9 (Dead ???)" inside a function output. Any ideas?
Thanks
-
Im trying to search for the string: srv_9 (Dead ???)
I thought to use preg_match, however I dont know much about reg ex. Can anyone help? Thankks
-
I have this function:
private function getLong(&$string) { $data = substr($string, 0, 4); $string = substr($string, 4); $data = unpack('Vvalue', $data); return $data['value']; }
But I am getting the error: Warning: unpack() [function.unpack]: Type V: not enough input, need 4, have 0
The error line is $data = unpack('Vvalue', $data);
Whats wrong?
-
But I need duplicate names in the db.
-
I insert a new row inside a table, and the db automatically gives it an ID. I was wondering, how I can obtain that ID without calling the db by one of the row values. Because, I add a user with a user_id and a name, and the name could be anything and possibly match other rows in the db. The col with user_id is auto increment, so I was wondering how I can obtain this while still adding the user to the db. Thanks
-
That didnt work, im outa ideas. Basically what im trying to do is:
start screen -> run program -> detach screen
Any ideas? Thanks
-
So I would do this?:
// execute a command if ($data = execshell("screen -X -S amitydm kill ; screen -dmS amitydm")) { echo $data; } if ($data = execshell("screen -r amitydm /server/srv102/srcds_run -game cstrike")) { echo $data; }
?
-
This is my code:
<? if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist"); // log in at server1.example.com on port 22 if(!($con = ssh2_connect("localhost", 22))){ echo "fail: unable to establish connection\n"; } else { // try to authenticate with username root, password secretpassword if(!ssh2_auth_password($con, "user", "password")) { echo "fail: unable to authenticate\n"; } else { // allright, we're in! echo "okay: logged in...<br /><br />\n"; function execshell ($command) { global $con; if(!($stream = ssh2_exec($con, $command, "vt102")) ){ return false; } else{ // collect returning data from command stream_set_blocking( $stream, true ); $data = ""; while( $buf = fread($stream,4096) ){ $data .= $buf . "\n<br />"; } return $data; fclose($stream); } } // execute a command if ($data = execshell("screen -X -S amitydm kill ; screen -dmS amitydm")) { echo $data; } } } ?>
That works fine, it terminates, and creates the screen.
However, I need to execute the following commands in the screen:
cd /server/srv102/
./srcds_run -game cstrike
and then after those commands are run, I need the session to detach. How would I go about doing that? Thanks!
Replace
in PHP Coding Help
Posted
I have multiple \n in a string, and I need to replace it with <br />. How do I go about doing this? Preg replace?