Jump to content

Aureole

Members
  • Posts

    788
  • Joined

  • Last visited

    Never

Everything posted by Aureole

  1. That's the port.........................................................
  2. I'm trying to connect to an IRC Server with PHP and I always get an error similar to this: Warning: fsockopen() [function.fsockopen]: unable to connect to irc.quakenet.org:6667 in /home/veraci7y/public_html/playground/connecttoirc.php on line 29 <?php $server_host = "irc.quakenet.org"; $server_port = 6667; $server_chan = "#help"; // Line 29: $server['SOCKET'] = fsockopen( $server_host, $server_port, $errno, $errstr, 2 ); ?>
  3. About the Google thing, it turns out I was searching *too* specifically. Here's what I have so far and it doesn't work, it just shows the sign in page. <?php $url = "http://login.live.com/login.srf?wa=wsignin1.0&rpsnv=10&ct=1206715726&rver=4.5.2135.0&wp=MBI&wreply=https:%2F%2Flive.xbox.com%2Fxweb%2Flive%2Fpassport%2FsetCookies.ashx%3Frru%3DhttpZ3AZ2FZ2FwwwZ2ExboxZ2EcomZ2FenZ2DUSZ2FdefaultZ2Ehtm&lc=1033&cb=B001033httpZ3AZ2FZ2FwwwZ2ExboxZ2EcomZ2FenZ2DUSZ2FdefaultZ2Ehtm&id=66262"; $c = curl_init(); curl_setopt( $c, CURLOPT_URL, $url ); curl_setopt( $c, CURLOPT_POST, 2 ); curl_setopt( $c, CURLOPT_POSTFIELDS, "i0116=emailaddresshere" ); curl_setopt( $c, CURLOPT_POSTFIELDS, "i0118=passwordhere" ); $result1 = curl_exec( $c ); curl_close( $c ); print $result; ?>
  4. I'm just going to go ahead and give this a bump, I still can't find any information via Google.
  5. I'm not too familiar with cURL or sockets and I can't find ANYTHING on the web that helps. If anyone has any example code laying around, or doesn't mind writing some then it would be most appreciated.
  6. Here's basically what I want to do: I will put my Windows Live ID email address and password into a PHP script and then: Sign in to Xbox.com with the email address and password, in the background. Once signed in, open the Messages page, in the background. Check for new messages. Show them. I will be able to work out how to check and show the messages on my own, it's the background stuff I need help with. I'm assuming I'll need to use sockets etc. but I can't find a tutorial or anything on Google on how to do something like this.
  7. Sorry, I checked google and I didn't find any results that helped. I tried both a domain and an IP Address. This is basically all you need, right? <?php $this->vars['db_host'] = 'veraci7y.net'; $this->vars['db_user'] = '...'; $this->vars['db_pass'] = '...'; $this->connection = mysql_connect( $this->vars['db_host'], $this->vars['db_user'], $this->vars['db_pass'] ) or die( 'Connection error: ' . mysql_error() ); ?>
  8. The error is basically the same: Connection error: Lost connection to MySQL server at 'reading initial communication packet', system error: 110
  9. I am getting the following error: Warning: mysql_connect() [function.mysql-connect]: Lost connection to MySQL server at 'reading initial communication packet', system error: 110 in /home/gamingre/public_html/alpha/sources/classes/class_database.php on line 26
  10. Thanks a lot, I shall give it a try now.
  11. I have 2 servers, I'd like to use one for the database, images and css and another for all of the php. How do I go about accessing another server's database?
  12. I changed the function as you stated and I have fixed the connection problem, silly error on my part... I created a new topic with my new problem, been as though this topic was basically to do with the connection problem. Here's a link to the topic It explains everything a lot better. Consider this topic solved.
  13. Ok, basically, I taught myself PHP by reading tutorials and taking apart other people's code, not sure if other people have done the same, but anyway... No doubt, a lot of the code I used to taught myself was old and/or outdated. When I'm approaching login, this is basically what I do. <?php $ln = md5( $_POST['login_name'] ); $pa = md5( $_POST['password'] ); $query = "SELECT * FROM `members` WHERE `login_name` = '{$ln}' AND `password` = '{$pa}'"; $result = mysql_query( $query ); if( $result ) { echo( 'Login successful.' ); } else { echo( 'Login unsuccessful.' ); } ?> Now that's all fine and dandy and it has always worked for me, but now I've started to use classes and functions it doesn't work out. <?php $ln = md5( $_POST['login_name'] ); $pa = md5( $_POST['password'] ); $db->select( '*', 'members', array( 'mem_lname' => $ln, 'mem_pass' => $pa ) ); $db->exec_query(); /* $exec_query performs mysql_query() on the query created with $db->select and returns it within $db->result Now the problem is, the following statement always evaluates to true */ if( $db->result ) { echo( 'Login successful.' ); } else { echo( 'Login unsuccessful.' ); } /* If I get rid of the above statement and do this: $db->fetch_assoc(); var_dump( $db->assoc ); ...it works as expected, so my query is well formed and is being executed echo( $db->result ); would produce a resource id, unless of course I enter incorrect details and $db->assoc contains all the data from the database, again, unless I enter incorrect details. */ ?> So what should I do to check if the login was successful, now that if( $db->result) doesn't work?
  14. I've always used num_rows for this... oh well, I'll try affectected_rows.
  15. Wow. I only get the error when using the num_rows() function, if I don't use it then there are no errors.
  16. I'm having a little database trouble. The select function is working fine... <?php function select( $select, $table, $where = '' ) { $this->query = "SELECT {$select} FROM `{$table}`"; if( $where !== '' ) { $this->query .= " WHERE"; if( is_array( $where ) ) { foreach( $where as $f => $v ) { $nval = ( is_numeric( $v ) && intval( $v ) == $v ) ? $v : "'{$v}'"; $this->query .= " `$f` = $nval AND"; } } else { $nwhere = explode( '|', $where ); $nval = ( is_numeric( $nwhere[1] ) && intval( $nwhere[1] ) == $nwhere[1] ) ? $nwhere[1] : "'{$nwhere[1]}'"; $this->query .= " `$nwhere[0]` = $nval"; } } $this->query = substr( $this->query, 0, -4 ); return( $this->query ); } ?> ...as is this... <?php function exec_query() { return $this->result = mysql_query( $this->query ); } ?> ...but this isn't... <?php function num_rows() { return mysql_num_rows( $this->result ); } ?> When I try to use it, I get: Otherwise there are no errors. The actual code, is: <?php $lname = md5( $_POST['mem_lname'] ); $pass = md5( $_POST['mem_pass'] ); $db->select( '*', 'members', array( 'mem_lname' => $lname, 'mem_pass' => $pass ) ); $db->exec_query(); if( $db->num_rows > 0 ) { echo( 'Login success.' ); } else { echo( 'Login failure.' ); } ?>
  17. I know there are multiple ways of doing this, but what I was looking for was a way to dynamically append something to the end of URLs... just like PHPSESSID is, if cookies are disabled...
  18. I'll try and give you a realistic example: Let's say we have a website, but the database isn't working, but we have a backup server with another copy of the database. How could I dynamically append say "?secondary_db" to all URLs? <?php // Pseudo code... if there is an error connecting to the database append a string to all urls if the url contains the appended string connect to the secondary database instead ?>
  19. The only problem with using substr() is words may get cut off half way through, if you don't want that to happen you could do something like this: <?php $puzzle; $counter = 1; $words = 15; $full_article = 'I am an article, blah blah blah. You find the topic that I am based on extremely interesting and you want to read more of me.'; $pieces = explode( ' ', $full_article ); foreach( $pieces as $piece ) { $counter++; $puzzle .= $piece . ' '; if( $counter > $words ) break; } $puzzle = rtrim( $puzzle ) . '...'; echo( $puzzle ); ?> There are probably better ways of doing it, but it works...
  20. I figured I'd learn C++, I set myself a goal, to create an extremely simple mini-calculator. All is well so far, but I've ran into a few problems. #1: When you choose whether to add, subtract, multiply or divide... if you enter a number (e.g. 6) then it does what I want it to do (asks you to enter a number between 1-4), though if you enter a letter (e.g. "h") then the do() part runs over and over again extremely fast and fills the entire console and it won't stop. #2: As far as my searches have turned up, there is no way to check if input is numeric... I need something like PHPs is_numeric(). #3: Within main() after answer() I want the program to "restart", so that the user can choose another option and go again, but I can't figure out how to do that. #4: I'd like to make it so a user can enter "exit" at any time to exit the program. If it makes any difference I'm using Microsoft Visual C++ 2008 Express Edition. I realize that this probably isn't the best way of doing things and it's probably not very efficient but I just started learning, take it easy. I'm just trying to learn the basics. #include <iostream> #include <string> #include "stdafx.h" void start() { using namespace std; cout << "Welcome to my simple Calculator!" << endl; } int choice() { using namespace std; int uChoice; do { cout << endl << "What do you want to do?" << endl; cout << "1) Add" << endl; cout << "2) Subtract" << endl; cout << "3) Multiply" << endl; cout << "4) Divide" << endl; cout << endl << "Waiting for input... (enter a number): "; cin >> uChoice; cout << endl; } while( uChoice != 1 && uChoice != 2 && uChoice != 3 && uChoice != 4 ); switch ( uChoice ) { case 1: cout << endl << "You chose addition." << endl; break; case 2: cout << endl << "You chose subtraction." << endl; break; case 3: cout << endl << "You chose multiplication." << endl; break; case 4: cout << endl << "You chose division." << endl; break; } return uChoice; } int input( bool i = false ) { using namespace std; string text; text = ( i == true ) ? "Enter another number: " : "Enter a number: "; cout << endl << text; int number; cin >> number; return number; } int work( int one, int two, int todo ) { using namespace std; int answer; switch ( todo ) { case 1: answer = one + two; break; case 2: answer = one - two; break; case 3: answer = one * two; break; case 4: answer = one / two; break; } return answer; } void answer( int theanswer ) { using namespace std; cout << endl << "The answer is " << theanswer << "." << endl; cout << endl << "Hit Return to exit."; cin.clear(); cin.ignore( 255, '\n' ); cin.get(); } int main() { using namespace std; start(); int todo = choice(); int one = input(); int two = input( true ); int theanswer = work( one, two, todo ); answer( theanswer ); return 0; }
  21. I know not to echo from within a function, I was just doing that to test it. Thanks a lot for helping, I'll try your code now.
  22. I also tried this and it didn't work, so that's not it: $whatever = compile_update_array( $array ); $query = "UPDATE `{$table}` SET {$whatever}"; You are right about the scope, I forgot about that... but even when I assign the result of compile_update_array() to a variable inside the other function, then use it - it still doesn't work.
  23. Does anyone have any idea why this isn't working? I'm stumped. The output is: When it should be a little more like: <?php function quick_update( $table, $array, $where = '' ) { compile_update_array( $array ); $query = "UPDATE `{$table}` SET {$cdata}"; if( $where !== '' ) { $where = explode( '|', $where ); $query .= " WHERE `{$where[0]}` = '{$where[1]}'"; } echo( $query ); exit; } function compile_update_array( $data ) { $cdata = ''; foreach( $data as $k => $v ) { if( is_numeric( $v ) and intval( $v ) == $v ) { $cdata .= '`' . $k . '`' . " = " . $v . ","; } else { $cdata .= '`' . $k . '`' . " = '" . $v . "',"; } } $cdata = preg_replace( "/,$/", "", $cdata ); return $cdata; } quick_update( 'members', array( 'mem_title' => 'Testing...', 'mem_profile_message' => 'Testing...' ), 'mem_id|1' ); ?>
  24. I'd suggest using preg_match() as it is much faster than ereg(), other than that it looks fine.
×
×
  • 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.