Tolong pilih kategori sesuai, jenis posting (diskusi atau bukan) dan sertakan tag/topik yang sesuai seperti komputer, java, php, mysql, dll. Promosi atau posting tidak pada tempatnya akan kami hapus!
- Bagi Anda yang ingin mendaftar, baca link berikut:
http://diskusiweb.com/discussion/50491/how-to-registrasi-diskusiweb-com-baca-ini-terlebih-dahulu
- Cara menyisipkan kode program supaya tampil rapi dan terformat dengan baik di diskusiweb.com: http://www.diskusiweb.com/discussion/50415/cara-menyisipkan-kode-program-di-diskusiweb-com
- Cara posting gambar/image di post Anda: http://www.diskusiweb.com/discussion/47345/cara-menyisipkan-menyertakan-image-pada-posting/p1

Fungsi header location gak jalan

<?php
$username = $_POST["username"];
$password = $_POST["password"];
if ($username == "admin" && $password == "tes"){
header("Location:loginok.php");
}else{
echo "Login Gagal!!";
}
?>

gak bisa muncul


Warning: Cannot modify header information - headers already sent by (output started at D:\xampp\htdocs\login\index.php:8) in D:\xampp\htdocs\login\index.php on line 12

kenapa ya??? tolong donk
Tagged:

