I have a session lost problem in sub domain url (test.example.com) after login. But the same code working fine in (i.e example.com). I tried session.cookie_domain but same error exist. Please anybody help in this regards
I had the same experience like you hundreds of times which I finally found the problem. You don't need to worry if cookies enable or disable. You just have to re-declare parts of your scripts (variables-the data which you want to display) in a if else condition. Just redeclare the same thing using !isset and then else with the same variables mentioned twice in the if else condition, if you understand what i mean.e.g if (!isset etc){A+B} else {A+B}. It will call back the same variables over and over. And make sure start session is above the page and define a session e.g session['id'] on that page which you claim missing.. no need to worry about headers or white lines, it has actually nothing to do with it. I've tried it a million times. You don't need to bother using ajax etc. PHP can do almost everything. cheerio.
Related
I am trying to make login using ajax to send username and password to my php script for checking if there is any record in database, on my ajax success i want to reload the page in order to show something if session is created. I use session start on very top of my pages. Also on local server my login works perfect, but on ipage server i have this problem with losing session...(i tested it using var_dump($_SESSION) and its always array (size=0) empty)
I have also tried using this on my very top of pages:
session_save_path("your home directory path"/cgi-bin/tmp);
session_start();
but this also didn't work...
Also i have tried to change session.save_path but still same.
I am sorry for my bad English.
EDIT:
I`ve tried using form to create login but same issue still going on. Its clear now that something with the server is wrong.(maybe with the php.ini)
It turns out that my host changed servers and started using a different session save path other than /var/php_sessions which didn't exist anymore. A solution would have been to declare ini_set(' session.save_path','SOME WRITABLE PATH'); in all my script files but that would have been a pain. I talked with the host and they explicitly set the session path to a real path that did exist. Hope this helps anyone having session path troubles.
Location of session folder:
/domains/account/session
location of index.php
/domains/account/public_html/index.php
What I placed in index.php at line 0:
<?php
ini_set('session.save_path',realpath(dirname($_SERVER['DOCUMENT_ROOT']) . '/../session'));
session_start();
This is the only solution that worked for me. Hope this helps someone.
Maybe I'm late with my answer but I think it will be helpful to people who run into the same problem as I did.
I'm validating Login form by using jQuery and AJAX. If there are no matching records within the database then PHP script returns error but if everything is all right then PHP script stores email,passoword and loggedIn variables as sessions and returns success to jQuery. Then I put location.reload();
which apparently deletes session variables (all except boolean). So I used location.reload(true);. This solved my problem.
You can also read something more about this on W3Schools .
This is something that I in practice so far I have not seen before.
I made a web app which works beautifully on all devices (so far I was thinking). Last week I received a few complaints that one part of the application does not work. Maybe I've reviewed over 100 times my code and I have not found a mistake and error behavior is that at one point the session expires or is just is not setup - which is not possible. The system was tested on a pile of users.
Today I received a response from a client that uses the iPhone 5. And really happens is that sessions are not working properly.
I use this session to force the user to open the pages in the order and that there is no possibility of jumping from page to page. If the user tries to skip the page, just go back to the beginning and need to re-start the process.
On the iPhone during the process returns me to the start and stop. It does not allow you to go to level 1 just returning back until you clear you cache.
This error happen randomly anywhere in process.
-To mention, I sessions not deleted until the user reache the end.
Is it possible that the iPhone has a problem with their browser or is error on my side?
Thanks!
This is what that solved the same problem i was facing earliar. May this will help..
the session problems for login page might occur because the url you are opening in the browser are not unique. for example If say you are creating a login page for your website, and you have created sessions successfully. Now, if you are logging in from url say http://geekzgarage.com then your session is limited to this url only. If you again open the above url like http://www.geekzgarage.com (note www. in both urls), then you will see that you are not logged in. So please be sure that your webpage is opening always in single type of url. either with www. or without www.
I have an issue with the above plugin (WP Session Manager) where the session variables I set, are not always set. I know the PHP I'm using to set the variables is correct as they do work sometimes. But for example, I can have them working perfectly fine and echo'ed out to the screen as a test, then I 'logout' and blank all the variables by setting them to "", then log back in (and set them again) but they do not get echo'ed out this time, meaning they must not be set.
I know one works for definite, as it is used to see if the user is logged in or not, and I only get asked to log in on my site once, I can navigate around pages etc, close the browser and I'm only asked to log back in when I use my logout button to blank the variables.
Does anyone know what might be causing this please? Or is it going to be something very hard to diagnose?
Don't know if it will help or not (to fix the issue), with regards to editing the session timeout time, I see that there is the info on the FAQ page of the plugin, saying that it can be edited using this filter
add_filter( 'wp_session_expiration', function() { return 60 * 60; } ); // Set expiration to 1 hour
But where is this filter found/edited or added?
Hope someone can help with the problem :)
Thanks!
I have fixed this now. Redirecting to a different page instantly was causing an issue, waiting for 1 second before doing the redirect allowed the variables to be set.
I've read quite a few solutions on the web, but none really works for me. So Coming back to Stackoverflow:
The Issue is as following: My session gets created, it get's passed trough the pages, and it is usually still running if uploading a picture or changing information via AJAX. But sometimes, and that's not something I can reproduce - It just changes the Session ID as soon a picture is uploaded - I just get a new Session ID on the upload script - meaning if i browse trough the page it's the old ID but the picture of course won't get saved as it's a new session_id - and what's even more funny this one will stay the same for picture uploads until it's destroyed! So in fact I'll have 2 session_id's for the same session.
I am getting unpatient so it would be really nice if somebody had a clue for me. Of course session_start is executed at the top of every page ;).
I am doing quite a few unneccesary mistakes since a couple of weeks.. Oh well of course there was nothing wrong with the code as it was... The mistake was on my side as of I forget that flash doesn't pass anything if not told to.
And as I use the swfuploader libary, oh well I think you can imagine the rest.
Don't ever forget to pass your session id if using flash!
after searching (and testing) a way to offer a kind of go-back button I am asking that question here (maybe there is an easy solution).
I have a description about orienteering on my website (5 pages): http://www.uhebeisen.net/o-def/o-definition_ge.php
There are many websites from abroad having a link to this pages. Now I'd like to get their URL if a websurfer is entering my pages. Then I can place a button go-back to my navigation list that brings him back to his page from where he clicked the link to my description-pages.
I've seen solutions using javascript:history.go(-1) or $_SERVER['HTTP_REFERER'] with PHP but problem is that a websurfer can move around my pages and if finishing his reading from any page should be provided with his (calling) URL, e.g. the one of his University.
So I need to catch his URL and store it in a safe place until he decides to leave. And if he returns to the starting page while surfing on my pages his URL shouldn't be overwritten.
Since I do not program - just copy&paste and try to understand what happens. Any suggestion on how this can be done is welcome.
thank you George, that one worked
I wasn't aware to place the session_start at the very beginning of the file that's why I get the two warnings.
While testing this function I found that the session variables were not always cleared by the browser. Especially with Firefox, it keeps the calling URL almost forever (WinXP, FF 5.x) whereas Firefox 5 on the Mac, Safari (Mac) and Camino (Mac) work as expected: after restarting the program I can test successfully with another website.
Does Firefox have different setting possibilities in regard of sessions than other browsers?
You should store $_SERVER['HTTP_REFERER'] in the user's session upon arrival. Using this method, the value won't be overritten when the user browses within your site.
session_start();
if ( !isset( $_SESSION['referrer'] ) ) {
if ( !empty( $_SERVER['HTTP_REFERER'] ) ) { // Because not all browsers set this
$_SESSION['referrer'] = $_SERVER['HTTP_REFERER'];
}
}
One way to do it would be to store somewhere (perhaps in a cookie or session, which easy to do with your PHP page) the page they're coming from, but only if that page is not on your website's domain. This would require some if-statements to set the cookie/session value appropriately, but it can be done relatively easily using particular parts of the referrer variable. There is probably a more efficient way to store this, but this is one that jumps to mind right away.
EDIT: I highly recommend George's solution, much better way to do this.
Have you tried using a session?
session_start();
if( !isset($_SESSION['refer']) )
{
$_SESSION['refer'] = $_SERVER['HTTP_REFERER'];
}
then, once your ready to make the button, set the link to $_SESSION['refer'].
In my past projects I usually stores the redirect url following this process:
search for a query string parameter url (www.yoursite.com/?redirect_url=my_encoded_url)
If search at point 1 doesn't return any results, then I checks for the HTTP_REFERER
In both cases, I stores that value in a SESSION variable after verified that the url belongs to my site's domain.