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
https://forums.phpfreaks.com/topic/290374-whats-wrong-with-that-img-onclick/
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)

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!

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. 

Archived

This topic is now archived and is closed to further replies.

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