/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] PHP Session not set first time

Hello fellow developers.

I’ve got some weird issue that I really need to get my head around.

I have a registration page and when a user hits submit I send it to a processing page to validate and then back to the registration page with the results.

On the return back to the registration page I look to see if the session is set:

[code=php] if(isset($_SESSION[‘arr_val’]) && isset($_SESSION[‘arr_error’])){ … [/code]

The first time a user submits the form the session variables are not set, but if I fill the form out again then the session variables are set.

Here is my redirect from the processing page:

[code=php]header(“Location: “.ROOT_PATH.”registration.php”);[/code]

If I redirect like this everything works fine:

[code=php]header(“Location: registration.php”);[/code]

WHY?!?! ?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NogDogApr 13.2010 — What is the value of ROOT_PATH? If it includes the domain name as part of the full URI (which technically should always be used in a Location header to be HTTP 1.1 compliant), it could be an issue with the page request using the "www." sub-domain in the URL while the redirect does not. This problem can be avoided by specifying that the session cookie domain be ".yourdomain.com" (note leading ".") either via the session.cookie_domain PHP config setting, or the [url=http://php.net/session_set_cookie_params]session_set_cookie_params[/url]() function (which would need to be called in each script prior to the session_start() call.
Copy linkTweet thisAlerts:
@jeremuauthorApr 13.2010 — Ok ... I thought ROOT_PATH was a PHP thing ... when I do an echo on ROOT_PATH it just says ROOT_PATH ... now I don't get it. Even if I do this:
[code=php]<?php echo ROOT_PATH."register.php" ?>[/code]
I get ROOT_PATHregister.php

This is throwing me off ... shouldn't I get an error or ROOT_PATH display as blank.
Copy linkTweet thisAlerts:
@NogDogApr 13.2010 — Your error_reporting setting probably has notices turned off. If it were on, you'd probably see a message to the effect that you are using an undefined constant and it is therefore being set to have a value the same as its name.
[code=php]
header('Location: http://'.$_SERVER['SERVER_NAME'].'/registration.php');
[/code]
Copy linkTweet thisAlerts:
@jeremuauthorApr 13.2010 — thanks for the help.
×

Success!

Help @jeremu spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...