handoyo Posted May 15, 2009 Share Posted May 15, 2009 Hi all...I'm trying to make an error display on the register.php when the user hasn't enter valid data by proccesing it to proses.php..I've made it by using session..But i was unable to destroy the session suppose the user doesn't want to register and they go back to the index.php by using the browser back button...What should i do so the session can be cleared suppose the user came back to the register.php?I've tried the unset() and it's not working...Here are the codes that i've made...Thanks a lot... register.php /error_reporting(0); session_start(); include 'output_fns.php'; $thisPage="Index"; include 'include/navigation.php'; do_kepala('Register'); $prop=$_SESSION["id_prop"]; $tgl_pil=$_SESSION["id_tgl"]; $bln_pil=$_SESSION["id_bln"]; ?> <div id="styled" class="myform"> <form id="form1" name="form1" method="post" action="proses.php"> <fieldset> <legend >Data keanggotaan</legend> <br> <label>Email anda : <span class="small">Untuk login</span> </label> <input type="text" name="email" id="email" value="<?php echo $fields['email']; ?>"> <span class="error"> <?php echo $Error['email']; ?> <?php echo $Error['daftar']; ?> </span> <div class="spacer"></div> <label>Password : <span class="small">6-12 karakter</span> </label> <input type="password" name="pwd1" id="pwd1" ?> <span class="error"> <?php echo $Error['pwd1']; ?> </span> <div class="spacer"></div> <label>Ulangi Password : </label> <input type="password" name="pwd2" id="pwd2" /> <span class="error"> <?php echo $Error['pwd2']; ?> </span> <div class="spacer"></div> </fieldset> <fieldset> <legend>Data pribadi</legend> <br> <h1> * Mohon diisi dengan data yang sebenarnya</h1> <div class="spacer"></div> <br> <label>*Nama lengkap anda : <span class="small">Mohon nama asli anda</span> </label> <input type="text" name="nama" id="nama" value="<?php echo $nama; ?>"/> <span class="error"> <?php echo $Error['nama']; ?> </span> <div class="spacer"></div> <label>*Tempat lahir anda : <span class="small"></span> </label> <input type="text" name="tempat_lahir" id="tempat_lahir" value="<?php echo $tmpt; ?>"/> <div class="spacer"></div> <label for="tgl">*Tanggal lahir <span class="small">dd/mm/yyyy</span> </label> <select name="tgl" id="tgl"> <?php //ambil id dari table propinsi buat ditaruh di option propinsi $usertgl=$tgl_pil; $handle=db_connect(); $ambil="Select * from tgl"; $result=$handle->query($ambil); while($row=$result->fetch_array()) { if ($row['id'] == $usertgl) { echo '<option value="'.$row['id'].'" selected="selected">'.$row['tgl'].'</option>'; } else { echo '<option value="'.$row['id'].'">'.$row['tgl'].'</option>'; } } ?> </select> <label for="bln"></label><select name="bln" id="bln"> <option value="1" selected="selected">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> </select> <label for="thn"></label> <input type="text" name="thn" id="thn" style="float:left; font-size:12px; padding:5px 0px; border:solid 1px #aacfe4; width:55px; margin:2px 0 10px 8px;" value="<?php echo $thn?>"/> <div class="spacer"></div> <label>Jenis Kelamin <span class="small">Jenis kelamin anda</span> </label> <select name="jekel"> <option value="Pilih" selected="selected">Pilih salah satu... </option> <option value="pria" id="jekel">Pria</option> <option value="wanita" id="jekel">Wanita</option> </select> <div class="spacer"></div> <label>*Alamat : <span class="small">Alamat lengkap anda</span> </label> <input type="text" name="alamat" id="alamat" value="<?php echo $alamat; ?>"/> <div class="spacer"></div> <label>*Kota : <span class="small">Kota anda</span> </label> <input type="text" name="kota" id="kota" value="<?php echo $kota; ?>"/> <div class="spacer"></div> <label>*Propinsi : <span class="small">Propinsi anda</span> </label> <select name="propinsi"> <?php //ambil id dari table propinsi buat ditaruh di option propinsi $userprop=$prop; $handle=db_connect(); $ambil="Select * from propinsi"; $result=$handle->query($ambil); while($row=$result->fetch_array()) { if ($row['id'] == $userprop) { echo '<option value="'.$row['id'].'" selected="selected">'.$row['prop'].'</option>'; } else { echo '<option value="'.$row['id'].'">'.$row['prop'].'</option>'; } } ?> </select> </fieldset> <br> <button type="submit" name="submit">Sign-up</button> </form> </div> ?> proses.php session_start(); include 'class/class.all.php'; $Error = array(); $fields = array(); //if(isset($_POST['submit'])) // { //$email=$_POST['email']; $email=$_REQUEST['email']; $fields['email']=$email; if(empty($email)) { $Error['email']='Email tidak boleh kosong'; } else if (!strchr($email, '@')) { $Error['email']='Email yang anda masukkan tidak valid'; } $pwd1=$_REQUEST['pwd1']; if(empty($pwd1)) { $Error['pwd1']='Password 1 tidak boleh kosong'; } $pwd2=$_REQUEST['pwd2']; if(empty($pwd2)) { $Error['pwd2']='Password 2 tidak boleh kosong'; } else if($pwd1 != $pwd2) { $Error['pwd2']='Password harus cocok'; } $nama=$_REQUEST['nama']; if(empty($nama)) { $Error['nama']='Nama tidak boleh kosong'; } $pwd=$pwd1; $tmpt=$_REQUEST['tempat_lahir']; $tgl=$_REQUEST['tgl']; $bln=$_REQUEST['bln']; $thn=$_REQUEST['thn']; $tgl_lahir=$tgl.'-'.$bln.'-'.$thn; $jekel=$_REQUEST['jekel']; $alamat=$_REQUEST['alamat']; $kota=$_REQUEST['kota']; $propinsi=$_REQUEST['propinsi']; //if (!empty($Error)) if (count($Error)>0) { $_SESSION["errors"]=$Error; $_SESSION["fields"]=$fields; $_SESSION["id_prop"]=$propinsi; $_SESSION["id_tgl"]=$tgl; $_SESSION["id_bln"]=$bln; //header('Refresh: 2; url=http://'.$_SERVER['HTTP_HOST'].'/rekandoa/register.php'); //echo 'ada yang salah'; header('location:register.php'); } else { unset($_SESSION["errors"]); unset($_SESSION["fields"]); unset($_SESSION["id_prop"]); unset($_SESSION["id_tgl"]); unset($_SESSION["id_bln"]); session_destroy(); //class class.auth.php $adduser=new auth(); //cek email $cek=$adduser->CekEmail($email); if ($cek) { $Error['daftar']='Email yang anda masukkan sudah terdaftar'; $_SESSION["errors"]=$Error; header('location:register.php'); } else { //panggil fungsi adduser yg ada di class class.auth.php $add=$adduser->adduser($email,$pwd,$nama,$tmpt,$tgl_lahir,$jekel,$alamat,$kota,$propinsi); if ($add==1) { header('location:thanks.php'); } else { } } } // } ?> Quote Link to comment https://forums.phpfreaks.com/topic/158277-destroy-session/ Share on other sites More sharing options...
JonnoTheDev Posted May 15, 2009 Share Posted May 15, 2009 Why are you even using sessions for a registration form? Quote Link to comment https://forums.phpfreaks.com/topic/158277-destroy-session/#findComment-834873 Share on other sites More sharing options...
handoyo Posted May 16, 2009 Author Share Posted May 16, 2009 I'm using it to hold the errors..Could you help me please?Thanks a lot... Quote Link to comment https://forums.phpfreaks.com/topic/158277-destroy-session/#findComment-835105 Share on other sites More sharing options...
Masna Posted May 16, 2009 Share Posted May 16, 2009 After all of your session unsets, you still have session_destroy(). Get rid of that, and it should work. Quote Link to comment https://forums.phpfreaks.com/topic/158277-destroy-session/#findComment-835134 Share on other sites More sharing options...
handoyo Posted May 17, 2009 Author Share Posted May 17, 2009 Do you mean the session_destroy() at proses.php?Thanks... Quote Link to comment https://forums.phpfreaks.com/topic/158277-destroy-session/#findComment-835676 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.