Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

redirect in php in the middle of the site

Tags:

php

I have a site in PHP; I want to redirect to external site after running some code; so I want something in the body tag; to redirect it after my code running; something like following example ; what can i do?

<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<header>
</header>
<?php
    $myffirend=" ";
$allmyffirend=" ";
$user=$_GET['user'];
    // this info save in my db

   redirect here // after save the information

   other code

?>
like image 493
user3485110 Avatar asked Dec 13 '25 12:12

user3485110


2 Answers

You can inject javascript script with redirection:

echo "<script>window.location = 'http://www.yourdomain.com'</script>";
like image 71
mareckmareck Avatar answered Dec 16 '25 03:12

mareckmareck


If you want redirect after page load

if (window.addEventListener) {
   window.addEventListener("load", afterLoadRedirect, false);
} else {
   window.attachEvent('onload', afterLoadRedirect);
}

function afterLoadRedirect(){
  window.location='your url';
}
like image 30
Nanhe Kumar Avatar answered Dec 16 '25 03:12

Nanhe Kumar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!