I am writing a PHP script where I take input from user like server IP and one more input.
After this is available, I make ssh call to the server and execute some command. I want to show the output on the web page but i gets error as 500 (server error).
Here is my main script where i get input from user:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Centos Health Checker</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<center>
<div id="login-form">
<form method="post" action="redirectPage.php">
<table align="center" width="30%" border="0">
<tr>
<td><input type="text" name="IP" placeholder="System IP" required /></td>
</tr>
<tr>
<td><input type="text" name="Component" placeholder="Component" required /></td>
</tr>
<tr>
<td><button type="submit" name="submit">Check System</button></td>
</tr>
</table>
</form>
</div>
</center>
</body>
</html>
Here is my landing page:
<?php
function Connect()
{
include('/home/as5714/php_data/Net/SSH2.php');
$IP1 = $_POST['IP'];
$Component1 = $_POST['Component'];
$ssh = new Net_SSH2($IP1);
if (!$ssh->login('centos', 'centos')) {
exit('Login Failed');
}
echo $ssh->exec('pwd');
echo $ssh->exec('ls -la');
}
if(isset($_POST['submit']))
{
Connect();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome - <?php echo $IP1; ?></title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div id="header">
<div id="left">
<label>cleartuts</label>
</div>
<div id="right">
<div id="content">
Cennecting to ' <?php echo $IP1; ?> and Data is : <?php echo $data2; ?> Go Back
</div>
</div>
</div>
</body>
</html>
I am getting server error(500) while using above php code.
Please note that I am working on vim editor on a linux server for the script and do not have any logs available. Also, If I just run the program to do ssh connection and execution of command in server directly (php 123.php), I get proper data on console.
Please help.
Related
Since yesterday slideshare API for upload slideshow using PHP didn't work.
We receive only 500 response (check below).
We accessed endpoint: https://www.slideshare.net/api/2/upload_slideshow
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link href="/stylesheets/error.css" type="text/css" rel="stylesheet" media="screen" />
<script type="text/javascript">
function disableSearch(event) {
var t = document.getElementById('searchstring');
if(t.value === 'Type text here …' || t.value.length === 0) {
event.preventDefault();
}
}
</script>
<title>500 error. The page could not be loaded.</title>
</head>
<body>
<div class="smiley"><img src="/images/errorsmiley.png" width="128px" height="128px" alt="error" /></div>
<div class="errorBox">
<p class="errorCode">500</p>
<h1>Sorry! The page could not be loaded.</h1>
<h2>
This is probably a temporary error. Just refresh the page and retry. If problem continues, please check back in 5-10 minutes.
<br/><br/>You could also check out our homepage or search below.</h2>
<div class="searchSection">
<form style="display: inline;" action="/search/slideshow" method="get">
<input type="text" id="searchstring" name="q" value="Type text here …" class="errorSearchBox" onclick="this.value = '';">
<button type="submit" onclick="disableSearch(event)">
Search<span> </span></button>
</form>
</div>
</div>
</body>
</html>
I am trying to add reCAPTCHA to my php/html site. But it does not display. I have downloaded the library and set up my site so I have the public and private keys. I have created a basic page to try and get this working but still no luck. This is my php code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
require_once('lib/recaptchalib.php');
?>
<title>Test odds and ends</title>
</head>
<body>
<form method="post" action="">
<?php
$publickey = "~hidden~";
echo recaptcha_get_html($publickey);
?>
</form>
</body>
</html>
The page displays completely blank. The html produced is:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test odds and ends</title>
</head>
<body>
<form method="post" action="">
<script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k=~hidden~">
</script>
<noscript>
<iframe src="http://www.google.com/recaptcha/api/noscript?k=~hidden~" height="300" width="500" frameborder="0">
</iframe><br/>
<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
<input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
</noscript>
</form>
</body>
</html>
Does anyone know why this doesn't work? Many thanks in advance.
I made a pop-up window that has a submit form and upon submission it must close but i first want to process the information from the pop-up window in a different page without displaying that other page. How can I do it?
my popupwindow contains this code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function closeSelf(){
self.close();
return true;
}
</script>
<title>Add Activity</title>
</head>
<body>
<form action="./addact.php" method="post" onsubmit ="return closeSelf()">
<table width="500" border="1"><br/>
<tr>
<td>Activity Name</td>
<td>Assigned Person</td>
<td>Deadline</td>
</tr>
<tr>
<td> <input name="activities" type="text" size="40%"/></td>
<td><input name="name" type="text" size="40%"/></td>
<td><input type="date" name="deadline" size="20%"/></td>
</tr>
</table>
<input type="submit" name = "saved" id="saved"/>
</form>
</body>
</html>
and my other page contains this
<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<?php
include('config.php');
$actname= $_POST['activities'];
$assigned = $_POST['name'];
$deadline = $_POST ['deadline'];
$sql = "INSERT INTO ".$_SESSION['pname']."_activities
(actname, assigned, deadline)
VALUES
('$actname', '$assigned', '$deadline')
";
$query = mysql_query($sql);
echo $_SESSION['pname'];
?>
<body>
</body>
</html>
You should close the window when the response is returned, not when you submit the page. And as #Marc B pointed out, you have major security problem!
This was my last attempt that I tried as a last effort:
index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Customer Login</title>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="wrapper">
<div class="login">
<form name="loginForm" action="loginCheck.php" method="post">
<?php require("protect/serverInfo.php"); ?>
Email: <input type="text" name="Email" maxlength="35" /><br />
Password: <input type="text" name="Password" maxlength="4" /><br />
<input type="submit" name ="submit"/>
</form>
</div>
</div>
</body>
</html>
loginCheck.php
<?php
session_start();
$_SESSION['email'] = $_POST['Email'];
$_SESSION['password'] = $_POST['Password'];
require("protect/serverInfo.php");
$myusername=$_POST[Email];
$mypassword=$_POST[Password];
$result = mysql_query("SELECT * FROM Customers WHERE Email='$myusername' AND Password=$mypassword");
$count=mysql_num_rows($result);
if($count==1){
header('Location: customer.php');
exit();
}
else{
header('Location: index.php');
exit();
}
?>
customer.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
<?php
session_start();
$myusername = $_SESSION['email'];
$mypassword = $_SESSION['password'];
?>
</head>
<body>
<?php
echo"success";
?>
</body>
</html>
I just need a very simple way to have a form post, the post info to be checked if correct then redirect if correct and pass the post data with it. I have been trying to use sessions and redirects but it doesn't to work quite right. What is the easiest way to accomplish this. At the moment I have been using PHP to check the login info from a MySQL database.
You need to use "session_start()" before you do anything else on the page.
Other few things, I avoid storing passwords on a page.. it just seems like a security issue.
Your login form should generate $_SESSION data based on the mysql information returned from the queury, not the form information that the user submited. You need to check against your customers database, to make sure they are an actual customer.
Also, avoid using the "header()" function, especially when working with sessions. I typically have a "redirect" function in php that does something like this...
function redirect($url) {
echo "<script type='text'/javascript'>window.location='" . $url . "';</script>";
}
I'm starting to try to learn PHP while using Expression Web 3. I set up PHP runtime and configured the ini. What happens is my script doesn't do as it should.
My page looks like:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="en-us" http-equiv="Content-Language" />
<title>Sports</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link href="master.css" rel="stylesheet" type="text/css" />
<style type="text/css">
</style>
</head>
<body>
<div id="masthead">
</div>
<div id="top_nav">
<ul>
<li>Sports </li>
<li>Clubs</li>
<li>Cloud</li>
</ul>
</div>
<div id="container">
<div id="left_col">
</div>
<div id="page_content">
</div>
</div>
<div id="footer">
<form method="post">
</form>
</div>
<form action="action.php" method="post">
<p>Your name: <input type="text" name="name" /></p>
<p>Your age: <input type="text" name="age" /></p>
<p><input type="submit" /></p>
</form>
</body>
</html>
Then my PHP file looks like:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>action</title>
</head>
<body>
Hi <?php echo htmlspecialchars($_POST['name']); ?>.
You are <?php echo (int)$_POST['age']; ?> years old.
</body>
</html>
What should happen is for example if I type John as name and 50 as age, it should output Hi John, you are 50 years old.
But instead it says (with Firefox) :
Hi you are years old
in Internet Explorer 8, it just outputs the whole php script.
I'm not sure where I went wrong.
Thanks
Either you are not running these files from a PHP enabled webserver or the webserver is not configured to serve the used file extension as PHP. How to install and configure a webserver is best asked on ServerFault.com. Have a look at XAMP or Zend Server CE.
In addition, you have a terribly low acceptance rate. Why not go back to some previous questions and you asked and accept some of the answers you have been given?