Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: PHP Cookies and Sessions not working with virtual hosts ? |
|
Author |
|
Rodion
Joined: 21 Feb 2014 Posts: 5 Location: Russia, Yekaterinburg
|
Posted: Sun 06 Apr '14 19:19 Post subject: PHP Cookies and Sessions not working with virtual hosts ? |
|
|
Hello, when I setup virtual hosts on my server and set cookies and sessions in PHP - they are not working, when I call scripts via domain name in browser ( for example, domain_parking_statistics.com/index.php ), but when I call them via IP adress - cookies and sessions work ( for example, 127.0.0.1/index.php ). I use Apache 2.4.7 win32 VC9 and PHP 5.5.9-Win32-VC11-x86. I've added string for domain name into my "System32\drivers\etc\hosts" :
Code: |
127.0.0.1 domain_parking_statistics.com |
Here is my httpd.conf :
Admin note:
Conf files removed, see the forum rules.
Here is part of my httpd-vhosts.conf with virtual host configuration :
Code: | <Directory "I:/Work/Servers/Site/Apache/Sites/2014/DomainsParkingSystem/pages">
Require all granted
</Directory>
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "I:/Work/Servers/Site/Apache/Sites/2014/DomainsParkingSystem/pages"
ServerName domain_parking_statistics.com
ServerAlias www.domain_parking_statistics.com
ErrorLog "logs/domain_parking_statistics.com-error.log"
CustomLog "logs/domain_parking_statistics.com-access.log" common
</VirtualHost> |
Maybe, somebody can help me to identify source of this problem and solve it? |
|
Back to top |
|
James Blond Moderator

Joined: 19 Jan 2006 Posts: 7398 Location: EU, Germany, Next to Hamburg
|
Posted: Sun 20 Apr '14 19:38 Post subject: |
|
|
how do you set the cookie? example script? |
|
Back to top |
|
Rodion
Joined: 21 Feb 2014 Posts: 5 Location: Russia, Yekaterinburg
|
Posted: Wed 23 Apr '14 13:24 Post subject: |
|
|
This way :
Code: | if ( $LoginBySession ) $_SESSION [ 'DomainParkingStatistics_Views' ] = 1;
$AuthorizationCookieExpireTime = 30 * 24 * 60 * 60;
if ( ! SetCookie ( "EMail", $UserEmail, Time () + $AuthorizationCookieExpireTime, "/" ) ) $ErrorString = $ErrorString . " Error in authorization cookie setting.";
if ( ! SetCookie ( "AuthorizationId", $AuthorizationIdString, Time () + $AuthorizationCookieExpireTime, "/" ) ) $ErrorString = $ErrorString . " Error in authorization cookie setting."; |
By the way, on site's hosting everything works without errors; so, it seems, that error is not in PHP scripts and is somewhere in server configuration. |
|
Back to top |
|
jraute

Joined: 13 Sep 2013 Posts: 188 Location: Rheinland, Germany
|
Posted: Wed 23 Apr '14 14:11 Post subject: |
|
|
May i ask what you mean with "on site's hosting everything works ..."? |
|
Back to top |
|
Rodion
Joined: 21 Feb 2014 Posts: 5 Location: Russia, Yekaterinburg
|
Posted: Wed 23 Apr '14 15:28 Post subject: |
|
|
>> May i ask what you mean with "on site's hosting everything works ..."?
This phrase means : I develop web site locally on server, installed on my computer, and then upload it to hosting ( Hostgator ) - and there on site's hosting cookies and sessions are set without problems. I think that this should be obvious. |
|
Back to top |
|
jraute

Joined: 13 Sep 2013 Posts: 188 Location: Rheinland, Germany
|
Posted: Wed 23 Apr '14 16:48 Post subject: |
|
|
Ok, thanks for explaining.
If it is running in a hosted environment and only on your server it is not running i would check dns, proxy-configuration (if used, it can cause problems if there are wrong or missing entries) and vhost-configuration. Do you use name based vhosts, then have a look at NameVirtualHost *:80 definition ...
It must be something trivial which is simply missing or misleading. |
|
Back to top |
|
Rodion
Joined: 21 Feb 2014 Posts: 5 Location: Russia, Yekaterinburg
|
Posted: Wed 23 Apr '14 17:06 Post subject: |
|
|
>> If it is running in a hosted environment and only on your server it is not running i would check dns, proxy-configuration (if used, it can cause problems if there are wrong or missing entries) and vhost-configuration.
I did not configured proxies, I just set vhost as it is shown in part of my httpd-vhosts.conf, which is shown in first post.
>> Do you use name based vhosts, then have a look at NameVirtualHost *:80 definition ... It must be something trivial which is simply missing or misleading.
Yes, I use name based vhost, but it is defined as "VirtualHost *:80" and then name of host goes in definition. Yes, I also think that I miss something in server configuration, but did not figured source of this error for now by myself. So, maybe someone, who has more experience in vhosts configuration, solved this error previously and can help me to solve it. |
|
Back to top |
|
jraute

Joined: 13 Sep 2013 Posts: 188 Location: Rheinland, Germany
|
Posted: Wed 23 Apr '14 17:21 Post subject: |
|
|
Rodion wrote: | >> If it is running in a hosted environment and only on your server it is not running i would check dns, proxy-configuration (if used, it can cause problems if there are wrong or missing entries) and vhost-configuration.
I did not configured proxies, I just set vhost as it is shown in part of my httpd-vhosts.conf, which is shown in first post. |
You got me wrong. I mean in windows, in the internet options the proxy configuration. That sounds strange, i know, but if that configuration is wrong, the local apache will not function as usual.
Quote: | Yes, I use name based vhost, but it is defined as "VirtualHost *:80" and then name of host goes in definition. |
Sorry, the question was if you use name based vhostS (more than one) ..., then you need a NameVirtualHost entry. |
|
Back to top |
|
Rodion
Joined: 21 Feb 2014 Posts: 5 Location: Russia, Yekaterinburg
|
Posted: Mon 28 Apr '14 16:43 Post subject: |
|
|
Sorry for delayed response.
>> You got me wrong. I mean in windows, in the internet options the proxy configuration. That sounds strange, i know, but if that configuration is wrong, the local apache will not function as usual.
No, I did not configured proxy in Windows; I use 3G modem, which uses its own program for connection - maybe it autoconfigures proxy or some other internet connection options.
>> Sorry, the question was if you use name based vhostS (more than one) ..., then you need a NameVirtualHost entry.
No, I use just one virtual host and another site, which is configured in httpd.conf; maybe they are conflicting in some way with each other? |
|
Back to top |
|
|
|
|
|
|