meta redirect with php inside - php

I have a php file. In it I want an error redirect like this:
<?php
$ponka = somerandomsite.com;
if (1=1)
{echo '<META HTTP-EQUIV="Refresh" Content="0; URL=http://$ponka/error.php">'}
?>
How can I achieve it?

You php contains lots of errors, here's a working sample
<?php
$site = $_GET['site'] // will get the variable $site form a url like script.php?site=somerandomsite.com
$ponka = "somerandomsite.com";
if ($site == $ponka){
echo "<META HTTP-EQUIV='Refresh' Content='0; URL=http://$ponka/error.php'>";
}
?>
Also, remeber that php as a function called header
<?php
$site = $_GET['site'] // will get the variable $site form a url like script.php?site=somerandomsite.com
$ponka = "somerandomsite.com";
if ($site == $ponka){
header("Location: http://$ponka/error.php");
}
?>

Related

Redirect in PHP doesnt load my link?

I have 2 php files.
The first one handles the link and stuff. Here is a preview my code:
<?php
session_start();
$link=$_GET['redirect'];
if ($link == '1'){
$_SESSION['link'] = 'https://www.google.com/';
header('Location: selection_handler.php');
exit;
}
if ($link == '2'){
$_SESSION['link'] = 'https://www.facebook.com/';
header('Location: selection_handler.php');
exit;
}
if ($link == '3'){
$_SESSION['link'] = 'https://www.twitter.com/';
header('Location: selection_handler.php');
exit;
}
?>
This is my selection_handler.php
<?php
session_start();
$link= $_SESSION['link'];
if(isset($_SESSION['user_id']))
{
header("Location: " .$link);
exit;
}
else
{
echo $_SESSION['link'];
}
?>
user_id would be handled later so by default, i would get the echo of the link from the session, right? that works properly but when i try to test setting a value for the user_id, i see my browser trying to load the link. It says 'Resolving host... Waiting for [insert link selected]' but doesnt fully continue to the site but instead im shown a blank page?
UPDATE: I tried changing the header to ('Location: https://www.google.com') instead of getting from the variable but im still getting a blank page

if elseif else preg_match windows location

I am creating a form where i want that if someone answer is a certain number like 2 or 7 the will be directed to diffrent pages.
I searched online and came up making this.
<?php
// define variables
$name "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (!preg_match("/^3/",$name)) {
echo "<meta http-equiv="refresh" content="0; URL=http://google.nl/">";
} elseif (!preg_match("/^9/",$name)) {
echo "<meta http-equiv="refresh" content="0; URL=http://osm.nl/">";
}
else {
echo "<meta http-equiv="refresh" content="0; URL=http://facebook.nl/">";
}
}
?>
First i tested it by creating a validation form, which works fine. Trough research i edited the code. But now when i tried to open the page it is point blank.
How do i fix it that i can redirect the inputs
Personally I would Use Switch Statement and the php header function to redirect
In the file your posting the form to:
$page = $_POST['name'];
switch($page)
{
case 2:
header("Location: http://www.google.com");
break;
case 7:
header("Location: http://www.facebook.com");
break;
}
Should do the trick.
So here are all your errors:
Line 3 :$name "": Where is the "="?
Line 7, 9, 12: echo "<meta http-equiv="refresh": If you haven't figured that youself, consider using header as #NathanLeadill said.

PHP redirect script

I want to redirect my site visitors form page B using my custom PHP script following this rule: If they come from page A, will be redirected to url 1, else i will display content/or url 2. I use this:
<?php
$referer = $_SERVER['HTTP_REFERER'];
$rest = substr("$referer", -8);
if($rest == "send.php")// if they come from my website page "send.php"
{
echo "<meta http-equiv=\"refresh\" content=\"0;url=http://google.com\">";
}
else
{
echo "$rest";
include 'content.php';
}
?>
.
Anyone can help?
<?php
$referer = $_SERVER['HTTP_REFERER'];
if (strpos($referer,'send.php') !== false)
{
echo "<meta http-equiv=\"refresh\" content=\"0;url=http://google.com\">";
}
else
{
echo "$rest";
include 'content.php';
}
?>
Instead of meta redirect you can also use header location.
header("Location:http://www.google.com");

