Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

passing variable in browser does not work

New Here ,
Jul 22, 2009 Jul 22, 2009

Im trying to pass a variable from one page to the next, but it is not working correctly. the variable $message is set on the previous page and sent through the url to the next page, but my script bellow is not picking it up for some reason. Any help is appreciated.

<?php

if ($message == "pm") {
    echo "Your passwords do not match each other. Please fix this and retry.";
} else if ($message == "pl") {
    echo "Your password does not meet the required length. It must be between 6 and 16 characters in length";
} else if ($message == "ul") {
    echo "Your Username doese not meet the required length. It must be between 5 and 30 characters in length";
} else if ($message == "ue") {
    echo "That username exists. Please try another";
} else {
    echo "";
}

?>

redirect from previous page: register.php?message=$warning

When it goes through the redirection it shows up as this in the browser "register.php?message=pm", "register.php?message=pl", "register.php?message=ul", or "register.php?message=ue", but my script above is not picking up that variable for some reason.

TOPICS
Server side applications
620
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 22, 2009 Jul 22, 2009

Please show us the part of the script that is assigning data passed from the form to the local $message variable on this page. Or did you forget that part?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 23, 2009 Jul 23, 2009
LATEST

jj12689 wrote:

Im trying to pass a variable from one page to the next, but it is not working correctly. the variable $message is set on the previous page and sent through the url to the next page, but my script bellow is not picking it up for some reason.

It's not picking it up because you're relying on a feature of PHP that was officially abandoned way back in 2002. The PHP configuration directive, register_globals, was turned off for security reasons, but a lot of hosting companies turned it back on to avoid breaking scripts. Thankfully, most hosting companies have abandoned that practice these days.

The solution is simple. Instead of using $message to get a value passed through the query string on the end of a URL, you need to use $_GET['message']. To get the value of a form variable, you use the $_POST superglobal array, e.g., $_POST['message'].

Change each instance of $message in your script like this:

if ($_GET['message'] == "pm") {

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines