URL Redirection issue for hash(#) - php

I am sending mail using different file. My Main URL is something like this
http://www.examplehasset.com/enquiry-form.php#quote_page
from this page, i send enquiry. and after sending mail I wrote header loaction to redirect thank you page.
header("Location: enquiry-thanks-you-page.php");
exit;
so this line is working proper to redirect me on thank you page. but one issue is that character after (#) is also appended to my URL. so my thankyou page URL is looks like this.
http://www.examplehasset.com/enquiry-thanks-you-page.php#quote_page
I dont want #quote_page in URL. So let me know what is the method to do so? I just want the URL as follow. http://www.examplehasset.com/enquiry-thanks-you-page.php

Try to redirect with # only [ Work around ] .(See if it works across all browser).
header("Location: enquiry-thanks-you-page.php#"); //See if it works

Related

Send a message with PHP header location redirect

Is it possible to include some message in a PHP header:
header("Location: http://somesite.com");
header("Message: hello");
then on site.com:
$message = some_function(); // "hello"
I am currently using a $_GET parameter in the URL, but looking for an alternative, maybe sending a $_POST?
I'm trying to not use $_GET, or use cookies (I know, those are the best ways..)
It sounds like you are wanting to send some extra data to the page you are redirecting to. No, this isn't possible outside of the query string. You should understand what is happening here.
When you send a 302 or 301 status code along with a Location: header, the browser sees this and then makes a separate request to the URL specified by the Location: header. The server isn't sending anything to that page. It's almost as if the user simply typed in that new URL in their browser.
I say almost because in some circumstances, there is a referrer set by the browser. This isn't guaranteed though.
What you can do is send some sort of token that contains more information. Perhaps your page saves off a message in a database or something, and then you pass the ID in the query string of the URL you're redirecting to.
Also, if you set session/cookie data and you're redirecting to something on the same domain, you can read that information on the page the user eventually lands on.
In addition to what Brad suggested, you can also send some info using # in the url without affecting the query string and then capture it with js.
header("Location: http://somesite.com#success");
in js:
if(window.location.href.indexOf('#success')>0) {
alert("operation successfully completed");
}

PHP file redirect to given link

I have search on the web, yet I can't get the answer where a single PHP file could redirect to given url.
Like example I see on the website when I click the contact link on the menu I can see the url like below. And it redirect me to contact page. Even when I try placed other domain on the redirect 'to' location it can work as usual.
What is the best way to have a single file where could work like this
example.com/redir?s=icon_topost&url=http://www.example.com/contact (redir)
or
mydomain.com/redir.php?=http//www.mydomain.com/contact (redir.php)
I have try this code. I can't.
<?php header('Location: http://'); ?>
Thanks.
This code should work, but you must have not returned anything in the body to be able to change headers. What's the error PHP is displaying?
<?php header("Location: $_GET['url']"); ?>

php redirect() not working on online server

I had redirected my page like:
redirect(base_url().'user/login/?redirect=site/cart_steps/steps');
and it works fine in localhost and when i uploaded it to server it didnt redirect. I checked all the codes and above this all code executes. But when it comes to redirect the page doesnt redirects. I also tried
redirect(base_url().'user/login?redirect=site/cart_steps/steps');
redirect(base_url().'user/login');
header('Location:'.base_url().'user/login?redirect=site/cart_steps/steps');
header('Location:'.base_url().'user/login');
but the page didn't redirect? and also i checked out this The header function is not working on online server?
but it cant help me too.... can any one explain what is the problem here....
You can use the refresh method like this:
<?php
redirect($this->input->server('HTTP_REFERER'), 'refresh'); // refresh the page
?>
Another common mistake could be echoing out / printing something before the redirection.
I would check your CodeIgniter error logs to verify that particular file isn't throwing any error messages that could tell you what needs fixing.
If you haven't already, you'll probably also want to make sure that the URL helper is loaded.
ex:
$this->load->helper('url');
Another solution
<meta http-equiv="refresh" url=http://example.com/">
Try to use like this,
First define your base URL as :
$base_url = "Your base url";
then apply this $base_url variable to your redirect link.
Hope this will help.

php Header to redirect when post - redirect troubles

header('Location: ../pages/my-files.php?parent_id=' . $_POST['parent_id']);
The above needs to redirect the user when a form is submitted, using a hidden variable for _parent_id.
However for some reason the user is bieng redirected (or seems to be by looking at the browser URL) to simply ../pages/my-files.php
Any ideas?
PS. Im certain that $_POST['parent_id'] has a value.
Have you tried to encode $_POST['parent_id'] for use in a url?
header('Location: ../pages/my-files.php?parent_id=' . rawurlencode($_POST['parent_id']));
But it must be something else because your code looks ok. Are you shure that you are redirecting from that point and not from another? Have you tried putting a die() just before that redirection?Most of the times i had your problem i wasn't redirecting from the right place!

does a PHP redirection affects the way a crawler or a robot views a website?

for example if in my index.php i have something like:
<?php
header('Location: /mypublicsite/index.php');
?>
what do the crawlers and/or robots get? just a blank page? or they actually arrive to /mypublicsite/index.php?
Initially, they get a blank page, with a header saying they should load a different page instead. The client has to load the new page itself.
Robots do understand the Location directive, and will load the new page instead.
You have to understand though you should stop the execution of your php script yourself, because the Location header can be ignored.
So something like this:
<?php
header('Location: otherpage.php');
echo $secret;
?>
is unsafe, because $secret will be sent to the client.
They arrive at the target of the redirection.
The header information of the document will be read by the crawler. The robot will go to the url because the location entry tells everybody to redirect to the given URL.
See http://www.theinternetdigest.net/archive/301-redirects-seo.html and http://jesperastrom.com/seo-301/different-variations-of-redirects-301-302-303-304-etc/

Categories