Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

need help with session

session

  • Please log in to reply
5 replies to this topic

#1 yonghan

yonghan

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 103 posts

Posted 14 May 2009 - 07:28 AM

Hi all,i need help with unset session..I got the code below

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>
?>


prosess.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
{
}
}

}
// }

?>


When the user register,it will go to proses.php..If there are errors,it will go back to register.php and show the errors using session..How to unset the session suppose the user go back to the index.php?Thanks a lot....
  • 0

#2 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 14 May 2009 - 08:43 AM

session_destroy() removes the session... so just destroy it if your conditions for not have done it properly are met...
  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#3 yonghan

yonghan

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 103 posts

Posted 14 May 2009 - 08:14 PM

Where should i put it??Thanks...
  • 0

#4 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 15 May 2009 - 05:13 AM

where you need to destroy it, simply.
I guess in this case, you would probably destroy the session in top of index.php if user is not registered.
  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#5 yonghan

yonghan

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 103 posts

Posted 15 May 2009 - 05:46 AM

Then i should use session_start() first?
  • 0

#6 yonghan

yonghan

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 103 posts

Posted 15 May 2009 - 05:52 AM

Here what i'm trying to do suppose my first post was not clear enough...I'm trying to make an error display when the user hasn't enter valid data..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?I've tried the unset()...Thanks...
  • 0





Also tagged with one or more of these keywords: session

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download