Jump to content

I'm getting a session error


maviyazilim
Go to solution Solved by mac_gyver,

Recommended Posts

the print_r() output is showing that the "nik" session variable is set, but it is empty. the warning on line 5 in sayfam.php is therefore coming from a reference to an undefined array key "nik" in some other variable. probably $_POST["nik"]. the OP's first post in this thread contained the code for sayfam.php. on line 4 in that code is an incorrect line of code setting - $_SESSION['nik'] = $_POST['nik']; the later post in this thread, with the three files of the code, where the last one is for sayfam.php, does not contain the line setting - $_SESSION['nik'] = $_POST['nik']; yet, there is now an error indicating that line of code is probably in (never removed from) sayfam.php,

so, two problems. 1) the OP is not posting the actual code that is being executed, and 2) that line of code needs to be removed from sayfam.php, since it is setting the session variable to a null/empty value.

Edited by mac_gyver
Link to comment
Share on other sites

4 minutes ago, mac_gyver said:

the print_r() output is showing that the "nik" session variable is set, but it is empty. the warning on line 5 in sayfam.php is therefore coming from a reference to an undefined array key "nik" in some other variable. probably $_POST["nik"]. the OP's first post in this thread contained the code for sayfam.php. on line 4 in that code is an incorrect line of code setting - $_SESSION['nik'] = $_POST['nik']; the later post in this thread, with the three files of the code, where the last one is for sayfam.php, does not contain the line setting - $_SESSION['nik'] = $_POST['nik']; yet, there is now an error indicating that line of code is probably in (never removed) from sayfam.php,

so, two problems. 1) the OP is not posting the actual code that is being executed, and 2) that line of code needs to be removed from sayfam.php, since it is setting the session variable to a null/empty value.

If I remove that code the error goes away. but this time how do i show the login person's name from the screen

Link to comment
Share on other sites

can you describe, in your native language, what $_SESSION['nik'] = $_POST['nik']; does and why it is in sayfam.php?

in English, this line of code is assigning a post method from variable $_POST['nik'] to the session variable $_SESSION['nik'] and it doesn't belong in sayfam.php at all. that post variable only exists on the page that the form submits to, denetim.php. it doesn't exist when sayfam.php is requested, producing the undefined index error you are getting and clearing that session variable.

what does the print_r() output show after you have removed that line of code from sayfam.php? note: as i already posted, you must completely close all instances of your browser and start over to cause the session variable to be set to the expected value.

post the current code for sayfam.php?

are you using google's online/browser translator to translate our replies into your native language? my first reply in this thread contains a lot of helpful information that would allow you to create an application that - is secure, provides a good User eXpeinace (UX), is simple and doesn't contain a lot of unnecessary typing, and through having error handling and validation logic, will either work or it will tell you why it doesn't work.

Link to comment
Share on other sites

1 hour ago, mac_gyver said:

can you describe, in your native language, what $_SESSION['nik'] = $_POST['nik']; does and why it is in sayfam.php?

in English, this line of code is assigning a post method from variable $_POST['nik'] to the session variable $_SESSION['nik'] and it doesn't belong in sayfam.php at all. that post variable only exists on the page that the form submits to, denetim.php. it doesn't exist when sayfam.php is requested, producing the undefined index error you are getting and clearing that session variable.

what does the print_r() output show after you have removed that line of code from sayfam.php? note: as i already posted, you must completely close all instances of your browser and start over to cause the session variable to be set to the expected value.

post the current code for sayfam.php?

are you using google's online/browser translator to translate our replies into your native language? my first reply in this thread contains a lot of helpful information that would allow you to create an application that - is secure, provides a good User eXpeinace (UX), is simple and doesn't contain a lot of unnecessary typing, and through having error handling and validation logic, will either work or it will tell you why it doesn't work.

I removed the session code in mypage.php. all errors are gone. but it doesn't show the username on the screen. the code is not working.

This is the reason why this code is on this page. I want to show the name of the person who logged into that page on the screen. but it doesn't.

I translate your answers using google translate.

My goal is to show the login person's name(nickname) on the screen. but it doesn't. as an error (Warning: Undefined array key "nik" in)

 

Link to comment
Share on other sites

1 hour ago, gizmola said:

This is usually simple.   At this point I think people need to see all your code.  Ideally you could put it in a github repo, but an alternative would be to post it to a pastebin like this one:  https://forum.gizmola.com/pastebin

https://forum.gizmola.com/pastebin/?51c9333ee96588e0#Hm9qCC27QMkJQ63cEnH4dJg1vhTqLH8Tk9CbCdMwkwBq

Link to comment
Share on other sites

We know no more now than we did when you posted the 3 files. We already understood that is the file with the error. Please provide all 4 files using the actual file names and without any sensitive information that is in them. I have a suspicion you have not followed the majority of the advice you have already been given. There is obviously a mistake (or many) that is causing the error. It will be very hard for you to solve the error if you are going to pick and choose what advice is given.

Edited by dodgeitorelse3
Added more context.
Link to comment
Share on other sites

  • Solution

the correct place to assign a value to the session variable is in the post method form processing code, at the point where you have confirmed that the username and password have been matched (it is currently not at this point in the code and needs to be corrected.) it should not be assigned a value in any other place. therefore, remove the assignment statement you currently/still have in sayfam.php. the debugging line of code, with print_r($_SESSION, true), should still be in sayfam.php, until you get this to work, since is shows if the session variable is set and what value it contains.

Edited by mac_gyver
Link to comment
Share on other sites

On 6/24/2023 at 4:54 AM, dodgeitorelse3 said:

We know no more now than we did when you posted the 3 files. We already understood that is the file with the error. Please provide all 4 files using the actual file names and without any sensitive information that is in them. I have a suspicion you have not followed the majority of the advice you have already been given. There is obviously a mistake (or many) that is causing the error. It will be very hard for you to solve the error if you are going to pick and choose what advice is given.

There is no other file than 3 files. there is a file. it is the file to which the database connection is made. it is added to the page with require_once in that file. There is no problem with the database connection. In the advice given, they said read the data. When I check whether there is data or not, it shows blank. already here is the problem. Why is there no data? why data does not reach this page?

Link to comment
Share on other sites

On 6/24/2023 at 6:36 PM, mac_gyver said:

the correct place to assign a value to the session variable is in the post method form processing code, at the point where you have confirmed that the username and password have been matched (it is currently not at this point in the code and needs to be corrected.) it should not be assigned a value in any other place. therefore, remove the assignment statement you currently/still have in sayfam.php. the debugging line of code, with print_r($_SESSION, true), should still be in sayfam.php, until you get this to work, since is shows if the session variable is set and what value it contains.

Thank you. After deleting the code from the problematic page, the code showing the username worked. now i can see the logged in user on the screen.

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.