Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

PHP: How to use Javascript inside PHP code

I would like to run one of JS scripts while redirecting to another webpage .. Script to change a variable in Index.php like below code:

if ($flag == 1) {
 // echo "<h1> Welcome to Website Home Page </h1>";
 if(header("Location: ../../index2.php")) {
 echo "<script type='text/javascript'> document.getElementById(body).style.color = 'red'; </script>";
 };
} else {
 // echo "<h1>Try Again!!!</h1>";
 echo "<div class='alert alert-danger' role='alert'>
 Your are not a Registered User <i class='fas fa-exclamation-triangle'></i> <br> Please Use below registrarion form.</div>";
 }

N.B: Still Junior learning PHP.

Answer*

Draft saved
Draft discarded
Cancel
3
  • Whatever for? I can't see how that would help. Commented Apr 14, 2020 at 21:53
  • You are right! Red it a bit fast based on the title and did not pay attention. Commented Apr 14, 2020 at 21:58
  • "when you check the URL" – They aren't checking the URL though, and its an HTTP redirect, they can't run JS inside it. Commented Apr 14, 2020 at 21:59

default

AltStyle によって変換されたページ (->オリジナル) /