CariDotMy

 Forgot password?
 Register

ADVERTISEMENT

View: 2667|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
...BYE 2024, HELLO 2025...
seribulan...BYE 2024, HELLO 2025...
Views : 54993 Replies : 13
...AZAM TAHUN 2025...
seribulan...AZAM TAHUN 2025...
Views : 55522 Replies : 25
[Netflix 2021] SQUID GAME Season 1,2,3 - Lee Jung Jae, Lee Byung Hun, Wi Ha Joon, Gong Yoo ~ 26 Dec 2024 (Season 2), 2025 (Final Season)
Rahah[Netflix 2021] SQUID GAME Season 1,2,3 -
Views : 29125 Replies : 254
...CHAT HUMANITARY...HAPPY NEW YEAR...
seribulan...CHAT HUMANITARY...HAPPY NEW YEAR...
Views : 44248 Replies : 29
V82: HANIS HAIZI B. ABD HAMID Melarikan Diri Dari Bayar Cukai LHDN Ke Los Angeles CA
anony-mousV82: HANIS HAIZI B. ABD HAMID Melarikan
Views : 11125 Replies : 449
New Chapter 01: FATTAH AMIN ~ Bebaskanlah mimpi-mimpi terindah
codenamedreamNew Chapter 01: FATTAH AMIN ~ Bebaskanla
Views : 47200 Replies : 1958
siri ikonik Korea, Squid Game 2 ditayangkan di Neflix hari ini
YgBenarsiri ikonik Korea, Squid Game 2 ditayang
Views : 13087 Replies : 5
Instafamous Rempit (kak yah, kak zah & the geng) part 3
hotmakInstafamous Rempit (kak yah, kak zah & t
Views : 232317 Replies : 1832
madu gula tok matahari
aaanf14madu gula tok matahari
Views : 109982 Replies : 1152
Acikpor vs. Ngai, isu tajaan MARA dikorek
maklukpenggodaAcikpor vs. Ngai, isu tajaan MARA dikore
Views : 52274 Replies : 1477

 

ADVERTISEMENT


 


ADVERTISEMENT
Follow Us

ADVERTISEMENT


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

28-12-2024 08:33 AM GMT+8 , Processed in 0.449817 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