Forum Moderators: coopster

Message Too Old, No Replies

How can I pass a variable from script to script

from script a.php to script b.php

         

bethesda

12:25 am on Dec 9, 2011 (gmt 0)

10+ Year Member



Hello again.

How can I pass a variable from script A.php to script B.php ? Code of script A.php


if (strspn($_POST['something'],"a±bcædeêfghijkl³mnñoópqrs¶tuvwxyz¼¿A¡BCÆDEÊFGHIJKL£MNÑOÓPQRS¦TUVWXYZ¬¯0123456789-:/.") == 0) {
$ error = "something to show"
header ("Location: .. / b.php");
}


In the script (b.php) I have this code:
echo "<div> $ error </ div>";

From a few hours im trying to transfer variables between a few scripts, but each time the script is loaded - variable disappears and with it the content that is my error

:-(

Thanks in advance.

vortex

12:54 am on Dec 9, 2011 (gmt 0)

10+ Year Member



One way is to send the variable via a $_GET argument, meaning your header code should be
header("location: ../b.php?error

and in b.php
if (isset($_GET['error'])) {
echo "<div>something to show</div>";
}

You can also use
header("location: ../b.php?error=something_to_show

and b.php
if (isset($_GET['error'])) {
$error = strip_tags($error);
$error = str_replace('_', ' ', $error);
echo "<div>$error</div>";
}

It would require more work in b.php though.

penders

9:19 am on Dec 9, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If using the URL parameter approach you might also need to pass "something to show" through urlencode() [uk3.php.net].

bethesda

11:49 pm on Dec 9, 2011 (gmt 0)

10+ Year Member



Thanks very much.