pass information from one session to another

pass information from one sesion to anaver

Page 1 of 1

2 Replies - 2208 Views - Last Post: 14 May 2009 - 04:24 AM Rate Topic: -----

#1 Bildukas   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 14-May 09

pass information from one session to another

Posted 14 May 2009 - 04:07 AM

i need help passing information to start session whit mysql

I have this php script that check identity of the user then he tipe Login and Password
this one is cheklogin.php and it working perfect ! now i need from here pass "User name" to other php members.php its below this code ....
<?php
$host="localhost"; // Host name
$username="test;
$password="test";
$db_name="test_informacija"; // Database name
$tbl_name="Informacija"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE Vartotojas='$myusername' and Slaptazodis='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:members.php?var_name=$myusername");
}
else {
echo "Wrong Username or Password";
}
mysql_close();
?> 


and here i need to get his user name what his enter before then i use header whit _Get command its work fine but its unsecured becouse you can change name in the address bar and you will get other user account its realy bad

i wanna try send buy cookies but i don't know how to do it some can post where i must start session and end session
i know i must set
<?php
setcookie("user", "name", time()+3600);
?>
and then get them back but where i must put that code and where i must put $myusername in the code
i try some some combinations and i get errors

<?
session_start();
if(!session_is_registered(myusername)){
header("location:index.php");
}
?>



<html>
<body>
<?
$passed_value = $_GET['var_name'];

echo "HELLO ".$passed_value;
echo "<br>"
?>
Login Successful <a href="logout.php">log out
</a>
</body>
</html>

This post has been edited by Bildukas: 14 May 2009 - 04:09 AM


Is This A Good Question/Topic? 0
  • +

Replies To: pass information from one session to another

#2 noorahmad   User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: pass information from one session to another

Posted 14 May 2009 - 04:15 AM

if(!isset($_SESSION))
{
session_start();

$_SESSION['a']=$_SESSION['x'];
}


Was This Post Helpful? 0
  • +
  • -

#3 Bildukas   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 14-May 09

Re: pass information from one session to another

Posted 14 May 2009 - 04:24 AM

ok i found :D how its work
i just put new code
for start cookie
<?php
$myusername=$_POST['myusername'];
setcookie("user", "$myusername", time()+3600);
?>


and in next page for get them

<?php
echo $_COOKIE["user"];
?> 


so problem solved :) no need to use get and its secured i think :P
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1