Jump to content

Whats wrong with that? 'img onclick'


RaNN

Recommended Posts

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 ><

Link to comment
Share on other sites

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 by Barand
Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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