PHP redirect with URL variables

I'm very new to php and trying to build a redirect which uses parameters from a URL which will differ from person to person.
The URL a person will access looks like: www.website1.com/redirect.php?p=p123&r=4&s=567
The p, r, and s will change for each person
I then want to redirect them to some other site that looks like this:
www.website2.com/p123.aspx?r=4&s=567
Here is what I have so far, but it's giving me an error "Cannot modify header information - headers already sent by ..."
<html>
<?php
$fpvalue = $_GET['p'];
$frvalue = $_GET['r'];
$fsvalue = $_GET['s'];
header("Location: http://website2.com/".$fpvalue.".aspx?r=".$frvalue."&s=".$fsvalue);
?>
</html>
I would really appreciate the help for a beginner.
Thanks!
You can't do a redirection when you have been sent a "content" (text, html, space, wherever).
You should NOT do this before calling the header() function.
As you can see, you have a "" before calling the header() function.
Change that:
<html>
<?php
$fpvalue = $_GET['p'];
$frvalue = $_GET['r'];
$fsvalue = $_GET['s'];
header("Location: http://website2.com/".$fpvalue.".aspx?r=".$frvalue."&s=".$fsvalue);
?>
</html>
For that:
<?php
$fpvalue = $_GET['p'];
$frvalue = $_GET['r'];
$fsvalue = $_GET['s'];
header("Location: http://website2.com/".$fpvalue.".aspx?r=".$frvalue."&s=".$fsvalue);
exit;
?>
<html>
</html>
And remember: Check if there is another previous space or "new line" before the "< ?php " tag.
The error "Cannot modify header information - headers already sent by ..." caused when you place session_start or php header below other codes, e.g. html
then you should change into:
<?php
//your php codes
//....
?>
<!DOCTYPE html>
....etc.
This must work
This instructions works for me to fix seo redirects, but you use for all
example url: http://yourdomain.com/index2.php?area=xpto
example index2.php file:
<?php
$fpvalue = $_GET['area'];
if ($fpvalue == 'xpto') {
header("Location: http://newurl.com/", true, 301);
}
else if ($fpvalue == 'loren') {
header("Location: http://otherurl.com/", true, 301);
}
else if ($fpvalue == '') {
header("Location: http://otherurl.com/", true, 301);
}?>

PHP subdomain redirect according to language variable

I'm trying to write a php script that checks the language(which is defined by the language function in $language) for a value and if user requests any address, www.example.com/foo/bar/data.php?=foobar it will redirect him by http refresh or redirect or header location(not preferable) to subdomain.example.com/$1 ($1 as in the same original requested address).
something like this but without the header location:
<?php if ($language == "en") { header ("Location: http://"$language".example.com/"$1""); } ?>
this does not work, also I get an error in the log "header already sent by another file" which is another script I got running and cannot change the code.
So, what I need is a script that reads the variable and according to its value it will redirect the user to the appropriate subdomain.
Hi you can echo a javascript code that contains redirection. Try this one.
<?php
if($language === "en"){
echo "<script type='text/javascript'> document.location = 'http://' . $language . '.example.com/' . $1; </script>";
}
?>
This code works most for me compared to header('Location: etc...').
<?php
// Language detection code
// ...
if ('en' === $language)
{
header('Location: http://' . $language . '.example.com' . $_SERVER['REQUEST_URI']);
exit();
}
If you really can't change the code from the other file, you'll need to make an html redirection instead.
<?php
// Language detection code
// ...
if ('en' === $language)
{
$url = 'http://' . $language . '.example.com' . $_SERVER['REQUEST_URI'];
echo <<<EOF
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Refresh" content="0; url={$url}" />
</head>
<body></body>
</html>
EOF;
exit();
}

Categories