My code in index.php:
<?php
$keyword = ($_GET['keyword']);
$adid = $_GET['adid'];
header("Location: http://www.tracking.com/base.php?asdf&keyword=&ad=" .$keyword .$adid);
?>
The tracking link is supposed to end with:
&keyword={keyword}&ad={AdId}
I need to pass the keyword and AdId through the URL onto the landing page which then redirects and pass both variables to the tracking link.
This is the URL I was trying:
www.example.com/?keyword={keyword}&ad={AdId}
I don't think I can test if my format above is correct unless I run search traffic to it.
I need help on getting the codes right and getting the URL to pass them correctly.
Edit: Did I format the URL to pass the variables correctly?
change this
header("Location: http://www.tracking.com/base.php?asdf&keyword=&ad=" .$keyword .$adid);
to
header("Location: http://www.tracking.com/base.php?keyword=$keyword&ad=$adid");
Try this:
header("Location:",'http://www.example.com/?&keyword='.$keyword.'&ad='.$adid);
try this..
<?php
$keyword = ($_GET['keyword']);
$adid = $_GET['adid'];
header("Location: http://www.tracking.com/base.php?keyword=$keyword&ad=$adid");
?>
You can try:
header("Location: http://www.tracing.com/base.php?asdf&keyword=$keyword&ad=$aid");
It seems that I post later,Ah.
Related
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
?>
I want to pass some information to another page using "header" but I also want to use a variable for the location, for example:
With a static URL in location:
header("Location: mypage.com?fname=$_POST['fname']&lname=$_POST['lname']");
I want to use a variable like so:
header("Location: $myVariable?fname=$_POST['fname']&lname=$_POST['lname']");
But I can't for the life of me get the syntax right, as shown above it will throw an error, any help is appreciated.
Tom
You need to set a full url (with http://) and use put arrays between parentheses {}.
Working well with a static url:
header("Location: http://mypage.com?fname={$_POST['fname']}&lname={$_POST['lname']}");
Working well with a url variable:
$url = 'http://mypage.com';
header("Location: $url?fname={$_POST['fname']}&lname={$_POST['lname']}");
I hope this helps!
There are two way you can achive this, one is use session and another this url strucutre,
In session :
session_start(); // this should be on top of login_check file
// this goes just before redirect line
$_SESSION['fname'] = $_POST['fname'];
Or use url structure as follows,
header(wwww.example.com?action='')
I would like to know if its possible to append a variable to url in address bar when page loads.
demo: http://communityimpact.com/discussions/
Current page is geolocated, if category = Central Austin...would like the url to load as http://communityimpact.com/discussions/central-austin
<?php echo $my_category; ?> = Central Austin
<?php echo $my_category_slug; ?> = central-austin
Any suggestions?
Actually headers are your best bet if you need to append variables to url.
Example:
$my_category = "Central Austin";
$my_category_grub = "central-austin";
header("location: community-impact/discussions/$my_category_grub");
//or append a var like this:
header(" location: community-impact/discussions/?location=$my_category_grub");
//then you could handle the request on the new page
But both of these methods would redirect you.
If you want to use $_SESSION vars would make more sense. I don't see any possibility of appending vars to URL without redirecting. Url is the address, if you change the Url then you HAVE to change page. But session vars live until they leave your site. And can hold that info hope this helps, I'm not sure what your purpose is.
$_SESSION["category"] = "central-austin";
But you have to have
session_start();
at the beginning of the page.
Try to use a redirection with headers, like
header("Location: http://communityimpact.com/discussions/central-austin");
Your probably should use JavaScript, there are two options here:
With a redirection
// similar behavior as an HTTP redirect
window.location.replace("http://communityimpact.com/discussions/central-austin");
// similar behavior as clicking on a link
window.location.href = "http://communityimpact.com/discussions/central-austin";
Without redirection
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();
Think my current page url is:
http://example.com/id=10
In this this page has link to go other page, I want to pass current URL as a query string like this:
http://example.com/about-us/?edit=1&return=http://example.com/id=10
in PHP
http://example.com/about-us/?edit=1&return=<?php echo $_SERVER['QUERY_STRING'] ?>
but this is not working, could anyone help me to do this.
Use this (I assume you are using http only);
$currentUrl = urlencode("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
$link = "http://example.com/about-us/?edit=1&return=" . $currentUrl;
use urlencode($_SERVER['QUERY_STRING'])
It encodes the link.