if on the screen before the query is performed

1

I'm trying to create a consultant with PHP who makes a request on a form with an email from the client and returns me if he is registered in the service. The problem is that when I start my page directly the if prints on the screen the value true (it should only pass me the values of if after the query made).

HTML code:

<html>
    <head>
        <!-- Latest compiled and minified CSS -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

        <!-- Optional theme -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">

        <!-- Latest compiled and minified JavaScript -->
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<head>
</head>
<head>

    <title>.::Cliente Consultor::.</title>
</head>
<body>
<form method="POST">
<center>
    <BR>
        <BR>
            <BR>
<font size="4" color="orange" face="Segoe Print">.::Consulta::.<img src=""  </font></span></p></div align=""> 
<BR>
    <BR>
        <BR>
<input type="text" name="bin">
<input type="submit">
</center>   
</form>
</body>
<style>
body { 
  background: url() no-repeat center center fixed; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  color: black;
}
.twitter a{
  text-decoration: none;
  font-family: Arial, sans-serif  ;
  font-size: 50px;
  text-shadow: grey 0px 0px 10px;
}


}</style>
</html>

PHP code:

<?php


 error_reporting(0);

$bin = $_POST['bin'];

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, "https://minhaconta.payleven.com.br/forgot-password");
            curl_setopt($ch, CURLOPT_HEADER, 1);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

           curl_setopt( $ch, CURLOPT_POSTFIELDS, "password_token_type[email]=$bin" );
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
            $s = curl_exec($ch);

$mensagem = ' ';


if ($1 == $2) 

{



            $q = explode('</title>', $s);  
            $1 = $q[1];
            $2 = $q[1];
            $binchecker = " [".$bin."] ";

$mensagem = 'cliente encontrado';

} 

else

{

$mensagem= 'cliente não cadastrado';

}


   echo "<br><br><center>".$mensagem."</center>";




?>
    
asked by anonymous 03.07.2017 / 14:59

1 answer

1
  • To execute PHP code only when the form is submitted, you need to make a check of the HTTP method of the treated request and the fields present in that request.

    <?php
    
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
        // Código aqui...
    }
    
  • Do not use error_reporting(0) without knowing what you are doing. In my view, you should never use this line of code. This will hide any error messages in your code, but error messages are your best friends.

  • PHP does not allow variables with names beginning with numbers, with only letter or underline. Read documentation for more details.

  • It does not make sense for you to check the value of two variables before you can define it. You are setting the value of $1 and $2 only within if , so in condition $1 == $2 neither exists.

  •   

    Remembering that $1 and $2 are not valid names for variables.

  • It also makes no sense for you to echo of an HTML element out of the html and body tag. The message should be properly displayed in the body of the page.
  • 03.07.2017 / 15:26