0

is there a limit to the amount of times you can pass a variable in a URL? I have opened up a page after doing an AJAX call and I'm passing the mid variable through fine.

 window.open('articlecrop.php?id='+ result.mid, '_self');

I get the variable in php, do some unrelated stuff, then forward it through...

  $id = $_GET['id'];
   if( isset($_POST['submit']) )
    {header("Location: articlesave.php?filename=$filename&height=$orig_h&id=$id");
}

But the variable doesn't go through.

I've tried to echo the $id on to the screen and it works. I've also tried changing the $id field to some random text and it passes, so I know there isn't anything wrong with me pulling and passing the variable.

The problem seems to be in that I'm taking a variable from a URL, then passing it on again in the URL. Does anyone have a way around that?

   <form action="<?PHP echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
            <p>
                <label for="image">Image</label>
                <input type="file" name="image" id="image">
                <br />
            </p>
            <p>
                <input type="submit" name="submit" value="Upload image" />
            </p>
        </form>
5
  • What comes thru? Is is blank? Commented Mar 13, 2016 at 0:24
  • Possible duplicate of PHP passing a variable with header redirect Commented Mar 13, 2016 at 1:24
  • Yes, it's $id= then it's blank. Commented Mar 13, 2016 at 1:49
  • I've tried URL encoding. Commented Mar 13, 2016 at 1:49
  • As I mentioned, I've checked that I'm getting the variable from the previous screen by writing it on to the screen. I've also checked that it's not the process of passing the variable by replacing the get with "hello" and it passes it. That's why I think that the form encryption method might be the cause. Commented Mar 13, 2016 at 1:52

2 Answers 2

1

It's difficult to answer based on your question as you have provided just two lines of your code. There is no problem in passing variable more than once. As long as you are creating new url and executing that url, you can always add variables even it the same variable you have received from GET.

Sign up to request clarification or add additional context in comments.

2 Comments

I've added a form that may be causing it. Although, it doesn't explain why it works when I change $id = $_GET['id']; to $id ="hello"; Does it matter that the original url forward was done in javascript and then php?
Could the encryption type on the form prevent the id from being passed?
0

I've figured it out. The id variable that I pulled from the URL was lost when I submitted the form. To get around this I...

pulled the variable on page load

$id = $_GET['id']; 

then passed it in a hidden field on the form.

<input type="hidden" name="mid" id="mid" value="<?php echo $id; ?>">

pulled it on the form submission

$mid = $_POST['mid'];

then added it to the URL

header("Location: articlesave.php?filename=$filename&height=$orig_h&id=$mid");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.