簡體   English   中英

如何使用Oracle SQL對PHP用戶登錄進行編碼?

[英]How to code for a PHP user login with Oracle SQL?

好的,讓我首先說我對PHP仍然很菜鳥。 基本上,我正在嘗試設計一個用戶注冊和登錄系統,該系統從Oracle SQL數據庫查詢用戶數據,並且對我有用的唯一教程都是關於MYSQL的。 我想知道是否有人有時間幫助我進行一些PHP編碼以使其正常工作。

任何幫助將不勝感激。

編輯:對不起,我忘了提及,我正在嘗試獲取一個登錄頁面,該頁面設置一個cookie以保持用戶會話直到他們注銷。 我嘗試了幾種不同的變體,但沒有一種能奏效。 我需要它來配合下面的注冊頁面。

目前,我非常確定我的用戶注冊代碼是業余的:

 <?php
 /* Set oracle user login and password info */
  $dbuser = "xxxxxxx";  /* your login */
  $dbpass = "xxxxxx";  /* your password */
  $db = "xxxxx"; 
  $connect = OCILogon($dbuser, $dbpass, $db); 
  $salt = "plants";

  if (!$connect)  {
    echo "An error occurred connecting to the database"; 
    exit; 
  }


  // get the max ID in plants table and allocate $ID+1 for the new record
$max_id_stmt = "SELECT max(ID) FROM register_table";

// check the sql statement for errors and if errors report them
$stmt = OCIParse($connect, $max_id_stmt);
if(!$stmt) {
  echo "An error occurred in parsing the sql string.\n";
  exit;
}
OCIExecute($stmt);
$ID =0;

if(OCIFetch($stmt)) {
  $ID= OCIResult($stmt,1); //return the data from column 1
}else {
  echo "An error occurred in retrieving book id.\n";
  exit;
}
$ID++;


// Extract form data
$username=$_REQUEST['username'];
$password=$_REQUEST['password'];
$email=$_REQUEST['email'];
$phone=$_REQUEST['phone'];
$address=$_REQUEST['address'];
global $salt;


// Create the SQL statement to add the data. Note: field value should be single quoted           
'' if VARCHAR2 type.
$sql = "INSERT INTO register_table VALUES ($ID, '$username', '$password', '$email',             
'$address', '$phone')";
$password = md5($salt.$password);
// Add the data to the database as a new record
$stmt = OCIParse($connect, $sql);
if(!$stmt) {
echo "An error occurred in parsing the sql string.\n";
exit;
}
OCIExecute($stmt);
echo ("<p>Your registration has been successful!</p>
<p>User ID: $ID</P>
<p>Username: $username</p>
<p>Phone: $phone</p>
<p>Address: $address</p>


</p>")


?>

謝謝!

感謝您澄清問題。 我認為您可能將PHP的$ _REQUEST變量與$ _SESSION變量混淆了。 您需要建立一個新會話以維護用戶的會話狀態,這反過來(無論如何,默認情況下)將設置cookie。 您可以使用session_start()或將PHP配置為自動建立新會話,從而使用標准PHP代碼建立新會話。

當然,這樣做不會使當前用戶與您通過上述代碼傳遞給數據庫的注冊數據結婚; 您可以通過將生成的會話ID與該用戶數據相關聯來實現。 我建議看一下PHP文檔的此頁面以快速入門。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM