php JSON til ASP JSON
Er der mon nogle herinde der kan hjælpe mig med at oversætte følgende PHP kode med JSON til ASP?<?php
$error = false;
// Lib to enable support for json_encode for php < 5.2.0 - remove if your version is 5.2.0 or upper
require('_errors/libError.php');
// If login form submitted
if (isset($_POST['a']))
{
$valid = false;
$redirect = isset($_REQUEST['redirect']) ? $_REQUEST['redirect'] : 'index.php';
// Check fields
if (!isset($_POST['login']) or strlen($_POST['login']) == 0)
{
$error = 'Please enter your user name';
}
elseif (!isset($_POST['pass']) or strlen($_POST['pass']) == 0)
{
$error = 'Please enter your password';
}
else
{
/*
* Do whatever here to check user login
*/
$valid = ($_POST['login'] == 'admin' and $_POST['pass'] == 'admin');
if (!$valid)
{
$error = 'Wrong user/password, please try again';
}
}
// Check if AJAX request
$ajax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) and strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
// If user valid
if ($valid)
{
// Handle the keep-logged option
if (isset($_POST['keep-logged']) and $_POST['keep-logged'] == 1)
{
// Set cookie or whatever here
}
if ($ajax)
{
header('Cache-Control: no-cache, must-revalidate');
header('Expires: '.date('r', time()+(86400*365)));
header('Content-type: application/json');
echo json_encode(array(
'valid' => true,
'redirect' => $redirect
));
exit();
}
else
{
header('Location: '.$redirect);
exit();
}
}
else
{
if ($ajax)
{
header('Cache-Control: no-cache, must-revalidate');
header('Expires: '.date('r', time()+(86400*365)));
header('Content-type: application/json');
echo json_encode(array(
'valid' => false,
'error' => $error
));
exit();
}
}
}
?>