Comments

  • edited January 2011
    Coba hapus<div class='geshi_syntax'><table><tr><td><div class='code'><pre class="html"><br /></pre></div></td></tr></table></div> nya tuh, kalo nampilin header itu bisanya sebelum ada output/konten lain kang. Jadi ga bisa nampilin tag HTML sebelum header
  • hapus apanya???
  • Coba cek komen saya lagi :D
  • udah ... tetep gak jalan...
  • Coba dilampirin kode lengkapnya deh trus jelasin itu error terjadi saat apa? Saat diakses atau saat posting form? Utk lampirin kode php di sini diawali dengan tag<div class='geshi_syntax'><table><tr><td><div class='code'><pre class="html"><pre lang="php">Kode PHPmu</pre></div></td></tr></table></div> </pre> kemudian tutup dengan tag pre lagi biar kode phpnya enak dibaca
  • <div class='geshi_syntax'><table><tr><td><div class='code'><pre class="php"><span class="kw2"><?php</span>
    <span class="re0">$username</span> <span class="sy0">=</span> <span class="re0">$_POST</span><span class="br0">[</span><span class="st0">"username"</span><span class="br0">]</span><span class="sy0">;</span>
    <span class="re0">$password</span> <span class="sy0">=</span> <span class="re0">$_POST</span><span class="br0">[</span><span class="st0">"password"</span><span class="br0">]</span><span class="sy0">;</span>
    <span class="kw1">if</span> <span class="br0">(</span><span class="re0">$username</span> <span class="sy0">==</span> <span class="st0">"admin"</span> <span class="sy0">&&</span> <span class="re0">$password</span> <span class="sy0">==</span> <span class="st0">"tes"</span><span class="br0">)</span><span class="br0">{</span>
    <span class="kw3">header</span><span class="br0">(</span><span class="st0">"location:loginok.php"</span><span class="br0">)</span><span class="sy0">;</span>
    <span class="br0">}</span><span class="kw1">else</span><span class="br0">{</span><span class="kw1">echo</span> <span class="st0">"Login Gagal"</span><span class="sy0">;</span>
    <span class="br0">}</span>
    <span class="sy1">?></span></pre></div></td></tr></table></div>
  • Ubah kodenya jadi:<div class='geshi_syntax'><table><tr><td><div class='code'><pre class="php"> 
    <span class="kw2"><?php</span>
     
    <span class="re0">$username</span> <span class="sy0">=</span> <span class="kw3">isset</span><span class="br0">(</span><span class="re0">$_POST</span><span class="br0">[</span><span class="st0">"username"</span><span class="br0">]</span><span class="br0">)</span>?<span class="re0">$_POST</span><span class="br0">[</span><span class="st0">"username"</span><span class="br0">]</span><span class="sy0">:</span><span class="st0">""</span><span class="sy0">;</span>
     
    <span class="re0">$password</span> <span class="sy0">=</span> <span class="kw3">isset</span><span class="br0">(</span><span class="re0">$_POST</span><span class="br0">[</span><span class="st0">"password"</span><span class="br0">]</span><span class="br0">)</span>?<span class="re0">$_POST</span><span class="br0">[</span><span class="st0">"passwod"</span><span class="br0">]</span><span class="sy0">:</span><span class="st0">""</span><span class="sy0">;</span>
     
    <span class="kw1">if</span> <span class="br0">(</span><span class="re0">$username</span> <span class="sy0">==</span> <span class="st0">"admin"</span> <span class="sy0">&&</span> <span class="re0">$password</span> <span class="sy0">==</span> <span class="st0">"tes"</span><span class="br0">)</span><span class="br0">{</span>
     
    <span class="kw3">header</span><span class="br0">(</span><span class="st0">"location:loginok.php"</span><span class="br0">)</span><span class="sy0">;</span>
     
    <span class="br0">}</span><span class="kw1">else</span><span class="br0">{</span><span class="kw1">echo</span> <span class="st0">"Login Gagal"</span><span class="sy0">;</span>
     
    <span class="br0">}</span>
     
    <span class="sy1">?></span></pre></div></td></tr></table></div>
  • yakin selain skrip diatas ga da output apa-apa?
  • edited January 2011
    D:\xampp\htdocs\login\index.php di baris 8 ... ada apa di situ?
  • @ issec dah tetep gak bisa...
    @skatel cuman itu aja....

    sekedar tambahan anehnya pas ntu halaman baru dibuka dah ada tulisan "Login Gagal" duluan
  • Mungkin ada diinclude kan kali ke halaman lain?
  • deded1989 wrote:
    @skatel cuman itu aja....

    sekedar tambahan anehnya pas ntu halaman baru dibuka dah ada tulisan "Login Gagal" duluan

    iya kalo memang diakses langsung memang dianggap login gagal karena kedua variable itu kosong. Tamabahkan aja kondisi<div class='geshi_syntax'><table><tr><td><div class='code'><pre class="php"><span class="kw2"><?php</span>
    <span class="kw1">if</span> <span class="br0">(</span><span class="re0">$_POST</span><span class="br0">)</span> <span class="br0">{</span>
    <span class="coMULTI">/* proses login disini */</span>
    <span class="br0">}</span></pre></div></td></tr></table></div>
  • Cape deh, itu mah bener kalo dibuka ada tulisan "Login Gagal". Logikanya kan begitu?
    Makanya tadi saya tanya itu error header output itu terjadi saat kapan?

    Sepertinya kamu memang perlu tambah if nya lagi yaitu if username=="" dan password=="" itu utk nampilin html utk login formnya. jadi ga keliatan login gagal
    kemudian else terakhirnya utk tampilin "Login gagal" itu bila username!="admin" and password!=tes
  • dibaris ke 8 cuman ada <?php doang gak ada karakter lain.....
    @goku gak ada perintah include
  • Kali aja diincludekan ke halaman lain?
  • dah saya ganti jadi gini<div class='geshi_syntax'><table><tr><td><div class='code'><pre class="php"><span class="kw2"><?php</span>
    <span class="kw1">if</span> <span class="br0">(</span><span class="re0">$_POST</span><span class="br0">)</span><span class="br0">{</span>
    <span class="re0">$username</span> <span class="sy0">=</span> <span class="re0">$_POST</span><span class="br0">[</span><span class="st0">"username"</span><span class="br0">]</span><span class="sy0">;</span>
    <span class="re0">$password</span> <span class="sy0">=</span> <span class="re0">$_POST</span><span class="br0">[</span><span class="st0">"password"</span><span class="br0">]</span><span class="sy0">;</span>
    <span class="kw1">if</span> <span class="br0">(</span><span class="re0">$username</span> <span class="sy0">==</span> <span class="st0">"admin"</span> <span class="sy0">&&</span> <span class="re0">$password</span> <span class="sy0">==</span> <span class="st0">"tes"</span><span class="br0">)</span><span class="br0">{</span>
    <span class="kw3">header</span><span class="br0">(</span><span class="st0">"location:loginok.php"</span><span class="br0">)</span><span class="sy0">;</span>
    <span class="br0">}</span><span class="kw1">else</span><span class="br0">{</span><span class="kw1">echo</span> <span class="st0">"Login Gagal"</span><span class="sy0">;</span>
    <span class="br0">}</span><span class="br0">}</span>
    <span class="sy1">?></span></pre></div></td></tr></table></div>

    gak muncul login gagal duluan lagi tapi tetep gak bisa....
  • Formnya kayak apa? Lalu actionnya ke file diatas?
  • edited January 2011
    mungkin ada spasi sebelum "<? php"

    "<? php" nya harus benar2 di awal file
  • <div class='geshi_syntax'><table><tr><td><div class='code'><pre class=""><html>
    <head>
    <title>Login</title>
    </head>
     
    <body>
    <?php
    if <span class="br0">(</span>$_POST<span class="br0">)</span><span class="br0">{</span>
    $username = $_POST<span class="br0">[</span>"username"<span class="br0">]</span>;
    $password = $_POST<span class="br0">[</span>"password"<span class="br0">]</span>;
    if <span class="br0">(</span>$username == "admin" && $password == "tes"<span class="br0">)</span><span class="br0">{</span>
    header<span class="br0">(</span>"location:loginok.php"<span class="br0">)</span>;
    <span class="br0">}</span>else<span class="br0">{</span>echo "Login Gagal";
    <span class="br0">}</span><span class="br0">}</span>
    ?>
    <form name="form1" method="post" action="">
    <p align="center">Username
    <label>
    <input name="username" type="text">
    </label>
    </p>
    <p align="center">Password
    <label>
    <input name="password" type="password">
    </label>
    </p>
    <p align="center">
    <label>
    <input name="login" type="submit" id="login" value="Login">
    </label>
    <label>
    <input name="cancel" type="reset" id="cancel" value="Cancel">
    </label>
    </p>
     
    </form>
    </body>
    </html></pre></div></td></tr></table></div>

    lengkapnya kayak gini... mohon bantuannya...
  • @all Solved ... tks... atas keramahannya terhdap newbie kayak saya....
  • edited January 2011
    Ya ini ada tag html<div class='geshi_syntax'><table><tr><td><div class='code'><pre class="php"><html>
    <head>
    <title>Login</title>
    ...
    <span class="kw2"><?php</span>
    <span class="kw1">if</span> <span class="br0">(</span><span class="re0">$_POST</span><span class="br0">)</span><span class="br0">{</span>
    <span class="sy0">...</span>
    <span class="kw3">header</span><span class="br0">(</span><span class="st0">"location:loginok.php"</span><span class="br0">)</span><span class="sy0">;</span>
    <span class="sy0">.....</span></pre></div></td></tr></table></div>

    Coba ubah<div class='geshi_syntax'><table><tr><td><div class='code'><pre class="php"><span class="kw2"><?php</span>
    <span class="kw1">if</span> <span class="br0">(</span><span class="re0">$_POST</span><span class="br0">)</span><span class="br0">{</span>
    <span class="re0">$username</span> <span class="sy0">=</span> <span class="re0">$_POST</span><span class="br0">[</span><span class="st0">"username"</span><span class="br0">]</span><span class="sy0">;</span>
    <span class="re0">$password</span> <span class="sy0">=</span> <span class="re0">$_POST</span><span class="br0">[</span><span class="st0">"password"</span><span class="br0">]</span><span class="sy0">;</span>
    <span class="kw1">if</span> <span class="br0">(</span><span class="re0">$username</span> <span class="sy0">==</span> <span class="st0">"admin"</span> <span class="sy0">&&</span> <span class="re0">$password</span> <span class="sy0">==</span> <span class="st0">"tes"</span><span class="br0">)</span><span class="br0">{</span>
    <span class="kw3">header</span><span class="br0">(</span><span class="st0">"location:loginok.php"</span><span class="br0">)</span><span class="sy0">;</span>
    <span class="br0">}</span><span class="kw1">else</span><span class="br0">{</span><span class="kw1">echo</span> <span class="st0">"Login Gagal"</span><span class="sy0">;</span>
    <span class="br0">}</span><span class="br0">}</span>
    <span class="sy1">?></span>
    html
    <head>
    <title>Login</title>
    </head></pre></div></td></tr></table></div>
  • sekalian nanya ahh,...
    klo anggil header tuh g bisa kalo diatasnya ada include,require,dll kan.
    script php buat connect ke databases nya kan aku buat beda file, otomatis pake include,dkk.
    nah itu gmn ya solusinya?? 

  • Coba mas pake script di bawah ini untuk solusi yang lain...mungkin bisa digunakan!!!!
    <?php

    $username = isset($_POST["username"])?$_POST["username"]:"";

    $password = isset($_POST["password"])?$_POST["passwod"]:"";

    if ($username == "admin" && $password == "tes")

    {

    ?>

    <script language="JavaScript">

    location.href="loginok.php";

    </script>

    <?
    }else{echo "Login Gagal";

    }

    ?>
  • sekalian nanya ahh,...
    klo anggil header tuh g bisa kalo diatasnya ada include,require,dll kan.
    script php buat connect ke databases nya kan aku buat beda file, otomatis pake include,dkk.
    nah itu gmn ya solusinya?? 

    setau saya paling enak pake javascript aja.. bener tuh kata mas@harsyad... :-)
  • Kalo engga berfungsi coba pake JAVASCRIPT;

    ubah dari
    header("location:login.php");
    menjadi
    echo ("<script>location.href='login.php'</script>");
  • header() redirection better than <meta> redirection
    <meta> redirection better than javascript redirection

    ada yg bagus kok milih yg di bawah nya
  • saya kbetulan dapet problem sama..
    saya men-include php dalam include ke 3, saya kira gara2 terlalu banyak routing include, ternyata beda
    thanks atwal it works!
    it works !
This discussion has been closed.