Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #17238 > unrolled thread
| Started by | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| First post | 2016-12-29 02:20 +0000 |
| Last post | 2016-12-29 02:20 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.php
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: php session variable is not passed Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-29 02:20 +0000
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2016-12-29 02:20 +0000 |
| Subject | Re: php session variable is not passed |
| Message-ID | <87tw9neas7.fsf@bsb.me.uk> |
"." <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 top | Article view | comp.lang.php
csiph-web