Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.php Subject: Re: php session variable is not passed Date: Thu, 29 Dec 2016 02:20:24 +0000 Organization: A noiseless patient Spider Lines: 94 Message-ID: <87tw9neas7.fsf@bsb.me.uk> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="2b47fd5e98a8ae1ba4ab5a3f46b37fc8"; logging-data="13999"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+rAulPVJe+uw3EAanHanJXr2F06hA6XDg=" Cancel-Lock: sha1:h2k/rGIhblQEADwBOMv6cErU1G0= sha1:0qwKN9tTyBfP5jcBfbXv5WQRirQ= X-BSB-Auth: 1.14cdba527ce4b0fb28f9.20161229022024GMT.87tw9neas7.fsf@bsb.me.uk Xref: csiph.com comp.lang.php:17238 "." writes: > I am facing problem with php sessions . Suppose I have two pages > 1)form.php 2)receiver.php . I want to pass a variable frrom form.php > to receiver.php . here is my code > > > form.php : > > > session_start(); > ?> > > > > > > >
>
> > required> > > >
>
> > if (isset($_POST["sb"])) This is very unlikely to be true. This "page" is likely going to be the result of a GET request rather than a POST. > { > $u = $_POST["uF"]; > echo "u : " . $u . "
"; > $_SESSION["username"] = $_POST["uF"]; > > > echo "get : " . "
"; > print_r($_GET); > echo "
"; > echo "post : " . "
"; > print_r($_POST); > echo "
"; > echo "session : " . "
"; > print_r($_SESSION); > echo "
"; > > } > ?> > > > > receiver.php : > > session_start(); But this code is the result of a POST request -- specifically the result of submitting the form shown above. In other words it's here where you need to look at $_POST["uF"]. If you need to set a session variable, it's here you would do it. > $r =$_SESSION["username"]; > echo "r : "."
"; > echo $r; > echo "
"; > > echo "get : "."
"; > print_r($_GET); > echo "
"; > echo "post : "."
"; > print_r($_POST); > echo "
"; > echo "session : "."
"; > print_r($_SESSION); > echo "
"; > > > ?> > > > My goal is to pass a variable from form.php to receiver.php and print > it . That happens as a result of submitting the form. You don't need to do anything with session variables at all. -- Ben.