Jump to content

unidox

Members
  • Posts

    557
  • Joined

  • Last visited

    Never

Everything posted by unidox

  1. unidox

    Replace

    I have multiple \n in a string, and I need to replace it with <br />. How do I go about doing this? Preg replace?
  2. unidox

    Array

    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
  3. unidox

    Bullets

    On my website, I have a bullet, and when the text gets to big for the div, it goes down a line, and starts underneath the bullet. How do I keep the same margin as how it started?
  4. unidox

    Sorting

    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.
  5. unidox

    Error

    Can I ask how I can improve it?
  6. unidox

    Error

    What do you mean by floored?
  7. unidox

    Error

    Could I use a global?
  8. unidox

    Error

    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" ); ?>
  9. unidox

    Error

    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]; }
  10. unidox

    Error

    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?
  11. unidox

    Error

    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
  12. unidox

    Sessions

    Never mind, im a moron haha. I used == instead of =
  13. $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]')";
  14. 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; } }
  15. unidox

    Time

    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
  16. unidox

    Reg Ex

    What im trying to do is, search for "srv_9 (Dead ???)" inside a function output. Any ideas? Thanks
  17. unidox

    Reg Ex

    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
  18. 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?
  19. unidox

    ID

    But I need duplicate names in the db.
  20. unidox

    ID

    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
  21. unidox

    Shell

    That didnt work, im outa ideas. Basically what im trying to do is: start screen -> run program -> detach screen Any ideas? Thanks
  22. unidox

    Shell

    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; } ?
  23. unidox

    Shell

    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!
  24. unidox

    SSH

    Yea, in ssh when I type screen there is no message that comes up. However, now my script is saying Im not connected to a terminal, yet the script successfully logs in. Whats wrong?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.