Jump to content

Login form - from .aspx to php help?


harvdog13

Recommended Posts

Hey everyone, first post here -- just looking for a bit of help with a php login script. I have it in .aspx and I am trying to convert it to php obviously. Just not terribly familiar with php.

 

Here is the ASP.Net code...

 

HttpWebRequest req =
(HttpWebRequest)WebRequest.Create("https://mysiteurl.aspx");
           req.Headers.Add("el-user", txtUser.Text);
           req.Headers.Add("el-pass", txtPass.Text);
           req.Method = "GET";


           HttpWebResponse webresponse = (HttpWebResponse)req.GetResponse();
           StreamReader ResponseStream = new StreamReader(webresponse.GetResponseStream());

           Response.Write(ResponseStream.ReadToEnd());
           Response.End();
           ResponseStream.Close();

 

Thanks in advance for any help!

Link to comment
https://forums.phpfreaks.com/topic/160494-login-form-from-aspx-to-php-help/
Share on other sites

The difference between ASP and PHP is quite a bit. Here's the login section of my script:

<?
// start session
session_start();

// start output buffering
ob_start();

// File includes
include "cfg.php";
include "functions.php";
include "variables.php";

// has form been submitted
if ($_POST['Submit'] == 'Login') {
$md5pass = md5(sanitize($_POST['password']));
$sql = mysql_query(sprintf("SELECT email, level FROM $tbl_name WHERE email='%s' and password='%s' and confirm='%d'", sanitize($_POST['email']), $md5pass, (int)1));

// we have a match
if (mysql_num_rows($sql) > 0)
{
// A matching row found (thus the name/pass found) - authenticated
list($email, $level) = mysql_fetch_row($sql);
//list($level) = mysql_fetch_row($sql);
// set user session
$_SESSION['user'] = $email;

// set session level - this is for security
$_SESSION['level'] = $level;

// redirect
if ($_SESSION['level'] == 1) {
// the user is logged in as non-admin
header("Location: calendar.php?msg=Logged In");
exit();
}

if ($_SESSION['level'] == 2) {
// the user is logged in as an admin
header("Location: admin/index.php");
exit();
}
} else {
// Add to DB that a failed login attempt occured
mysql_query(sprintf("INSERT into $tbl_logins (email, password, date, ip, id)
					VALUES ('%s', '%s', '%s', '%s', '%d')", 
					sanitize($_POST['email']), sanitize($_POST['password']), $today, $ip, '')) 
					or die('SQL Error : ' . mysql_error());
					$error = mysql_error();
header("Location: login.php?msg=Invalid Login");
exit();
}

} else { 
ShowLogin();
}
?>
<link href="styles.css" rel="stylesheet" type="text/css">
<?php
$msg = htmlentities(trim($_GET['msg']));
$msg = (isset($msg)) ? true : false;

if ($msg)
{ echo "<div class='msg'> $_GET[msg] </div>"; }

// release output buffer
ob_end_flush(); ?>

Hey everyone, first post here -- just looking for a bit of help with a php login script. I have it in .aspx and I am trying to convert it to php obviously. Just not terribly familiar with php.

 

Here is the ASP.Net code...

 

HttpWebRequest req =
(HttpWebRequest)WebRequest.Create("https://mysiteurl.aspx");
           req.Headers.Add("el-user", txtUser.Text);
           req.Headers.Add("el-pass", txtPass.Text);
           req.Method = "GET";


           HttpWebResponse webresponse = (HttpWebResponse)req.GetResponse();
           StreamReader ResponseStream = new StreamReader(webresponse.GetResponseStream());

           Response.Write(ResponseStream.ReadToEnd());
           Response.End();
           ResponseStream.Close();

 

Thanks in advance for any help!

 

Try this. I am using cURL here:

 

<?php
$elUser = 'username';
$elPass = 'password';

// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "https://mysiteurl.aspx?el-user=" . urlencode($elUser) . "&el-pass=" . urlencode($elPass));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

// grab URL and pass it to the browser
$response = curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);

// print the response
print_r($response);
?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.