dongyou2279 2016-12-30 17:47
浏览 47

卷曲,简单的PHP登录响应形式

I'm trying to create a simple php login page, for testing purposes.

Basically, it just needs username, password and submit.

I have found this easy code and it works fine:

<?php
session_start(); $username = $password = $userError = $passError = '';
if(isset($_POST['sub'])){
  $username = $_POST['username']; $password = $_POST['password'];
  if($username === 'admin' && $password === 'password'){
    $_SESSION['login'] = true; header('LOCATION:wherever.php'); die();
  }
  if($username !== 'admin' || $password !== 'pass')  echo "Invalid";
   else echo "Valid";

}
echo "<!DOCTYPE html>
<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' />
     <title>Login</title>
     <style type='text.css'>
       @import common.css;
     </style>
   </head>
<body>
  <form name='input' action='{$_SERVER['PHP_SELF']}' method='post'>
    <label for='username'></label><input type='text' value='$username' id='username' name='username' />
    <div class='error'>$userError</div>
    <label for='password'></label><input type='password' value='$password' id='password' name='password' />
    <div class='error'>$passError</div>
    <input type='submit' value='Submit' name='sub' />
  </form>
  <script type='text/javascript' src='common.js'></script>
</body>
</html>";
?>

Now the purpose of this page should be this:

On submitting "admin", "pass" return "Valid". Anything else, return "Invalid".

If I click submit and login, Valid/Invalid appear accordingly on top.

The problem is that when I try to get the same output with curl (http post?), it fails to print any.

I have tried this, according to all the answers I could find it's correct:

curl --data "username=admin&password=pass&sub=Submit" http://altervista.mypagegoeshere.org/index.php -o /root/Desktop/out.txt

But it shows no output.

**Other answers suggested replacing --data with -F

This action still prints neither "Valid" nor "Invalid", but does print the whole html code of the page.**

Curling just the address gived back all the html, so that's correct.

I need the curl input to return Valid, or Invalid.

What am I doing wrong?

According to the answers here on SO and to https://curl.haxx.se/docs/manual.html the curl command I wrote is correct.

I am running this from the ubuntu terminal, I don't know if that's helpful.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题