Jump to content

EchoFool

Members
  • Posts

    1,074
  • Joined

  • Last visited

Profile Information

  • Gender
    Female

EchoFool's Achievements

Advanced Member

Advanced Member (4/5)

0

Reputation

  1. Well i plan to run the script as a cron job anyway so i guess i could just use root user instead !
  2. Hey I have a query that looks like this: But i get this error: 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
  3. 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: 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.
  4. I have solved my own issue - for those who may want to know: The read function MUST return serialized session data (not php serialize) session has its own serialize. Otherwise it will simply be NULL if its not valid.
  5. 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 : 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!!
  6. Ok final question, I've written my class for this and in my database i have this : 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?
  7. So session_destroy(); would then be a mySQL delete based on $id ?
  8. 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!
  9. Hey Is there any special way to prevent the PHP from running when a user who by chance finds the Cron PHP file and visits it causing the file to execute before the server's time interval dictates it to ?
  10. Hey I'm wondering if there is any way to call a HTML file in JavaScript and also parse a JS array. I have a html file which has a table but i want to loop my JS array into that table as rows of data. Is there anyway to do it at all ?
  11. how come it does't execute script blocks? Seems a bit strange =/
  12. 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 ?
  13. Also i didn't get the same output as you ... i got: echo crypt('abc123', '$2a$04$saltsaltsaltsaltsaltxx'); Result :
  14. So something like this? <?php $result = crypt('abc123', '$2a$04$saltsaltsaltsaltsaltxx'); $array = explode('.',$result); $salt = $array[0]; $hash_pss = $array[1].$array[2]; ?>
  15. I'm not following how your example returns the salt ? Wouldn't that just return the hash of the input + salt ? How do you get the salt out of it?
×
×
  • 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.