How to pass keyword to landing page using PHP? - php

I'm using a landing page to redirect to my tracking url, how do I pass the keyword to my landing page which then passes it to my tracking link? Here is what my tracking link ends with:
&keyword={keyword}
I have tried doing http://www.foo.com?keyword={keyword} but no luck.
My landing page has this code:
<?php
header("Location: http://trackinglink.com&keyword={keyword}");
exit;
?>
Help please!!
edit: sorry for not being clear, I'm doing PPC and I need to use a landing page instead of direct linking (tracking url) so I need to be able to pass the keyword from the lander (which I'm gonna give to the PPC network) to my tracking link so I can see what keywords convert.
I need to know how to format the url to pass the keyword and what code to put into the landing page. thanks.

either the below, or I am not sure what you've asked at all
<?php
$keyword = 'location';
header("Location: http://foo.com?keyword=".$keyword);
exit;
?>

class saveKeys {
public function setKeyword($keyword) {
$this->keyword = $keyword;
}
public function getKeyword() {
return $this->keyword;
}
}
$keyword = new saveKeys();
$keyword->setKeyword($_GET['keyword']);
Now you saved the keyword in the setter and you can get it on the other page.

Related

Wordpress - Redirect based on IP address

I'm making a Wordpress function that redirects the user to a different page when they're on a certain IP address. The code however does not function properly and I can't get it to work.
function ip_based_login()
{
if ($_SERVER['REMOTE_ADDR'] == '95.81.51.134')
{
wp_redirect("examplewebsite.com/login2"(site_url($wp->request)));
}
else
{
exit;
}
}
you dont really need to write a code for that
The best thing about wordpress is that there are tons of stuff already available
You can use the following plugin for your requirements
https://wordpress.org/plugins/shortcode-redirect/
site_url expects a path to attach to the site url(eg: site_url('hello') => https://example.com/hello.
$wp->request contains the path of the request which means doing site_url($wp->request) will return you the url you are on.
here is a working snippet, just replace $url with the url you want to redirect to.
function ip_based_login() {
$visitor = $_SERVER['REMOTE_ADDR'];
$redirectTo = site_url('login2');
if (preg_match("/95.81.51.134/",$visitor)) {
wp_redirect($redirectTo);
}
exit;
}
keep in mind that placing this snippet in functions.php without hooking it to a specific action can cause an infinite redirect loop.

How to get URL parameter and redirect after

Please I need help with how to write php code to get a URL parameter from and redirect to another page after. My URL looks something like this http://mywebsite.com/login.php?referrer=forum
The parameter I am interested in is the referrer=forum
I need this because i am trying to integrate a forum into my website which i am almost done with except for the single sign on(SSO) feature which allows the forum to use the register and login system i have already created for my website.
Thanks.
Something like this:
<?php
// get parameter from URL params
$referrer = $_GET['referrer'];
// redirect to another URL, including the referrer above
header('Location: http://someotherwebsite.com/?referrer=' . $referrer);
?>
You can store that parameter value in variable and pass in the link or you can use Session to use that variable across the multiple page.
<?php
session_start();
$_SESSION['referrer'] = $_GET['referrer'];
?>
And then in second page just use it from the session
<?php
session_start();
echo $_SESSION['referrer']; // use it as per your requirement
?>

How to use PHP variable in href?

I made a FacebookConnect class in PHP for a project. It's working well, but the problem is that I'm unable to use the href correctly.
Connect with fb
I'm trying to call a method from one of my controllers in the href. I want to make it so that when I click on the button, it starts the login process.
public function _loginFacebook()
{
$connect = new FacebookConnect($appid,$app_secret);
$user = $connect->connect('http://localhost/washare/?site=public&module=Compte&action=profil');
if (is_string($user)) {
return $user;
}
}
In fact, I wanted to use the $user variable (which is a redirect URL) in the href directly, but iI guess I'm doing this wrong. Can someone help me?
Function _loginFacebook is called? If so, what part of code is achieved?
You can use header for redirecting on php.
<?php
header('Location: mapeamento.php');
?>

Redirecting to an other page based on url

I am looking to have a page like this http://mydomain.com/A.php?url:http://mydomain.com/B.php
I want the visitor to load page A and automatically after a second be directed to what ever link the URL variable is (in my example its B.php)
I tried a few things my self, couldn't get it.
Any help?
thank you!
in your A.php
put something like :
header("Location: B.php");
exit();
if you want some parameters to be passed from A.php do something like:
$url = $_GET["url"];
header('Location:'.$url);
exit();

Redirect users to Long URL

I have an application where URL after rewriting are like this
http://www.domain.com/product/seller/product_id
an example link would be
http://storeiown.com/product/kitchenking/92013
This was okay but I need the title of the product to be included in the url
http://storeiown.com/product/a-very-nice-electric-cooker-by-kitchenking/92013
I achieved this too and all was good.
Now, I want all the url which do not include the title to redirect to this one.
Like, if user lands from the url without the title they should be redirected to a version of the page with the url containing the title in the url.
How do i accomplish that. And for info additional info I use CodeIgniter in the app, if that makes it any easier.
you can do this way which i use. In the previous page type this at the top:-
<?php
session_start();
$_SESSION['mainpass']= '0';
?>
And in the next page code this at the top of the page :-
<?php
session_start;
if(isset($_SESSION['mainpass'])) {
//run the current page
}else{
header("location: www.domain.com");
}
?>
If you are using codeigniter, you could try the below.
$seg3 = $this->uri->segment(3);
if(is_numeric($seg3)){
//The user has come without the header because the third segment is numeric thus probably using the product id.
//Therefore, redirect again to the proper link after getting the heading from your db
} else {
// do nothing
// the seg3 is not numeric means it probably came through normal preferred way
}
And in order to use the
$this->uri->segment(3);
You need to either
auto load the url helper
load manually when required

Categories