Jump to content

from table to session how to ?


dgnzcn

Recommended Posts

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 ?

Link to comment
Share on other sites

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.";
  }
}

Link to comment
Share on other sites

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.";
  }
}

Link to comment
Share on other sites

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.";
  }
}

Link to comment
Share on other sites

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.";
  }
}

Link to comment
Share on other sites

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();}?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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();

}

?>

 

Link to comment
Share on other sites

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();
}

?>

Link to comment
Share on other sites

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();
}

?>

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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']";

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.  :D

 

@wildteen88: you are correct, I'm just used to working with that one over the other one.  8)

Link to comment
Share on other sites

@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

Link to comment
Share on other sites

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'];
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.