I am trying to pass a variable within a header link. I have tried below code
$name = "mike";
if($name != "lopan"){
header("Location:error-page.php?$errorMssg=Please enter information?");
}
This page redirect to location but doesn't pass the variable that contains the message. But when i create a simple link with values like this:
link
it passes it just fine.
Any ideas what i am doing wrong? or i can not pass information with headers?
You need to use urlencode like this:
if($name != "lopan"){
header("Location:error-page.php?errorMssg=".urlencode("Waoo so your not EVEN going to try to enter information huh?"));
}
And in error-page.php, you should get it (no need to urldecode):
<?php
$errorMssg = $_GET['errorMssg'];
Remove the $ before errorMssg and urlencode the message.
could it be because you have $errorMssg instead of $errorMsg ? also try to make a valid url, for example replace " " with %20 etc, function urlencode() could help you with this.
Related
I have the following code...
<?php
if ($_GET['custom_fields%5Bcartredirectmb%5D'] == 'test')
{ header("Location: http://www.google.com"); exit(); }
?>
I just need this code to get the parameter 'custom_fields[cartredirectmb]' and redirect based on its value.
It looks like it's hung up on the brackets in the parameter. I've tried using urlencode, but I'm not getting anywhere. I assume there's a simple answer to this get working.
Feedback? Thanks!
PHP automatically expands array expressions in the URL into the $_GET variable.
The following variable in the URL,
?custom_fields[cartredirectmb]=test
can be accessed through the cartredirectmb key, in the custom_fields array in the URL.
$_GET['custom_fields']['cartredirectmb']
I have a SMARTY form and would like to pass a variable(set from the url/referrer) from the form page to the thank you page. So what I do:
I open my page with the form: example.com/index.php?variable=blabla
I get the variable and form the thankyou page URL
$urlconv = 'example.com/thankyou.php?variable=' . $_GET["variable"];
When the form is filled and submit is clicked the form redirects to the thank you page: header('Location: ' . $urlconv);
I even echo $urlconv on the first page to be sure that I've constructed the url correctly together with the variable. And it shows it correctly.
Unfortunatelly the redirect omits the variable for some reason. It goes only to example.com/thankyou.php?variable= for some reason...
Maybe by the time I call the redirect the variable is gone, so my question is can I somehow hardcode the variable in $urlconv? Because if the echo is showing it right and then the riderect omits it it means it has saved only a shortcut to the variable and not the actual value in the string, right?
I have very basic programming skills.
Thanks!
Try using the urlencode function. Along with that, if its within your browser, kindly omit the example.com and try using a relative link.
So
$urlconv = '/thankyou.php?variable='.urlencode($_GET["variable"]);
I've tried this right now, and it did work.
$urlconv = '/start.php?variable='.$_GET["variable"];
header('Location: '.$urlconv);
2nd solution: Try using javascript redirection. Also use double quotes while assigning $urlconv, as in $urlconv = "/thankyou.php?variable=".urlencode($_GET["variable"]);
<?php
echo "<script>location.href='".$urlconv."';</script>";
?>
I have defined an email function in file: wel1.php
I need to call it in the middle of another php file, I'm trying to call it with:
include 'bienvenido/wel1.php?to="'.user.'"&pass="'.pass.'"';
I can correctly send email if I just type this in my browser's address bar:
bienvenido/wel1.php?to=some_email#gmail.com&pass=password
What am I missing?
Regards.
I think you can't pass GET parameters like this.
Thanks to the same variable scope used for included files, you can simply set $_GET variable before inclusion. Like this:
$_GET['to'] = $user;
$_GET['pass'] = $pass;
include 'bienvenido/wel1.php";
You will get what you want
Dollar signs for your variables:
include 'bienvenido/wel1.php?to="'.$user.'"&pass="'.$pass.'"';
you forgot the $ in front of the variable name: $user and $pass
So try: include 'bienvenido/wel1.php?to="'.$user.'"&pass="'.$pass.'"';
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.
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.