Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #17238

Re: php session variable is not passed

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.php
Subject Re: php session variable is not passed
Date 2016-12-29 02:20 +0000
Organization A noiseless patient Spider
Message-ID <87tw9neas7.fsf@bsb.me.uk> (permalink)
References <c8123c64-f5f4-4850-a785-991a28e628b6@googlegroups.com>

Show all headers | View raw


"." <wavesofbluesea@gmail.com> 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 : 
>
>
> <?php
> session_start();
> ?>
>
> <!DOCTYPE html>
> <html lang="en">
> <head>
> </head>
> <body style="color: white ; background-color: #2aabd2 ; ">
>     <br>
>     <form method="post" enctype="multipart/form-data" action="receiver.php">
>             <label for="userId">USERNAME : </label>
>             <input type="text" placeholder="Enter username" id="userId" name="uF"
>                    required>
>         <button type="submit" name="sb">SUBMIT</button>
>         <button type="reset" name="rb">Reset</button>
>     </form>
>     <br>
>
> <?php
> 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 . "<br>";
>     $_SESSION["username"] = $_POST["uF"];
>     
>     
>     echo "get : " . "<br>";
>     print_r($_GET);
>     echo "<br>";
>     echo "post : " . "<br>";
>     print_r($_POST);
>     echo "<br>";
>     echo "session : " . "<br>";
>     print_r($_SESSION);
>     echo "<br>";
>     
> }
> ?>
> </body>
> </html>

>
> receiver.php :
>
> <?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 : "."<br>";
>     echo $r;
>     echo "<br>";
>
>     echo "get : "."<br>";
>     print_r($_GET);
>     echo "<br>";
>     echo "post : "."<br>";
>     print_r($_POST);
>     echo "<br>";
>     echo "session : "."<br>";
>     print_r($_SESSION);
>     echo "<br>";
>
>
> ?>
>
>
> 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.

Back to comp.lang.php | Previous | Next | Find similar | Unroll thread


Thread

Re: php session variable is not passed Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-29 02:20 +0000

csiph-web