I am going crazy and need some tips and help. Working with custom cms and php programming language. I am working on online site on server.
Problem is next:
Session start is ok, In functions.php I start session['lng'] and put _LNG constant in it and it's ok, passing alright.
When I call session['lng'] in my other files I always get the same language constant (en) but I am passing (hr) or (de)?? I checked 10 time if session is set somewhere else but it isn't.
How can I check where's the problem...I really don't know what to do next
Did you place this at the start of other files before accessing session variables. It's required to access session vars.
<?php
session_start();
Related
I've following two path
path1- test/hello/hello.php
path2- test/hello1/hello1.php //notice the one in the directory after test/
hello.php
<?php
session_start();
$_SESSION['name1'] = 'abcd1';
?>
other file is
hello1.php
<?php
session_start();
echo $_SESSION['name1'];
?>
In one computer I am able to get the value in hello1.php
In another computer I am not getting value in hello.php
In both the PC I had clear storage, ran Hello.php for session to set. Hello1 has value in One pc , in another I don't have value.
What might be the issue?
Also, what is the correct work, In general will I get session value Outside test folder OR everywhere inside test folder or only in the parent directory of the file where session was created.
Please don't forget the original issue.
Also one comment I don't know if its realated, I have 2 xampp in 2 drive in the pc where hello1.php gave the value. does'nt it affect anything?
In short I want concept of Session WRT to directories/ also about framework, does framework make restrictions to accessing variable outside their core project folder.
You told us nothing about how your PHP is configured, so there is a very extensive list of things which could be going wrong - far too many to list here. Make sure your error reporting/logging is working correctly (and that no errors or warnings are being produced). Have a look at the path, name and value of the cookies being emitted by the server for both pages using firebug or developer tools.
Sessions are preserved across requests and use cookies set on the browser to access the data. Your computers have different cookies, and thusly different sessions.
Read more about this in another answer
Ultimately you need to think about if you are using the right tools to accomplish this goal.
As silly as it sounds, I'm baffled by this behavior:
In my PHP code I am calling session_start(); before anything else (not even a space before it is called). I can test this by setting a session variable and then echoing said variable.
If I run the following code on one of my pages I get an expected session ID back, but if I run it on one of post pages used for ajax then it comes up empty. Only sessions that I set on the ajax post page specifically can be seen, not session variables set from another page.
$a = session_id();
var_dump($a);
I know I'm going to get responses telling me to make sure my session_start(); has been called from the beginning, but I swear up and down it is (if it wasn't, sessions wouldn't work locally on that page).
What in the world could be causing this strange behavior?
FWIW, adding ini_set('display_errors', 1); error_reporting(E_ALL); doesn't give me any info other than telling me I have an undefined variable when trying to dump a session var that was set from another page.
How do you navigate between the pages? If you're using header, the session data isn't always written before leaving the first page. I had to use
session_write_close();
header('Location: page2.php');
If you say that session_start() is implemented correctly and $a shows on some pages but not on specific pages, I would say it is most likely because session variables are super global and maybe on those pages you have a global variable $a.
This ended up being caused by my /tmp partition being full. I have a headless dropbox installation on this server and it decided to update itself overnight last night to a new version and not clean up behind itself. I should have gotten a notification that the /tmp partition was full but I did not for some reason so I didn't even think about it being the cause.
Let this be a warning to others who find they have the same problem I did. I'm still not entirely sure why I was able to set a new session variable on the problem page or even set the session vars for the other pages to begin with if the /tmp was full.
I appreciate everyone's willingness to help out though!
I've left ColdFusion and trying to get up to speed with PHP. First off, in building an app I'm trying to set an Application variable for the include paths, in CF I would use Application.FilePath = "/myWebApp/" and use to set up all includes template files. In PHP I'm not finding something similar.
I'm also struggling with setting Session specific variables. In CF, I would also set them in the Application.cfc/Application.cfm file as session.mySessionVarName. In PHP I'm not seeing a similar place to put these so they're available throughout the webapp, and the current session.
I thought this may be a common question but I didn't find anything related.
Thank you for your time.
To start a session, sesson_start:
session_start();
add a value to a session:
$_SESSION['name'] = 'value';
End a session, session_destroy:
session_destroy();
Save path for sessions, session_save_path:
Using codeigniter running locally on WAMP and dealing with sessions. I tried the default session handler, db session, native session and now db session. They all result in the same issue and I can't for the life of me figure it out.
The problem is that I am trying to set a session variable using a variable. I have confirmed the variable and have echoed it out and all is well in the controller. The controller calls on a view and the variable is there as well. The view calls on a uploader file and this is where the variable randomly gets set to "style.css" for some reason. If I set the session statically, say to "randyval", then it sticks. It's only when trying to use a variable that it breaks.
Using db session allows me to set using:
$some_val = $some_otherVal;
$_SESSION['sess'] = $some_val;
Only in the final page does echo $_SESSION['sess'] result in "style.css".
If however I do:
$_SESSION['sess'] = 'test';
Everything works as should.
Wouldn't ask unless I was at my wits ends... thanks for any input.
Color me stupid. :\ Turns out there was some bad html that was causing the problem(?). It had to do with, yeah, you guessed it, the header and more specifically where the "style.css" file was being called. Not sure why that was wrecking the session, but it indeed was. So, sorry for wasting everyones time, you can go home now.
You should work with CI sessions using Session Class
For any of you who stumbled upon this page, see here for the solution :
I solved it this way : Losing a session variable between one page with codeigniter session library
I have an application with multiple regions and various incoming links. The premise, well it worked before, is that in the app_controller, I break out these incoming links and set them in the session.
So I have a huge beforeFilter() in my app_controller which catches these and sets two variables in the session. Viewing.region and Search.engine, no problem.
The problem arises that the session does not seem to be persistant across page requests. So for example, going to /reviews/write (userReviews/add) should have a session available which was set when the user arrived at the site. Although it seems to have vanished!
It would appear that unless $this->params is caught explicitly in the app_controller and a session variable written, it does not exist on other pages.
So far I have tried, swapping between storing session in 'cake' and 'php' both seem to exhibit the same behaviour. I use 'php' as a default. My Session.timeout is '120', Session.checkAgent is False and Security.level is 'low'. All of which should give enough leniency to the framework to allow sessions the most room to live!
I'm a bit stumped as to why the session seems to be either recreated or blanked when a new page is being requested. I have commented out the requestAction() calls to make sure that isn't confusing the session request object also, which doesn't seem to make a difference.
Any help would be great, as I don't have to have to recode the site to pass all the various variables via parameters in the url, as that would suck, and it's worked before, thus switching on $this->Session->read('Viewing.region') in all my code!
Try setting the security setting in your /app/config/core.php file to medium or low. That solved a session problem I had.
i had the solution or at least that work for me
you try to pass from controller reviews action write to controller userReviews action add right???
check that your controller userReviews must end whit php tag "?>" and NO MORE SPACE
SO if you have someting like this
line
999 //more code lines
1000 ?>
1001
your session fail
you have to had this
line
999 //more code lines
1000 ?>
sorry for my bad english
soo you
It would appear that unless
$this->params is caught explicitly in
the app_controller and a session
variable written, it does not exist on
other pages.
That sounds like the proper behavior unless you are posting data from page to page. If you want any variable to persist, it should either be set in the model (where it will persist with the association), or passed on in a function, or set in the session explicitly using the session component:
$this->Session->write('Viewing.region');
(see: http://book.cakephp.org/view/398/Methods)
On a related note, I've had most success with sessions stored in the database. Run the file from app/config and set it to db. See if that helps.
Also, do the Cake core tests for the session work?
Might it be this problem? Essentially, cake's session resets if the user-agent changes
It's a shame that I ran into this very problem you mention a few days ago and now I cannot find the link that helped me solve it.
Also: are you using database or plain php sessions?
I'm going to go out on a limb here without being able to look at your code, but might it be possible that your "reviews" controller (or whatever) has its own beforeFilter() and doesn't call its parent's beforeFilter() explicitly?
This has burned me before...
I got some issues like this. Session set using some controller was not available in another , controller . I could clear the issue after spending few hours . There was a white space afer the end of php tag at the bottom . After clearing the line and white space after the last ?>
tag worked fine .
I had this problem when moving a CakePHP site. My problem was that the session directory wasn't writeable. You should make sure the folder app/tmp and all it's subfolders (including sessions) have permission 777.