0

Hello all I am new to PHP

I am using window.location for redirecting to another PHP page.. but I need to add some data to this

so that I am using

echo'<script> window.location="../post/view_full_post.php?ID=<? echo $ID ?>"</script> ';

but it not workes for me and gives me in my URL

http://bla bla/bla bla/post/view_full_post.php?ID=%3C?%20echo%20$ID%20?%3E

and says me that I am passing valid ID but it not working

Not Acceptable

An appropriate representation of the requested resource /bla bla/post/view_full_post.php could not be found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

so my question is how to pass query string into Window.location?

1
  • This is why I prefer to use the sprintf() function for this... Commented Aug 13, 2013 at 13:37

3 Answers 3

2

Your below code is not correct:

echo'<script> window.location="../post/view_full_post.php?ID=<? echo $ID ?>"</script> ';

Replace it with the following:

echo '<script> window.location="../post/view_full_post.php?ID='.$ID.'"</script> ';
                                                             ^^^change here
Sign up to request clarification or add additional context in comments.

Comments

2

try changing it to

echo '<script> window.location="../post/view_full_post.php?ID=' . $ID . '"</script> ';

PHP doesn't evaluate code which appears in semi-quotes nor do you need to provide the echo in the middle of a line of code!

Comments

1

Seeing as you are already in PHP, you don't need php opening and closing tags. I would recomend this:

echo "<script> window.location=\"../post/view_full_post.php?ID=$ID\"</script> ";

However, if you can, I would use this before any output is sent. It will be quicker.

header('Location: http://example.com');

6 Comments

If you do header('Location: example.com'); you may need ob_start(); at the top of the document.
@rsmith Why woudl you want to add all those escape chars to confuse the eye. See other 2 answers for the correct/elegant way of doing it.
@RiggsFolly so we can include the variable within the string?
@rsmith Also he is using PHP to code up some javascript to be run in the browser once that page is sent. What on earth would be the point of running a header() function in the PHP to throw another page? Read, Digest, Consider, ...... Answer.
@RiggsFolly "he is using PHP to code up some javascript to be run in the browser once that page is sent" Ahh yes, because there is so many legit reasons why one would want to do this and then redirect
|

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.