RaNN Posted August 10, 2014 Share Posted August 10, 2014 Hello, I am trying to make 'onclick img' that will provide a Linux command when clicked. I've been trying this code: <body> <?php include("connect.php"); include('Net/SSH2.php'); *** CONNECTION TO DATABASE MYSQL CODE *** if(mysql_num_rows($result) > 0) { while($row = mysql_fetch_array($result)) { $_SESSION['logged'] = true; $ssh = new Net_SSH2('xx.xx.xx.xx'); if (!$ssh->login($info['username'], $info['password'])) { exit('Connection to Linux has failed, please try again.'); } echo '<form action="" method="GET">'; echo '<input type="image" src="start.png" width=100 height=100 name="start" />'; echo '</form>'; if(isset($_GET['start'])) { echo $ssh->setTimeout(5); echo $ssh->exec('(cd '.$info['username'].' ; nohup ./samp03svr &)'); } } } else { $_SESSION['logged'] = null; header("Location: loginfail.php"); } ?> </body> But when I clicked the image, it sends me to "loginfail.php". Please help >< Quote Link to comment https://forums.phpfreaks.com/topic/290374-whats-wrong-with-that-img-onclick/ Share on other sites More sharing options...
Barand Posted August 10, 2014 Share Posted August 10, 2014 (edited) When you click the image the page is reloaded as the form action, by default, is to call itself. It is when the page reloads that $_GET['start'] exists (not inside your while() loop) On this second load there is no username or password so nothing is retrieved from the db and you go the else{} condition. You need to test $_GET['start'] at the top of the code. edit: (Actually start_x and start_y are sent where x,y is the position of the click in the image) Edited August 10, 2014 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/290374-whats-wrong-with-that-img-onclick/#findComment-1487314 Share on other sites More sharing options...
RaNN Posted August 10, 2014 Author Share Posted August 10, 2014 When you click the image the page is reloaded as the form action, by default, is to call itself. It is when the page reloads that $_GET['start'] exists (not inside your while() loop) On this second load there is no username or password so nothing is retrieved from the db and you go the else{} condition. You need to test $_GET['start'] at the top of the code. edit: (Actually start_x and start_y are sent where x,y is the position of the click in the image) I didn't really got you, where should I put that $_GET? thanks for answer though! Quote Link to comment https://forums.phpfreaks.com/topic/290374-whats-wrong-with-that-img-onclick/#findComment-1487315 Share on other sites More sharing options...
Barand Posted August 10, 2014 Share Posted August 10, 2014 As I said, the test for $_GET['start_x] needs to go at the top of the page where you are currently getting info sent to the page, prior to querying the db Quote Link to comment https://forums.phpfreaks.com/topic/290374-whats-wrong-with-that-img-onclick/#findComment-1487317 Share on other sites More sharing options...
RaNN Posted August 10, 2014 Author Share Posted August 10, 2014 As I said, the test for $_GET['start_x] needs to go at the top of the page where you are currently getting info sent to the page, prior to querying the db Eh.. what should code should I put there then? As much as I understand, I gotta make like 'autologin' login system but I didn't success. Quote Link to comment https://forums.phpfreaks.com/topic/290374-whats-wrong-with-that-img-onclick/#findComment-1487318 Share on other sites More sharing options...
Barand Posted August 10, 2014 Share Posted August 10, 2014 Eh.. what should code should I put there then? Obviously code that does whatever you want to do in the event that the user has clicked on the image (ie $_GET['start_x'] is set) Quote Link to comment https://forums.phpfreaks.com/topic/290374-whats-wrong-with-that-img-onclick/#findComment-1487319 Share on other sites More sharing options...
RaNN Posted August 10, 2014 Author Share Posted August 10, 2014 Obviously code that does whatever you want to do in the event that the user has clicked on the image (ie $_GET['start_x'] is set) Tried, not working >< Quote Link to comment https://forums.phpfreaks.com/topic/290374-whats-wrong-with-that-img-onclick/#findComment-1487320 Share on other sites More sharing options...
boompa Posted August 10, 2014 Share Posted August 10, 2014 You do realize the security implications of allowing direct user input in a Linux command line, right? Quote Link to comment https://forums.phpfreaks.com/topic/290374-whats-wrong-with-that-img-onclick/#findComment-1487335 Share on other sites More sharing options...
RaNN Posted August 10, 2014 Author Share Posted August 10, 2014 You do realize the security implications of allowing direct user input in a Linux command line, right? This is just a command to turn on a SAMP server. Quote Link to comment https://forums.phpfreaks.com/topic/290374-whats-wrong-with-that-img-onclick/#findComment-1487342 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.