Jump to content

EchoFool

Members
  • Posts

    1,074
  • Joined

  • Last visited

Posts posted by EchoFool

  1. Hey

     

    I have a query that looks like this:

         

    GRANT FILE ON [dbName].* TO '[user]'@'127.0.0.1' IDENTIFIED BY '[password]'  WITH GRANT OPTION

     

     

     

    But i get this error: 

     

    SQLSTATE[28000]: Invalid authorization specification: 1045 Access denied for user '[hidden]'@'localhost' (using password: YES)

     

     

     

    Why is this happening? In Cpanel the user has all privalages yet FILE is not one of them and i cannot seem to grant it either =/ Here is my code:


     

    $dsn = 'mysql:dbname=hidden;host=127.0.0.1';
    $user = //hidden
    $password = //hidden
    
    	try {
    		$pdo = new PDO($dsn, $user, $password);
    		
    	} catch (PDOException $e) {
    		echo 'Connection failed: ' . $e->getMessage();
    		exit;
    	}
    
    	$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
    
    //grant file permission temporarily		
            $stmt = $pdo->prepare("GRANT FILE ON [hidden].* TO '[hidden]'@'127.0.0.1' IDENTIFIED BY '[hidden]'  WITH GRANT OPTION");
    			try {
    				$stmt->execute(array(1));
    			} catch (PDOException $e) {
    				echo $e -> getMessage(); exit; //ERROR IS HERE
    			}		
    

    Where am i going wrong here?

     

    p.s i have used [hidden] solely for this post, the script does have the real login credentials :)

  2. Hey

     

    I need help with understanding mySQL-node connection handling.

     

    I currently have a script which does some queries but i don't know where to put:
     

    connection.end();

     

     

    I keep getting an error where ever i put it so I am really confused. The error is Error: Cannot enqueue Quit after invoking quit.

     

    I cannot work out where I am suppose to end the connection.

     

    My code is currently like this:

     

    var http 	 = require('http'),
        fs           = require('fs'),
        sanitize 	 = require('validator').sanitize,
        mysql        = require('mysql');
    	
    var db_config = {
    		host: '127.0.0.1',
    		user: 'testDB',
    		password: '[hidden]',
    		database: '[hidden]'
    };	
    
    var clients = {},	
        connection;
    
    connection = mysql.createConnection(db_config);
    connection.connect(function(err) {              
       if(err) {   
         console.log('error when connecting to db:', err); 
       }                                     
    });                                     
    
    var app = http.createServer(function (request, response) {
    
    fs.readFile(__dirname + 'client.html', 'utf-8', function (error, data) {
          if (error) {
    	response.writeHead(500, {'Content-Type': 'text/html'});
    	response.write(error.toString());
          } else {
    	response.writeHead(200, {'Content-Type': 'text/html'});
    	response.write(data);
          }
    	response.end();
    });
    
    
    var io = require('socket.io').listen(app);
    
        io.sockets.on('connection', function(socket) {
           
           socket.on('connect', function(data,callBack){
    	   var session = sanitize(data['session']).escape();					
    	   var query = connection.query('SELECT uid FROM sessions WHERE id = ?', [session],
    	               function(err,results){
    			  if(err){ 
    			        console.log('Oh No! '+err);
    			  } else if(results.length == 1){
    				if(!clients[socket.id]){clients[socket.id] = {};}
    				clients[socket.id].uid = results[0].uid;
    				io.sockets.socket(socket.id).emit('connectConfirm',{data : true});
    			  }
    			connection.end();
    		       });
    		});		
    	socket.on('start', function(data,callBack) {			
    	   var userId = sanitize(data["userID"]).escape();
    	   var query = connection.query('SELECT name FROM users U WHERE U.uid = ?', [userId],
    			 function(err,results){
    				 if(err){ 
    					 console.log('Oh No! '+err);
    				 } else if(results.length == 1){
    					 io.sockets.emit("name",{ name: results[0].name});
    				 }
    			connection.end();
    			});
                     });
    	});
    }).listen(1339);
    

    So where does connection.end(); go? I'm really confused how i end the connection gracefully so i don't leak connections.

  3. Hello, I have a class which handles session data to my database but every time I run PHP  and have session_start(), the session data in my database is set to 0.

     

    I have no idea why its doing it.

     

    My script is like this (sorry its a quite large class):
     

    class FileSessionHandler
    {
        private $_sess_db;
    
        function open($_sess_db, $sessionName)
        {
    		$dsn = 'mysql:dbname=testDB;host=127.0.0.1';
    		$user = '[hidden]';
    		$password = '[hidden]';
    	try {
    		$_sess_db = new PDO($dsn, $user, $password);
    		
    	} catch (PDOException $e) {
    		echo 'Connection failed: ' . $e->getMessage();
    		exit;
    	}
    
    	$_sess_db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);				
    	$this->connection = $_sess_db;
            return true;
        }
        function close()
        {	
    	$this->connection = null;
            return true;
        }
        function write($id, $data)
        {
    	$access = time();
    	$stmt = $this->connection->prepare("REPLACE INTO sessions (id,access,data) VALUES (?,?,?)");
    		try {
    		    $stmt->execute(array($id,$access,$data));
    		} catch (PDOException $e) {
    		    echo $e -> getMessage(); exit;
    		}			
    		if(!$stmt->rowCount()){
    			return false; 
    		}
    			return true;
        }	
        function read($id)
        {	
    		$stmt = $this->connection->prepare("SELECT data FROM sessions WHERE id = ?");
    			try {
    				$stmt->execute(array($id));
    			} catch (PDOException $e) {
    				echo $e -> getMessage(); exit;
    			}		
    		if(!$stmt->rowCount()){ return false; }
    			$row = $stmt->fetch();
    			return $row['data'];	
        }
        function destroy($id)
        {
    		$stmt = $this->connection->prepare("DELETE FROM sessions WHERE id = ?");
    			try {
    				$stmt->execute(array($id));
    			} catch (PDOException $e) {
    				echo $e -> getMessage(); exit;
    			}			
    		if(!$stmt->rowCount()){ return ''; }
    		return 1;	
        }
        function clean($max)
        {
    		$old = time() - $max;
    		$stmt = $this->connection->prepare("DELETE FROM sessions WHERE access < ?");
    			try {
    				$stmt->execute(array($old));
    			} catch (PDOException $e) {
    				echo $e -> getMessage(); exit;
    			}					
    		if(!$stmt->rowCount()){ return ''; }
    		return 1;		
        }
    }
    
    $handler = new FileSessionHandler();
    session_set_save_handler(
        array($handler, 'open'),
        array($handler, 'close'),
        array($handler, 'read'),
        array($handler, 'write'),
        array($handler, 'destroy'),
        array($handler, 'clean')
        );
    
    session_start();
    

    Now in my database the row has :
     

    id : 2f534c82c004172c4fd49cfdd8d5f91a

    access  : 1387054887

    data : 1

     

     

    So the session is holding the value 1. Now when i run the PHP script and check the row, the field data says 0, i don't know why it keeps updating it to 0 rather than keeping the value?

     

    Please help been stuck on this all day!!

  4. Ok final question, I've written my class for this and in my database i have this :

     

    ID: b212afdb797206ae06e376f2c4d2e681
    Access: 1386984361
    Data: Userid|i:1;

     

     

     

    What I don't understand is how to get that info.

     

    Using this for example:

    socketio.emit("GetSeassionData", { ID : b212afdb797206ae06e376f2c4d2e681});

    A user could easily edit their JavaScript and change the ID ? So how do I get the session data in nodeJS?

  5. Hello.

     

    I've gotten my self really confused with server end checks for users being logged in. I create a session in PHP by using a straight forward ajax request and check the database against the user & pass sent to the server.

    I then set a session like this:
     

    $_SESSION['uid'] = $row['uid'];

    But i want to check this session in NodeJS aswell so i don't have to keep validating the user when they send data on a socket.

     

    The script i have is like this:

     

    socket.on('sendMessage', function(data,callBack){       
       var userID = //assign $_SESSION['uid'], possible?
       if(!userID){ 
           console.log('User not logged in!');
       } else {
    
       var message = sanitize(data['message']).escape();
       var query = connection.query('SELECT name FROM users WHERE uid = ?', [userID],
                   function(err,results){
                     if(err){
                        console.log('Query Error: '+err);
                     } else if(results.length == 1){
                        var username = results[0].name;
                        console.log(username+' sent a message!');
                     }
                });
        });
    

    How do i use the session in this situation - i can't work out how to do it =/

     

    Please help, really confused!

  6.  

    Hey

     

     

    I have a function which calls a php file - that php has a JS alert function call but it doesn't execute, so im a bit confused...

     

     

    MY function is:

     

    function call_file(file,div_id){
    
    var xmlhttp;
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById(div_id).innerHTML=xmlhttp.responseText;
        }
      }
    xmlhttp.open("GET",file,true);
    xmlhttp.send();
    
    }
    
    
    call_file('test.php?u=name','div_id_test');
    
    

     

    test.php:

    <script>alert('test');  //this doesn't work </script>
    
    <?php
       $user = $_GET['u'];
       echo $_GET['ud']; // this works
    ?>
    

     

     

    Why doesn't the alert occur ? And how do i solve it ?

  7. Hey

     

     

    I have been reading about creating and storing hashes from blowfish in PHP, but am confused by the salt aspect.

     

     

    It says it can generate it's own ? But then surely when a user inputs their password to check against the database it will use a new salt each time and thus they won't match up when checking... say on a login screen.... this confuses me greatly..

     

     

    Is it just wiser to have a fixed string of numbers to use for the salt all the time instead of letting it generate it's own ?

  8. Hey

     

     

    I have a basic Js script and some HTML that sets the width of a div. But its not working it keeps making it 100% wide all the time.

     

    I can't see any issue with it personally, but was wondering.... the script is called from an AJAX request... could that be causing some issue?

     

     

    This is my code:

     

    <head>
    <script type="text/javascript">
        function percentage(){
          var perc = Math.round((500 / 2500) * 100);
          
           if(perc > 100)
            {perc = 100;}
            else if(perc < 0 )
            {perc = 0;}
    
    
            d = document.getElementById('health');
            d.style.width = perc + "%";
          
       
        };
       onload = percentage;
    </script>
    </head>
    <body>
       <div style="width:250px;background-color:red;min-height:5px;">
       <div id="health" style="background-color:green;min-height:5px;">
       < / div > //dunno why but if i dont add spaces in this post it removes the close divs 
    < / div >
    </body>
    

     

     

    Any ideas?

  9. Is looping the entire array the only way? As it sounds quite intensive.

     

    Also how can you loop an array in such a way to check if the values are between the values like:

     

    Logic code:

    get id where x is > data[0] && y > data[1] && x < data[2] && y < data[3]
    

  10. Hey

     

     

    I have an array which carries id's + 4 numbers assigned to each id.

     

     

    I'm trying to find a way to use if statement to get the correct id by checking which of the 4 numbers goes with the check.

     

     

    This is the structure:

     

     

    
    				var listObj = {
    									id: uid,
    									data: [
    										abposx,
    										abposy,
    										width,
    										height
    									]
    								};	
    

     

     

    So lets say im trying to find the "id" which greater than the width & height and its abposx and abposy and greater than what im checking...

     

     

    The issue is how do i get the id from such a check =/ its confusing?

  11. Hey

     

     

    I'm having an issue dragging images in my JavaScript. Although it works it keeps resetting its offset when i try to drag a second time. I use a mousedown + movemove events. When i mouse up i remove the mouse move event, then on the second mouse down to continue dragging, thats when it starts back in its start position instead of continuing on from where i left off.

     

    So this is my script:

     

    var offset_x = 0;
    var offset_y = 0;
    function mousePos(e){
          mousex = e.pageX;
          mousey = e.pageY;
          canvas.addEventListener("mousemove", movePos, false);
    }
    function movePos(e){
    canvas.addEventListener('mouseup',onMouseUp,false);
    canvas.addEventListener('mouseout',onMouseUp,false);
    
          dx = e.pageX - mousex; //calculate how far the mouse moved in X in pixels
          dy = e.pageY - mousey; //calculate how far the mouse moved in Y in pixels
          
          offset_x = dx;
          offset_y = dy;
    }
    
    function onMouseUp(){
    canvas.removeEventListener('mousemove',movePos,false);
    }
    
    
    
    
    function init(){
    draw();// places images in the canvas
    canvas.addEventListener("mousedown", mousePos, false);
    
    canvas.addEventListener("mousewheel", zoom, false);
    }
    

     

     

    Can any one see the mistake or cause of the issue?

×
×
  • 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.