CariDotMy

 Forgot password?
 Register

ADVERTISEMENT

View: 2668|Reply: 9

tolong php

[Copy link]
ariandy This user has been deleted
Post time 1-8-2006 10:24 AM | Show all posts |Read mode
macamana kita nak buat bila kita login lepas tu page yang seterusnya terus papar nama orang yang log in tu.ade sapa2 leh tlong tak macamana nak buat coding tu
Reply

Use magic Report


ADVERTISEMENT


Post time 1-8-2006 06:38 PM | Show all posts
Banyak cara bleh buat...name yg nk display tu username atau nama penuh yg store dlm database ?? Kalo username...ambik direct dr page yg ade form utk login tu pun bulih...
Reply

Use magic Report

Post time 2-8-2006 10:32 AM | Show all posts
login page:

<?
     session_start(); // wajib ada, mesti di line pertama

    ... login functions
    ... if login ok then:

    $_SESSION["username"] = "<username yang nak papar>";
    ...
    ...

?>


page-page lain:
<?

   session_start(); // wajib ada, mesti di line pertama
   ...
   echo ($_SESSION["username"]); // untuk papar kembali user name yang tadi
   ...
   ...
?>
Reply

Use magic Report

ariandy This user has been deleted
 Author| Post time 4-8-2006 08:41 AM | Show all posts

tak tahu le

leh tak tunjuk coding yang penuh shanaz.
ini coding Loginprocess saya



<?PHP
   
if ((empty($username))||(empty($password)))
{
   die ("Please fill in username and password");
}
      
  $connect=mysql_connect('localhost');
  mysql_select_db('Fis');
  $SQLcommand = "SELECT * FROM daftar WHERE Katanama = '$username'";
  $result = mysql_query($SQLcommand, $connect);

  while($row = mysql_fetch_array($result))
  {
      $tmpUserName = $row["Katanama"];
      $tmpPassword = $row["Katalaluan"];
      
  }


if (!(($username==$tmpUserName)&&($password==$tmpPassword)))       
{
   echo "<h1>Wrong username and password!</h1>";
}
else
{
   session_start();
   session_register("username");
   session_encode();
   $url = "Location: home1.php?PHPSESSID=".$PHPSESSID;
   header($url);
   
}

?>

lepas login dia pi kepage seterusnya.lepas tu nama dipapar disitu.so coding tu nak letak dimana
Reply

Use magic Report

Post time 4-8-2006 10:01 AM | Show all posts

Reply #4 ariandy's post

My comments:

1. session_start() hanya boleh diletak di permulaan setiap page PHP (first PHP code in a PHP file). Tak berguna kalau dia di-embed di tengah-tengah PHP code.

2. I am assuming $username and $password values are taken from $_REQUEST (or $_GET / $_POST) arrays, depending on which version of PHP you are using.

3. Your SQL statement can be optimised. Instead of just setting the criteria for username, you can include the password in as well. Like so:


  1. $SQLCommand = "select * from daftar where katanama = '$username' and katalaluan = '$password';
Copy the Code


That way, the $row variable can be implemented as follows:


  1. $SQLCommand = ...;
  2. $result = mysql_query($SQLCommand);
  3. $row = mysql_fetch_array($result);

  4. if ($row == null || $row == "") {
  5.    echo ("Wrong username or password");
  6. }
  7. else {
  8.   // ... baca bahagian seterusnya ..
  9. }
Copy the Code


That way u save a few lines of code already.

4. Untuk redirect ke next page, saya tipu PHP into breaking into HTML. Set the session variable. Then in the next page just display the session variable. Code as follows:


  1. //(loginprocess.php - sambung code yang di atas)

  2. if ($row == null || $row = "") {
  3.    echo ("Wrong username or password");
  4. }
  5. else {
  6.    $_SESSION["username"] = $username; // set a new session variable
  7.    // ni trick saya guna untuk redirect to next page (tak tau efficient ke idak)

  8.    // breaking out of PHP   
  9.    ?>
  10.     <!-- in HTML -->
  11.     <meta http-equiv="refresh" content="0;url=home1.php">

  12.     <?
  13.     // back to PHP
  14. }

  15. //(home1.php)
  16. <?
  17.     session_start();
  18.     // if a session has been started in the preceding page,
  19.     // it continues the session, else it creates a new session. That's why
  20.     // it is required in the first line of every PHP page

  21.     // now check whether the session variable username is defined or not
  22.     if (isset($_SESSION["username"])) {
  23.         echo ("Welcome, " . $_SESSION["username"]);
  24.     }
  25.     else {
  26.         echo ("Your session has expired. Please try again.");
  27.     }

  28. ?>
Copy the Code


Harap dapat membantu.

[ Last edited by  shahnazz at 4-8-2006 10:04 AM ]
Reply

Use magic Report

ariandy This user has been deleted
 Author| Post time 4-8-2006 11:14 AM | Show all posts

tak jadi le

shahnaz tak jadi la.dia hanya dapat display satu nama sahaja lepas tu ada error
kasi email saya hantar full sistem untuk anda tengok.tolong ini projek praktikal saya
Reply

Use magic Report

Follow Us
Post time 4-8-2006 12:22 PM | Show all posts
saya dah hantar PM. nanti reply ye.
Reply

Use magic Report

slier This user has been deleted
Post time 10-9-2006 07:15 PM | Show all posts
huh...aku baru nak tunjul skill....
baru tengok shannaz explain aku dah penin....
apsal aku buat session senang jer.....
Reply

Use magic Report


ADVERTISEMENT


Post time 11-9-2006 10:14 AM | Show all posts
tunjuk la :bgrin:

tiap programmer ada skill-skill yang berbeza... at least boleh compare programiming styles...
Reply

Use magic Report

Post time 11-9-2006 11:17 AM | Show all posts
aku selalu wat session guna wizard jer hahaha..pemalas..
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

 

ADVERTISEMENT


Forum Hot Topic

 

ADVERTISEMENT


 


ADVERTISEMENT
Follow Us

ADVERTISEMENT


Mobile|Archiver|Mobile*default|About Us|CariDotMy

29-12-2024 12:30 AM GMT+8 , Processed in 0.157419 second(s), 24 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

Quick Reply To Top Return to the list