I know there are similar other questions here, but none of them solved my problem.
The problem: I'm setting data into $_SESSION, but in upcoming calls it is appearing as empty.
What I did to try solving it?
Make sure to run an up-to-date version of PHP
Make sure to know which php.ini is used
Log status of $_SESSION before and after setting it
Set various variables as suggested in other questions and forums
Here below I provide all the info I could supply, and hoping somebody will be able to suggest a solution!
I have installed PHP on my Mac using brew install php
I am running it locally for software development using this command:
php -S localhost:8099 -d display_errors=on -t .
[Tue Nov 17 23:12:55 2020] PHP 7.4.11 Development Server (http://localhost:8099) started
I'm calling session_start(); at the beginning of my script.
I am setting values into $_SESSION, but it is always empty when I am testing it in the following calls:
$ses = json_encode($_SESSION);
site_log("before: {$ses}");
session_regenerate_id();
$_SESSION["upath"] = 'XXXXXX';
$ses = json_encode($_SESSION);
site_log("after: {$ses}");
The result is always the same (while I'm expecting to see it on first call but not for the following calls):
20201118_040124_484 before: []
20201118_040124_485 after: {"upath":"XXXXXX"}
I was trying to follow many ideas from web forums:
Verify which is the INI file:
php -i | grep 'Configuration File'
>Configuration File (php.ini) Path => /usr/local/etc/php/7.4
>Loaded Configuration File => /usr/local/etc/php/7.4/php.ini
I was setting various INI file variables:
session.save_path = "/Users/myuser/Prog/MyApp/sessions"
+
chmod 777 /Users/myuser/Prog/MyApp/sessions
+
session.use_cookies = 1
+
session.cookie_secure = 0
But the result is still the same. Any idea please?
The following link points to the result of calling phpinfo(): link
So finally I have found a solution.
It is based on information provided here: Session cookie not being set
As #deceze was commenting correctly to my question, the first steps to debug such problem are these:
Check whether session files are created in the save_path folder (in my case: yes)
Use the dev-tools of the browser to see if cookies are set for the site (in my case: no)
So the actual problem is: why cookies are not set?
The solution:
Add an entry to alias 127.0.0.1 as a 'dot com' name. This is what I did:
# for Mac! see linked answer for other platforms
sudo vi /private/etc/hosts
# add this line:
127.0.0.1 mylocal.com
Activate the local php server for this domain (from the site root folder):
php -S mylocal.com:8099 -d display_errors=on -t .
Load the site from the php server. I'm using Brackets, and I had to open the menu: File -> Project Settings and set the live preview base URL to be:
http://mylocal.com:8099/
Some variables in the INI file might need to be set too, as already detailed in the question above
Hoping this info will help to others!
Related
I have database on my localhost when I tried to export database it gave me this error
Warning: a form on this page has more than 1000 fields. on submission,
some of the fields might be ignored, due to PHP's max_input_vars
configuration.
so I have changed max_input_vars = 1000 to max_input_vars = 10000
now I am able to download the database but it is taking lot of time to import on server and also it might be corrupt my database.
is there any other option to get my database working? I have around 450 tables and some tables have around 4000-5000 entries
I am working on windows 7 with xammp server and I have created this database for magento website.
This is 100% working
First find to max_input_vars in php.ini file
and change to:
;max_input_vars = 1000
to
max_input_vars = 1000
This is working fine in know more please visit video link.
The following was the solution for me :
First of, be sure that you are editing the right php.ini file. To do that you can check what it is with phpinfo().
Then restart php to reload php.ini, depending on how you installed it, it could be done like that :
brew services restart php72
Restart apache as well to be sure :
sudo apachectl -k restart
Then put the following statement in a test.php file :
echo ini_get('max_input_vars'); and check it.
At this point you will see it is correctly updated.
If you still have phpmyadmin showing error after that, you should then hard refresh your phpmyadmin page : it can be done with CMD+SHIFT+R on a Mac.
The reason for this is that phpmyadmin's local javascript file is getting passed the value of max_input_vars from php and is responsible for deciding to display the error or not. So if the javascript local file isn't updated for caching reasons for example, then you just have to refresh it and problem gone : )
You should provide more information about what system you are on and the method you tried to export the database, otherwise answers can't be specific.
mysqldump is what you need for exports.
On Linux (and probably on Apple computers too) you can simply use:
mysqldump -u YOUR_USER -p YOUR_DATABASE > DESIRED_FILE_NAME.sql
mysqldump should be also be available for Windows.
So I followed these instructions for my vagrant box and everything seemed to go fine, I mean its running. It has been configured with its server id and server token.
I then installed the PHP Probe, as per the instructions on the same page and restarted apache2 when it was done. I then did composer require
blackfire/php-sdk and finally in my code I did:
$probe = $blackfire->createProbe();
// some PHP code you want to profile
$blackfire->endProbe($probe);
dd('End here.'); // Laravels die and dump function.
So as far as I know I did everything right. Then, in my console I did:
vagrant#scotchbox:/var/www$ php artisan fetch_eve_online_region_type_history_information
[Blackfire\Exception\ApiException]
401: while calling GET https://blackfire.io/api/v1/collab-tokens [context: NULL] [headers: array (
0 => 'Authorization: Basic xxxxxx=',
1 => 'X-Blackfire-User-Agent: Blackfire PHP SDK/1.0',
)]
// where xxxx is some kind of authentication token that looks different from what I gave as my server id and token.
uh .... Ok so the docs state if something goes wrong to check the logs:
vagrant#scotchbox:/var/www$ cat /var/log/blackfire/agent.log
vagrant#scotchbox:/var/www$
Theres nothing in the logs....
What am I doing wrong?
Not a real solution, but rather a workaround until we hear more about how to actually solve it.
I have added the client credentials manually directly in the code and it solved the issue for me:
$config = new \Blackfire\ClientConfiguration();
$config->setClientId('...your _client_ id...');
$config->setClientToken('...your _client_ token...');
$blackfire = new \Blackfire\Client($config);
The string that I saw in the error was Authorization: Basic Og== and Og== is just a base64-encoded string :, which hints that username/password (or id/token in this case?) automatic lookup failed and authorization is impossible. That's why providing the details manually works around it.
A little bit late but maybe someone will need it in the future.
Adding the HOME environment variable to apache's vhost file so blackfire finds ~/.blackfire.ini solves it.
<VirtualHost hostname:80>
...
SetEnv HOME /Users/me #i'm running macOS, on linux would be /home/me
...
</VirtualHost>
consider that your probe configuration is correct (server_id & server_tokens) and you can profile from the browser , for using PHP SDK (phpunit integration with blackfire) you have to configure the client side :
apt-get install blackfire-agent
blackfire config you will prompt for BLACKFIRE_CLIENT_ID and BLACKFIRE_CLIENT_TOKEN .
you can also login to this api/v1/collab-tokens to test your client credentials username=>BLACKFIRE_CLIENT_ID , password=>BLACKFIRE_CLIENT_TOKEN
the config file location for the client : /root/.blackfire.ini
First, I have already looked at rciiipo's post from 2011. My problem don't seem to be fixed with the answers provided, and I have a few other inputs.
I get the below error when pointing browser to phpMyAdmin
Cannot start session without errors, please check errors given in
your PHP and/or webserver log file and configure your PHP installation properly.
Also ensure that cookies are enabled in your browser.
1) Session variables don't work with any php file. I am little unsure if it is related, but i believe the one problem causes the other.
This code below should display "teddy" when i refresh the webpage:
<?php
session_start();
$username = $_SESSION['username'];
if(isset($_SESSION['logged']) && $_SESSION['logged']=='yes') {
echo "$username";
}
$_SESSION['username']='Teddy';
$_SESSION['logged']='yes';
?>
My php.ini file:
session.save_path = "/var/lib/php5/session"
Permissions:
drwxr-xr-t 4 root www-data 4096 Sep 1 08:40 php5
|
-- drwxr-xr-x 2 root www-data 4096 Sep 1 08:40 session
I think the problem can be fixed if I only get $_SESSION variables to work in php.
I agree with bansi:
it looks like you have wrong permission for /var/lib/php5/session it
should be drwxrwxr-t or dr-xrwxr-t (assuming www-data is the web
server user). Write permission is required in the directory to save
session data.
Also, you should check the log files in /var/log/ of PHP (and maybe Apache as well) - they might give you some more details...
I am new to coding in php and also getting the environment set up on my local computer.
Here's the current setup configuration - I have installed wamp server version 2.2 which has the following - Apache 2.4.2, php 5.4.3, mysql 5.5.24
There is a very simple php code that i had written -
<?
mysql_connect("localhost","user","password");
mysql_select_db("mydbase");
$result = mysql_query("SELECT * FROM names WHERE ID LIKE '2'");
while($r=mysql_fetch_array($result))
{
$id = $r["id"];
$name = $r["name"];
}//close while
?>
Even a simple echo is not working. the output is blank. the same code works on the web server. It has the same user name, password and the tables were exported (from the webserver) and imported (into the local mysql).
The phpinfo() page shows the following -
display_errors - on - on
error_log - no value - no value
The php.ini file shows the following -
; display_errors
; Default Value: On
; Development Value: On
; Production Value: Off
and
;error_log = php_errors.log
; Log errors to syslog (Event Log on NT, not valid in Windows 95).
;error_log = syslog
error_log = c:/wamp/logs/php_error.log
The error logs are empty.
When i look at the source in the browser,
for the page online - it shows the output
for the page on the local computer - it just shows the php code
Could anyone please let me know what the problem could be? It seems like that there are some settings that i have messed up. But, i did not change anything - it is a regular installation and no custom settings were added.
Your script doesn't work, but your phpinfo page works? Check short_open_tag in your php.ini. Or modify your script and change your opening <? to <?php. If that works, you found the problem!
this happened to me too, try enabling the mime_module of apache
If, on info.php file creation with
<?php phpinfo(); ?>
You actully get that result, check if your webserver is configured to use php as script files:
Check inside httpd.conf for these lines and alter them if necessary:
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
Restart server and try to run the script again.
This is not your average session failed to start question, there is no whitespace, i have not called it in another file etc.
Im currently working on an application as I have started to build my session library, now when I call session_start I get the following error:
A session had already been started - ignoring session_start()
For those who wish to see the source: https://github.com/AdminSpot/ASFramework/blob/master/system/libraries/session.php
This usually means that the session.autostart directive is set to 1, but that's the thing.. it's not, it's set to 0 and I have verified this by doing the following:
Search my entire system for php.ini* files, checked them
Executed the following command php --ini amd validated the ini files
executed the following command php -i | grep session.auto_start. which responded with session.auto_start => Off => Off
Checked the PHPInfo page, see image below
Checked the php.ini files for cgi
There is no htaccess files on nginx
grep -lir "session_start" * only shows my library file
Restarting FastCGI, Nginx and the entire server
I have created a basic test script to test where i have just called session start on it's own.
The phpinfo() call stats the active php.ini is /etc/php5/cgi/php.ini so after running cat /etc/php5/cgi/php.ini | grep session.auto_start I get session.auto_start = 0, so it disabled, Could it be NGinx ?
Has anyone got any idea what's going on, some server information below:
PHP: PHP 5.3.5-1ubuntu7.2 with Suhosin-Patch
MySQL: Ver 14.14 Distrib 5.1.54, for debian-linux-gnu (i686) using readline 6.2
Nginx: Version: nginx/0.8.54
PHPInfo screen:
My first guess would be that you have an auto-prepend file or an .htaccess which is modifying the settings in the meanwhile.
You can use ini_get to retrieve the value of session.auto_start and auto_prepend_file to confirm. phpinfo() should work too.
Edit
Could it be that your session library is being instantiated twice? Since return $this->session_started is an instance variable, that could cause issues. What happens if you set that to a class-level variable?
Side note:
You also have this return $this->session_started = true; at the end of the start() method. It shouldn't matter, but it looks funny.
How about .htaccess containing a php_value session.auto_start 1? PHP on the command line would totally ignore settings overrides in .htaccess files. Remember that commandline PHP and web-based PHP have completely different .ini files in most standard configurations, so checking via command line is a waste of time.
I'd suggest having your script do a phpinfo() immediately before one of your session_start calls and check what the effective settings are there.
And anyway you can just verify if a session has already started or not.
if (!isset($_SESSION)) {
session_start();
}
http://php.net/manual/en/function.session-start.php#90007
Check and see if you are being passed a session cookie. May help you narrow it down.