dgnzcn Posted August 14, 2010 Share Posted August 14, 2010 i have got the A table. and i want get from data this table to session. how can I ? Quote Link to comment https://forums.phpfreaks.com/topic/210737-from-table-to-session-how-to/ Share on other sites More sharing options...
dgnzcn Posted August 14, 2010 Author Share Posted August 14, 2010 finally i do like this : <?php session_start(); $_SESSION['session_kullanici']=$row_ILAN['session_kullanici']; ?> <?php if($_SESSION['_login_id'] != $_SESSION['session_kullanici']echo "<script>window.location='index.php'</script>"; exit();}?> l what is wrong ? Quote Link to comment https://forums.phpfreaks.com/topic/210737-from-table-to-session-how-to/#findComment-1099319 Share on other sites More sharing options...
Skewled Posted August 14, 2010 Share Posted August 14, 2010 Let's check to find out of the session is getting set: if (!isset($_SESSION['session_kullanici'])) { if($_SESSION['_login_id'] != $_SESSION['session_kullanici']echo "<script>window.location='index.php'</script>"; exit(); } else { echo "Unable to set the SESSION."; } } Quote Link to comment https://forums.phpfreaks.com/topic/210737-from-table-to-session-how-to/#findComment-1099325 Share on other sites More sharing options...
dgnzcn Posted August 14, 2010 Author Share Posted August 14, 2010 thanks, but some errors.. Parse error: syntax error, unexpected T_ECHO in F:\sank\WEB\vidman\ilan_edit.php on line 8 if (!isset($_SESSION['session_kullanici'])) // line 7 if($_SESSION['_login_id'] != $_SESSION['session_kullanici']echo "<script>window.location='index.php'</script>"; // line 8 exit(); // line 9 } else { // line 10 echo "Unable to set the SESSION."; } } Quote Link to comment https://forums.phpfreaks.com/topic/210737-from-table-to-session-how-to/#findComment-1099327 Share on other sites More sharing options...
Skewled Posted August 14, 2010 Share Posted August 14, 2010 I forgot the { after )) on the first line... lol Quote Link to comment https://forums.phpfreaks.com/topic/210737-from-table-to-session-how-to/#findComment-1099328 Share on other sites More sharing options...
dgnzcn Posted August 14, 2010 Author Share Posted August 14, 2010 ok I edit but, but still same error if (!isset($_SESSION['session_kullanici'])) { if($_SESSION['_login_id'] != $_SESSION['session_kullanici']echo "<script>window.location='index.php'</script>"; exit(); } else { echo "Unable to set the SESSION."; } } Quote Link to comment https://forums.phpfreaks.com/topic/210737-from-table-to-session-how-to/#findComment-1099331 Share on other sites More sharing options...
Skewled Posted August 14, 2010 Share Posted August 14, 2010 Sorry I'm getting sleepy here.. if (!isset($_SESSION['session_kullanici'])) { if($_SESSION['_login_id'] != $_SESSION['session_kullanici']) { echo "<script>window.location='index.php'</script>"; exit(); } else { echo "Unable to set the SESSION."; } } Quote Link to comment https://forums.phpfreaks.com/topic/210737-from-table-to-session-how-to/#findComment-1099336 Share on other sites More sharing options...
dgnzcn Posted August 14, 2010 Author Share Posted August 14, 2010 thanks, no problem.. I wanna add to session of $row_ILAN['session_kullanici'] table.. is this wrong ? = $_SESSION['session_kullanici']=$row_ILAN['session_kullanici']; Quote Link to comment https://forums.phpfreaks.com/topic/210737-from-table-to-session-how-to/#findComment-1099341 Share on other sites More sharing options...
Skewled Posted August 14, 2010 Share Posted August 14, 2010 Are you querying for that information before setting the session to that? What was the result of the code above? Did it post the error message? Quote Link to comment https://forums.phpfreaks.com/topic/210737-from-table-to-session-how-to/#findComment-1099344 Share on other sites More sharing options...
dgnzcn Posted August 14, 2010 Author Share Posted August 14, 2010 yes ı Querying like this, and there is no error.. mysql_select_db($database_vman, $vman); $query_ILAN= "SELECT `session_kullanici` FROM ILAN"; $ILAN= mysql_query($query_ILAN, $vman) or die(mysql_error()); $row_ILAN= mysql_fetch_assoc($ILAN); $totalRows_ILAN= mysql_num_rows($ILAN); I wanna save 'session_kullanici' to $_SESSION. But, If '_login_id' and 'session_kullanici' SESSIONS VALUES is different it wil go to index.php. like this = <?php if($_SESSION['_login_id'] != $_SESSION['session_kullanici']echo "<script>window.location='index.php'</script>"; exit();}?> Quote Link to comment https://forums.phpfreaks.com/topic/210737-from-table-to-session-how-to/#findComment-1099347 Share on other sites More sharing options...
Skewled Posted August 14, 2010 Share Posted August 14, 2010 <?php if($_SESSION['_login_id'] != $_SESSION['session_kullanici']) { echo "<script>window.location='index.php'</script>"; } else { echo 'Sorry but the session died.'; exit(); } ?> Where does $_SESSION['_login_id'] get set? Your query looks ok to me, and setting the variable to the session looks fine. Also at the top of your script after the <?php opening tag place: error_reporting(E_ALL); Give that a go.. and it may spit out what the issue is. Quote Link to comment https://forums.phpfreaks.com/topic/210737-from-table-to-session-how-to/#findComment-1099353 Share on other sites More sharing options...
Skewled Posted August 14, 2010 Share Posted August 14, 2010 Also just noticed your edit so with that in mind: <?php header("Cache-Control: no-cache"); session_start(); if($_SESSION['_login_id'] != $_SESSION['session_kullanici']) { header('Location: /pathtoindex.php here'); } else { echo 'Sorry but the session died.'; exit(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/210737-from-table-to-session-how-to/#findComment-1099354 Share on other sites More sharing options...
dgnzcn Posted August 14, 2010 Author Share Posted August 14, 2010 Notice: Undefined variable: row_ILAN in F:\sank\WEB\viman\ilan.php on line 4 <? error_reporting(E_ALL); ?> <?php $_SESSION['session_kullanici']=$row_ILAN['session_kullanici']; // LINE 4 if($_SESSION['_login_id'] != $_SESSION['session_kullanici']) { echo "<script>window.location=''</script>"; } else { echo 'Sorry but the session died.'; exit(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/210737-from-table-to-session-how-to/#findComment-1099359 Share on other sites More sharing options...
Skewled Posted August 14, 2010 Share Posted August 14, 2010 Is the query in the same script as the one I posted? If it's not that would make sense, if it is then the query is failing for some reason. Quote Link to comment https://forums.phpfreaks.com/topic/210737-from-table-to-session-how-to/#findComment-1099369 Share on other sites More sharing options...
Skewled Posted August 14, 2010 Share Posted August 14, 2010 I'm working with portions of the scripts your show, but I image your script looks like the one below? <php // Check for any developmental errors error_reporting(E_ALL); // Query the database to assign a variable to $_SESSION mysql_select_db($database_vman, $vman); $query_ILAN= "SELECT `session_kullanici` FROM ILAN"; $ILAN= mysql_query($query_ILAN, $vman) or die(mysql_error()); $row_ILAN= mysql_fetch_array($ILAN); $totalRows_ILAN= mysql_num_rows($ILAN); $_SESSION['session_kullanici']=$row_ILAN['session_kullanici']; if($_SESSION['_login_id'] != $_SESSION['session_kullanici']) { $home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/index.php'; header('Location: ' . $home_url); } else { echo 'Sorry but the session died.'; exit(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/210737-from-table-to-session-how-to/#findComment-1099372 Share on other sites More sharing options...
dgnzcn Posted August 14, 2010 Author Share Posted August 14, 2010 I am not understand Quote Link to comment https://forums.phpfreaks.com/topic/210737-from-table-to-session-how-to/#findComment-1099373 Share on other sites More sharing options...
Skewled Posted August 14, 2010 Share Posted August 14, 2010 check back on page 1 I edited my post for you. Is that what your script looks like or similar to? I'm going to catch a movie with my wife so I'll check back later to see what you have. Quote Link to comment https://forums.phpfreaks.com/topic/210737-from-table-to-session-how-to/#findComment-1099376 Share on other sites More sharing options...
dgnzcn Posted August 14, 2010 Author Share Posted August 14, 2010 now give me a this message, I have not luck Sorry but the session died.. Quote Link to comment https://forums.phpfreaks.com/topic/210737-from-table-to-session-how-to/#findComment-1099383 Share on other sites More sharing options...
dgnzcn Posted August 14, 2010 Author Share Posted August 14, 2010 Ok, I checked your last edited message, and I changed like tihs : mysql_select_db($database_vekipman, $vekipman); $query_URUNS = "SELECT `session_user` FROM urunler"; $URUNS = mysql_query($query_URUNS, $vekipman) or die(mysql_error()); $row_URUNS = mysql_fetch_assoc($URUNS); $totalRows_URUNS = mysql_num_rows($URUNS); $_SESSION['session_user']=$row_URUNS['session_user']; if($_SESSION['_login_id'] != $_SESSION['session_user']) { $home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/index.php'; header('Location: ' . $home_url); } else { echo 'Sorry but the session died.'; exit(); } and no luck still Sorry but the session died mesaages showing. Quote Link to comment https://forums.phpfreaks.com/topic/210737-from-table-to-session-how-to/#findComment-1099385 Share on other sites More sharing options...
Skewled Posted August 15, 2010 Share Posted August 15, 2010 Change: $row_URUNS = mysql_fetch_assoc($URUNS); to: $row_URUNS = mysql_fetch_array($URUNS); also change: echo 'Sorry but the session died.'; to: echo "Sorry but $_SESSION['login_id'] was equal to $_SESSION['session_user']"; Quote Link to comment https://forums.phpfreaks.com/topic/210737-from-table-to-session-how-to/#findComment-1099513 Share on other sites More sharing options...
wildteen88 Posted August 15, 2010 Share Posted August 15, 2010 Change: $row_URUNS = mysql_fetch_assoc($URUNS); to: $row_URUNS = mysql_fetch_array($URUNS); Why? They both do the same thing. Except mysql_fetch_array returns two types of arrays, an associative array (aka mysql_fetch_assoc) and an enumerated array (aka mysql_fetch_row). @dgnzcn: Can you tell us what values does $_SESSION['_login_id'] and $_SESSION['username'] hold? My guess is $_SESSION['_login_id'] contains a number, which is assigned to the user when they are logged in? And $_SESSION['username'] is the logged in users username? If that is the case you cannot compare a number to a string if($_SESSION['_login_id'] != $_SESSION['session_user']) { $home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/index.php'; header('Location: ' . $home_url); } else { echo 'Sorry but the session died.'; exit(); } PHP will not know the relationship between the login id and the username. Therefore that if statement will always return false, and thus the error message is shown. Why are you needing to compare the login id with the username? Quote Link to comment https://forums.phpfreaks.com/topic/210737-from-table-to-session-how-to/#findComment-1099521 Share on other sites More sharing options...
PFMaBiSmAd Posted August 15, 2010 Share Posted August 15, 2010 to: echo "Sorry but $_SESSION['login_id'] was equal to $_SESSION['session_user']"; ^^^ Also, that's syntactically incorrect and introduces a fatal parse error. Quote Link to comment https://forums.phpfreaks.com/topic/210737-from-table-to-session-how-to/#findComment-1099529 Share on other sites More sharing options...
Skewled Posted August 15, 2010 Share Posted August 15, 2010 echo 'Sorry but ' . $_SESSION['login_id'] . ' was equal to ' . $_SESSION['session_user']; Your right, ^^ this however will work just fine, perhaps I should drink my first cup of joe in the morning before making a post haha. @wildteen88: you are correct, I'm just used to working with that one over the other one. Quote Link to comment https://forums.phpfreaks.com/topic/210737-from-table-to-session-how-to/#findComment-1099546 Share on other sites More sharing options...
dgnzcn Posted August 15, 2010 Author Share Posted August 15, 2010 @dgnzcn: Can you tell us what values does $_SESSION['_login_id'] and $_SESSION['username'] hold? My guess is $_SESSION['_login_id'] contains a number, which is assigned to the user when they are logged in? And $_SESSION['username'] is the logged in users username? _login_id and session_username is a number... because, when a user is registered, id is also recorded in user table to id, and also , in uruns table to session_username Quote Link to comment https://forums.phpfreaks.com/topic/210737-from-table-to-session-how-to/#findComment-1099585 Share on other sites More sharing options...
dgnzcn Posted August 15, 2010 Author Share Posted August 15, 2010 my edited like this and there is no luck, it will go to index.php mysql_select_db($database_vekipman, $vekipman); $query_URUNS = "SELECT `session_user` FROM urunler"; $URUNS = mysql_query($query_URUNS, $vekipman) or die(mysql_error()); $row_URUNS = mysql_fetch_array($URUNS); $totalRows_URUNS = mysql_num_rows($URUNS); $_SESSION['session_user']=$row_URUNS['session_user']; if($_SESSION['login_id'] != $_SESSION['session_user']) { $home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/index.php'; header('Location: ' . $home_url); } else { echo 'Sorry but ' . $_SESSION['login_id'] . ' was equal to ' . $_SESSION['session_user']; } Quote Link to comment https://forums.phpfreaks.com/topic/210737-from-table-to-session-how-to/#findComment-1099589 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.