简体   繁体   English

在两个HTML和PHP之间交换变量

[英]Exchange variables between two HTMLs and PHP

I'm trying to do a singup form to a mikrotik hotspot, this device do not allow to use PHP inside it, and I need to carry the variables from the device to a external php page that will save the costumer data and enable the trial in Hotspot... 我正在尝试对mikrotik热点进行汇总,此设备不允许在其中使用PHP,并且我需要将设备中的变量携带到外部php页面中,以保存客户数据并启用试用版在热点...

Inside this device it hosted a HTML page with the following code 在此设备内,它托管了一个包含以下代码的HTML页面

<html>
<head><title>...</title></head>
<body>
$(if chap-id)
<noscript>
<center><b>JavaScript required. Enable JavaScript to continue.</b></center>
</noscript>
$(endif)
<center>If you are not redirected in a few seconds, click 'continue' below<br>
<form name="redirect" action="http://10.2.3.100/cadastro.html?mac=$(mac)" method="post">
<input type="hidden" name="mac" value="$(mac)">
<input type="hidden" name="ip" value="$(ip)">
<input type="hidden" name="username" value="$(username)">
<input type="hidden" name="link-login" value="$(link-login)">
<input type="hidden" name="link-orig" value="$(link-orig)">
<input type="hidden" name="error" value="$(error)">
<input type="hidden" name="chap-id" value="$(chap-id)">
<input type="hidden" name="chap-challenge" value="$(chap-challenge)">
<input type="hidden" name="link-login-only" value="$(link-login-only)">
<input type="hidden" name="link-orig-esc" value="$(link-orig-esc)">
<input type="hidden" name="mac-esc" value="$(mac-esc)">
<input type="submit" value="continue">
</form>
<script language="JavaScript">
<!--
    document.redirect.submit();
//-->
</script></center>
</body>
</html>

I've learned searching in google that I can send the variables to another page, by inserting it at the end of the URL, so ok, I will send the variable $MAC that I need to start the trial. 我学会了在google中搜索,可以将变量发送到另一页,方法是将其插入URL的末尾,所以好的,我将发送开始试用所需的变量$ MAC。

The page that receive it is a form page writen in HTML, I could not receive the variable in this page, I need to receive this variable to send to another page, in PHP the last one that will save the form in MySQL and after send to Mikrotik the link with the MAC of client to allow it to browse in internet. 接收它的页面是用HTML编写的表单页面,我无法在该页面中接收该变量,我需要接收该变量以发送到另一页面,在PHP中,最后一个将在MySQL中保存表单并在发送之后到Mikrotik与客户端MAC的链接,使其可以在Internet中浏览。

<!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>CADASTRO DE CLIENTES COM BANCO DE DADOS E PHP</title>
<style type="text/css">


</head>

<body>
<p id="demo"></p>
<script type"text/javascript">
var qs = new QueryString();
var v1 = qs.get("mac");
document.getElementById("demo").innerHTML = v1;
</script>


<form id="cadastro" name="cadastro" method="post" action="cadastro.php" onsubmit="return validaCampo(); return false;">
  <table width="625" border="0">
    <tr>
      <td width="69">Nome:</td>
      <td width="546"><input name="nome" type="text" id="nome" value="$(mac)" size="70" maxlength="60" />
        <span class="style1">*</span></td>
    </tr>
    <tr>
      <td>Email:</td>
      <td><input name="email" type="text" id="email" size="70" maxlength="60" />
      <span class="style1">*</span></td>
    </tr>

    <tr>
      <td colspan="2"><p>
        <input name="cadastrar" type="submit" id="cadastrar" value="Concluir meu Cadastro!" /> 
        <br />
          <input name="limpar" type="reset" id="limpar" value="Limpar Campos preenchidos!" />
          <br />
          <span class="style1">* Campos com * s&atilde;o obrigat&oacute;rios!          </span></p>
      <p>&nbsp; </p></td>
    </tr>
  </table>
</form>
</body>
</html>

Now the PHP page 现在,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=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<?php 
// RECEBENDO OS DADOS DO PC DO USUARIO
   $mac=$_POST['mac'];

// RECEBENDO OS DADOS PREENCHIDOS DO FORMULÁRIO !
$nome   = $_POST ["nome"];  //atribuição do campo "nome" vindo do formulário para variavel  
$email  = $_POST ["email"]; //atribuição do campo "email" vindo do formulário para variavel

//Gravando no banco de dados !

//conectando com o localhost - mysql
$conexao = mysql_connect("localhost","root","senha");
if (!$conexao)
    die ("Erro de conexão com localhost, o seguinte erro ocorreu -> ".mysql_error());
//conectando com a tabela do banco de dados
$banco = mysql_select_db("cadhotspot",$conexao);
if (!$banco)
    die ("Erro de conexão com banco de dados, o seguinte erro ocorreu -> ".mysql_error());



$query = "INSERT INTO `clientes` ( `nome` , `email`  ) 
VALUES ('$nome', '$email', '$sexo' '')";

mysql_query($query,$conexao);

echo "Seu cadastro foi realizado com sucesso!<br>Agradecemos a atenção.";
?>
Mac: <?php echo $mac ?><br>

<meta http-equiv="refresh" content="60; url=<?php echo $linkloginonly; ?>?dst=<?php echo $linkorigesc; ?>&username=T-<?php echo $mac; ?>">


</body>
</html>

The idea is, receive the MAC from customer device from the MikroTik to a HTML page hosted in it, after that load a HTML page with form to customer singup and when the customer click in send it will write to mysql and send back the link below to Mikrotik 这个想法是,从MikroTik从客户设备接收MAC到托管在其中的HTML页面,然后将带有表单的HTML页面加载到客户singup,当客户单击发送时,它将写入mysql并发回下面的链接去米克罗蒂克

 <meta http-equiv="refresh" content="60; url=http://10.5.50.1?&username=T-<?php echo $mac; ?>">

My entire problem is to exchange the variables between HTML to HTML and after PHP pages. 我的整个问题是在HTML与HTML之间以及PHP页面之后交换变量。

To forward the value of mac to php page try to add the following JS code inside the form. 要将mac的值转发到php页面,请尝试在表单内添加以下JS代码。 This will create a hidden field which when submitted will post the mac value to the php page. 这将创建一个隐藏字段,提交后会将mac值发布到php页面。

<script type="text/javascript">
var qs = new QueryString();
var v1 = qs.get("mac");
document.write('<input type="hidden" name="mac" value="' + v1  + '">')
</script>

There are some ending tags missing in the html pages. html页面中缺少一些结束标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM