Re: Session_Start() Doesn't Work
From: Phil Powell (soazine_at_erols.com)
Date: 05/01/04
- Next message: Phil Powell: "Re: No PHP Error. Just "Page Cannot be displayed""
- Previous message: Razzbar: "BUG: _SERVER["SCRIPT_URI"] doesn't work right with subdomains."
- Maybe in reply to: Chris Allen: "Re: Session_Start() Doesn't Work"
- Next in thread: Phil Powell: "Re: Session_Start() Doesn't Work"
- Reply: Phil Powell: "Re: Session_Start() Doesn't Work"
- Reply: Phil Powell: "Re: Session_Start() Doesn't Work"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 30 Apr 2004 16:10:03 -0700
I got it to retain $_SESSION['sql'], however, I can retain
$_SESSION['hidden'] but I can't seem to re-retrieve it. Consider this
code:
PHP:
--------------------------------------------------------------------------------
class SearchView extends View {
function SearchView() {} // CONSTRUCTOR
function &retainFormElements(&$html) { // STATIC HTML METHOD
$global $_GET, $_POST;
if ((!is_array($_POST) || @sizeof(array_values($_POST)) == 0) &&
$_SESSION['hidden']) {
$html .= $_SESSION['hidden'];
} else {
$collection = ($_POST && is_array($_POST) &&
@sizeof(array_values($_POST)) > 0) ? $_POST : $_GET;
foreach ($collection as $key => $val) {
if (!is_array($val)) {
$hiddenHTMLRetainer .= "<input type=\"hidden\" name=\"$key\"
value=\"$val\">\n";
$html .= $hiddenHTMLRetainer;
} else {
foreach ($val as $innerKey => $indivVal) {
if ($indivVal) {
$hiddenHTMLRetainer .= "<input type=\"hidden\" name=\"${key}[";
if (!is_numeric($innerKey)) $hiddenHTMLRetainer .= $innerKey;
$hiddenHTMLRetainer .= "]\" value=\"$indivVal\">\n";
$html .= $hiddenHTMLRetainer;
}
}
}
}
$_SESSION['hidden'] = $hiddenHTMLRetainer;
}
return $html;
}
}
--------------------------------------------------------------------------------
This class method is called from the class-level scope in another
class method:
PHP:
--------------------------------------------------------------------------------
class SearchPerformer extends DBActionPerformer {
function SearchPerformer () {} // CONSTRUCTOR
function &displayResults() { // STATIC HTML METHOD
// ADD STUFF to $html
$html = SearchView::retainFormElements($html); // WORKS EXCEPT FOR
SESSION
// ADD MORE STUFF TO $html
return $html;
}
function doSearch() { // VOID METHOD
$sql = "select * from blah";
$_SESSION['sql'] = $sql;
}
}
--------------------------------------------------------------------------------
This is actually a dumbed-down version of my actual code except for
retainFormElements() method. I have a routine where I am doing search
querying and returning results. Requirement (this is WORK BTW) is to
allow for modification of the existing search query as well as sorting
the existing query.
The only way I could figure to do both successfully is to save the
$sql statement into one $_SESSION variable (when you sort so that you
have your pre-built SQL all over again without having to rebuild it
from scratch) and store the $_POST collection variables from the form
into another $_SESSION variable as an HTML <hidden> element string
block (so when you click the links to sort the search results, though
$_POST is gone your stuff is still there if you need to modify).
However, here's my problem: While $_SESSION['sql'] exists,
$_SESSION['hidden'] does not. Though both are set, $_SESSION['hidden']
vanishes while $_SESSION['sql'] persists.
I don't think it is as simple as a manual issue. I'm totally stuck on
this, still! I have only one main script, "index.php", with
"session_start()" at the very top of the script, using PHP 4.3.2 with
register globals off and all other default settings, server is Linux
Red Hat 7.3.
Thanx
Phil
Javier_ <javier@yeahright.com> wrote in message news:<sc0c80p4t6d6rh7nikpo566g2dlhrvtpe2@4ax.com>...
> Chris,
>
> I ran across the same problem a couple of weeks ago. Some hosting
> companies require special magic lines of code and incantations :) (I
> don't know if you are using a hosting company but...) After much
> searching on my hosting company's support site I found that not only
> is it required to have the Session_Start() function at the top of
> every page but additionally they required session_save_path() to be
> explicity set as well at the top of every page. See below.
>
> <?php
> session_save_path("/some/path/with/permissions/for/your/account");
> Session_Start();
>
> $_SESSION['user']=$username;
>
> ?>
>
> It worked for me.
>
> There is also a function that will echo out the current
> session_save_path if you're curious but I couldn't find it again.
>
> buena suerte! my two cents.
>
> Javier
> aed7@deadspam.hotmail.com
>
>
>
>
> On Mon, 19 Apr 2004 21:35:42 +0000 (UTC), "Chris Allen"
> <c.allen@nospam.co.uk> wrote:
>
> >Hi
> >
> >I'm new to PHP and I'm trying to create a Login Form. Once the user has
> >logged in then he shouldn't have to log in again. The trouble is I'm getting
> >a new session ID between every page and so it doesn't recognise the user.
> >I've used Session_Start() which I thought was meant to maintain the session
> >variables between pages but it doesn't do work.
> >
> >Any ideas or FAQ's?
> >
> >Thanks
> >Chris
> >
- Next message: Phil Powell: "Re: No PHP Error. Just "Page Cannot be displayed""
- Previous message: Razzbar: "BUG: _SERVER["SCRIPT_URI"] doesn't work right with subdomains."
- Maybe in reply to: Chris Allen: "Re: Session_Start() Doesn't Work"
- Next in thread: Phil Powell: "Re: Session_Start() Doesn't Work"
- Reply: Phil Powell: "Re: Session_Start() Doesn't Work"
- Reply: Phil Powell: "Re: Session_Start() Doesn't Work"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|