janim Posted December 14, 2007 Share Posted December 14, 2007 hi all i have session called name : $myname=$_session['name']; already stored but why it changes i have page showing books so when i open this page the session changes to the name of the book why this happens and this happens just in my server but in localhost everything ok why it would change ? thanx Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 14, 2007 Share Posted December 14, 2007 Post your script please, so we can examine it. Quote Link to comment Share on other sites More sharing options...
janim Posted December 14, 2007 Author Share Posted December 14, 2007 sorry phpSensei i can't post all the code it's little big and going between the html code so it's like that in general : <?php // for the login page : $name = $_POST['myname']; $_SESSION['login']=true; $_SESSION['name']=$name; ?> then i check for lgin or not : <?php $check = $_SESSION['name']; echo "Welcome back ".$check."<br>"; echo "<a href=\"profile.php?name={$check}\">My profile</a>"; ?> so in my local host it's work good but in my server it's change the session name to the book name in that's page the book name is comming from mysql like this : <?php $new=mysql_db_query($b,"select * from $books where id='$id'") or die ("".mysql_error()); if(mysql_num_rows($new)){ $q=mysql_fetch_array($new); $name=$q[bookname]; } ?> so what is the problem ??? why my session name changes to the book name ? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 14, 2007 Share Posted December 14, 2007 The reason why the $_SESSION['name'] is getting changed when $name=$q[bookname]; is executed is because register globals are ON and the $name variable is the same as $_SESSION['name']. You need to use unique variable names when register globals are on. You should also turn off register globals. Quote Link to comment Share on other sites More sharing options...
janim Posted December 14, 2007 Author Share Posted December 14, 2007 thank you PFMaBiSmAd i changed every thing and it works now but how i can know more about session and global variables ? thank you again Quote Link to comment 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.