header()加载同一页面上的所有内容ajax

时间:2016-09-29 03:36:22

标签: javascript php ajax

当我点击登录时,它会在index.php上加载home.php,看起来很奇怪..是否有可能让它重定向或删除index.php上的所有内容然后加载home.php



function login(){
	var name = $('input#answer').val();
	var pass = $('input#password').val();
	if( $(name) == '' || $(pass) == '' )
		$('#output').html('Please enter both username and password.');
	else
		$.post( ('php/login.php'), $('#myForm :input').serializeArray(), 
			function(data){
				$('#output').html(data);
				
	});
	$('#myForm').submit(function(){
		return false;
	});
};

<?php
session_start();
if(isset($_SESSION['users']) != ""){
header("Location: ../php/home.php");
}

require '../php/dbConnect.php';
    $username = $_POST['username'];
	$password = $_POST['password'];
    $query = ("SELECT * FROM `accounts` WHERE username = '$username'")or die(mysql_error());
    $response = mysql_query($query);
	
	$row = mysql_fetch_array($response);
	
    if($row['password'] == md5($password))
    {
		
        $_SESSION['user'] = $row['username'];
        header("Location: ../php/home.php");
    }
    else{
        echo("Wrong Credentials");
	}
?>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

也许试试:

npm WARN deprecated wrench@1.5.9: wrench.js is deprecated! You should check out fs-extra (https://github.com/jprichardson/node-fs-extra) for any operations you were using wrench for. Thanks for all the usage over the years.
npm WARN deprecated minimatch@2.0.10: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated tough-cookie@2.2.2: ReDoS vulnerability parsing Set-Cookie https://nodesecurity.io/advisories/130
/home/ablekh/.nvm/versions/node/v6.5.0/bin/binder-control -> /home/ablekh/.nvm/versions/node/v6.5.0/lib/node_modules/binder-control/bin/binder-control

> fibers@1.0.14 install /home/ablekh/.nvm/versions/node/v6.5.0/lib/node_modules/binder-control/node_modules/fibers
> node build.js || nodejs build.js

`linux-x64-v8-5.1` exists; testing
Binary is fine; exiting

> websocket@1.0.23 install /home/ablekh/.nvm/versions/node/v6.5.0/lib/node_modules/binder-control/node_modules/websocket
> (node-gyp rebuild 2> builderror.log) || (exit 0)

make: Entering directory `/home/ablekh/.nvm/versions/node/v6.5.0/lib/node_modules/binder-control/node_modules/websocket/build'
  CXX(target) Release/obj.target/bufferutil/src/bufferutil.o
  SOLINK_MODULE(target) Release/obj.target/bufferutil.node
  COPY Release/bufferutil.node
  CXX(target) Release/obj.target/validation/src/validation.o
  SOLINK_MODULE(target) Release/obj.target/validation.node
  COPY Release/validation.node
make: Leaving directory `/home/ablekh/.nvm/versions/node/v6.5.0/lib/node_modules/binder-control/node_modules/websocket/build'

> binder-db@1.0.1 postinstall /home/ablekh/.nvm/versions/node/v6.5.0/lib/node_modules/binder-control/node_modules/binder-db
> node scripts/postinstall.js

events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: EACCES: permission denied, open '/home/ablekh/.binder/db.conf'
    at Error (native)
/home/ablekh/.nvm/versions/node/v6.5.0/lib
└── (empty)

npm WARN optional Skipping failed optional dependency /binder-control/chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.0.14
npm ERR! Linux 3.19.0-33-generic
npm ERR! argv "/home/ablekh/.nvm/versions/node/v6.5.0/bin/node" "/home/ablekh/.nvm/versions/node/v6.5.0/bin/npm" "install" "binder-control" "-g"
npm ERR! node v6.5.0
npm ERR! npm  v3.10.3
npm ERR! code ELIFECYCLE

npm ERR! binder-db@1.0.1 postinstall: `node scripts/postinstall.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the binder-db@1.0.1 postinstall script 'node scripts/postinstall.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the binder-db package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node scripts/postinstall.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs binder-db
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls binder-db
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/ablekh/npm-debug.log
npm ERR! code 1

您通常需要在$_SESSION['user'] = $row['username']; header("Location: ../php/home.php"); die(); 声明后发出die()命令。