Pop up window closed without completion of the function - php

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!

Related

Unable to echo the data from ssh execution to webpage in PHP

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.

Error with where I position the new text

I was wondering if it could post to the top and instead of posting on the bottom?
index.php
<!DOCTYPE html PUBLIC "-W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="Content-Type" content="text/xml; charset=utf-8 ">
<title> Printing Statuses </title>
</head>
<body>
<form action = "StatusPoster.php" method = "get">
<fieldset>
<label>How are you feeling today?</label>
<input type = "text"
name = "userStatus" /><br>
<button type = "submit">
Submit
</button>
</fieldset>
</form>
</body>
</html>
StatusPoster.php
<!DOCTYPE html PUBLIC "-W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="Content-Type" content="text/xml; charset=utf-8 ">
<title> Printing Statuses </title>
</head>
<body>
<h1>Posted Successfully!</h1>
<?php
$date=date("m-d-Y h:i:s");
$userStatus = $_REQUEST["userStatus"];
print "<p>$userStatus at $date</p>"
?>
<?php
$status = fopen("mystatuses.php", "a+") or die("Unable to open file!");
$txt = " <span title='$date'>$userStatus</span><br>\n";
fwrite($status, $txt);
fclose($status);
print "Click <a href='http://localhost/FacebookStatus/mystatuses.php'>here</a> to see all statuses"
?>
</body>
</html>
mystatuses.php
Click <a href='http://localhost/FacebookStatus'>here</a> to go back<br> <span title='09-04-2015 10:22:30'>Alright</span><br>
<span title='09-04-2015 10:23:02'>Good</span><br>
<span title='09-04-2015 10:23:07'>Bad</span><br>
<span title='09-04-2015 10:26:02'>alright</span><br>

php reCAPTCHA not displaying

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.

fill text field by clicking on another page

i have two pages.When i click link on first page, it fill text field on second page(get value from 'from' ).
my first page codes abc.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 http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<p><strong>From</strong> <strong> Subject</strong> <strong>Reply</strong></p>
<p>biri deneme girdi click</p>
</body>
</html>
and this is second page kum.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 http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<label>
<input type="text" name="hum" id="hum" />
</label>
</form>
</body>
</html>
What should i do?
you can get the url where the user comes from with $_SERVER['HTTP_REFERER'];
<input type="text" name="hum" id="hum"<?php if ($_SERVER['HTTP_REFERER'] == "http://examplepage.com/start/"){?> value="hi" <?php } ?>
/>
(not tested, just to give you a idea how you could use it)

textbox number type in html cut off 0 if post form in php

If i give textbox type as number and submit a form it cut off 0 .
ex: 099921 means it will post as 99921
why it cut off preceding 0
Because 0 in front means nothing and is removed. Make it a string (text) and it will stay. Ints have no 0 in front.
i dont know why but i did the same code and it is displaying the value with o i.e 099921
check out my code
<?php
if(isset($_POST['submit']))
{
echo $numberValue = $_POST['numVal'];
}
?>
<!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>
<body>
<form method="post">
<input type="number" name="numVal" value="" />
<input type="submit" name="submit" value="submit"/>
</form>
</body>
</html

Categories