harvdog13 Posted June 1, 2009 Share Posted June 1, 2009 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 More sharing options...
peter_anderson Posted June 1, 2009 Share Posted June 1, 2009 You'd be better rewriting it completely for PHP. Too much differences. Link to comment https://forums.phpfreaks.com/topic/160494-login-form-from-aspx-to-php-help/#findComment-846989 Share on other sites More sharing options...
harvdog13 Posted June 1, 2009 Author Share Posted June 1, 2009 Hmm, really? Someone had told me it might not be too hard to convert. Suppose they were wrong then. That's no fun. Link to comment https://forums.phpfreaks.com/topic/160494-login-form-from-aspx-to-php-help/#findComment-847020 Share on other sites More sharing options...
Dark-Hawk Posted June 1, 2009 Share Posted June 1, 2009 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(); ?> Link to comment https://forums.phpfreaks.com/topic/160494-login-form-from-aspx-to-php-help/#findComment-847021 Share on other sites More sharing options...
anupamsaha Posted June 1, 2009 Share Posted June 1, 2009 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); ?> Link to comment https://forums.phpfreaks.com/topic/160494-login-form-from-aspx-to-php-help/#findComment-847027 Share on other sites More sharing options...
harvdog13 Posted June 1, 2009 Author Share Posted June 1, 2009 Thanks for the heads up Dark-Hawk. Maybe it won't work quite as easy as I'd have hoped. Thanks for the code anupamsaha -- I'll try to give that a shot once I read up a bit more on cURL and how exactly it works. Much appreciated though. Link to comment https://forums.phpfreaks.com/topic/160494-login-form-from-aspx-to-php-help/#findComment-847053 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.