-1

I am trying to add in my insertToDB.php file, that after some information, the page will redirect from www.example.com/insertToDB.php to the original page: www.example.com. I have tried a few thing like:

window.open("https://www.example.com","_self");

But this gives me error:

Warning: Use of undefined constant window - assumed 'window' (this will throw an Error in a future version of PHP) in /storage/ssd3/554/14293554/public_html/insertToDB.php on line 24

Fatal error: Uncaught Error: Call to undefined function open() in /storage/ssd3/554/14293554/public_html/insertToDB.php:24 Stack trace: #0 {main} thrown in /storage/ssd3/554/14293554/public_html/insertToDB.php on line 24

Also tried this:

/* Redirect browser */
header("Location: http://www.example.com/"); 
exit();

But gives me error:

Warning: Cannot modify header information - headers already sent by (output started at /storage/ssd3/554/14293554/public_html/insertToDB.php:22) in /storage/ssd3/554/14293554/public_html/insertToDB.php on line 25

Erik Auranaune
  • 1,384
  • 1
  • 12
  • 27

3 Answers3

0

Warning: Cannot modify header information - headers already sent by (output started at

check whitespace before <?php in you php file

peterp4n
  • 1
  • 1
  • 2
0

try to use this javascript redirect in your php code:

<?php
echo '<script>window.location.replace("https://www.example.com");</script>';
?>
avi haviv
  • 1
  • 1
-1

I managed to fix this. My code is like this:

echo "Done.";
/* Redirect browser */
header("Location: http://example.com/"); 
exit();

When I removed the echo line, it all worked fine.

Erik Auranaune
  • 1,384
  • 1
  • 12
  • 27
  • *"When I removed the echo line, it all worked fine."* - You need to remove the `echo "Done.";` here. People might copy / paste your entire code here and expect it to work. – Funk Forty Niner Jul 09 '20 at 14:19
  • @FunkFortyNiner That is pretty much what I said. Read the solution I posted again please ;) – Erik Auranaune Jul 09 '20 at 14:22
  • I'm glad that you fixed it yourself. But thing is that, you didn't include that echo'd line in your original post. What you should have done was to have posted the echo line in your question, that way others would have immediately spotted the error. But in this case, I and others would have known it anyway. But to someone who isn't experienced in that area, wouldn't know what to do. Others gave guessing answers and that isn't what Stack's about. – Funk Forty Niner Jul 09 '20 at 14:32