i create a login page.
when user submit "username" and "password" if the username and password was true the
page redirect with
header("location:home_page.php");
this code work in firefox but in ie8 doesn't work.
i search and understand that ie has problem with session(that sent with another page, like iframe and popup)
finally i found a solution that told me set a header for privacy policy (p3p).
and i set this header but my problem not solve.
please help me.
i use
echo '<script type="text/javascript">window.location.href="home_page.php";</script>';
but the problem not solved
Some time I can not discover why header errors appear then i use javascript header instead php like:
echo '<script type="text/javascript">window.location.href="redirectpage";</script>';
You can use html meta tag too with php for redirection.
Related
I'm new at HTML/PHP and a doubt just came to my mind while developing a simple system to the company I work for.
After the user fill an HTML form and save it, I have a php page that saves the previous form information in my MySQL database. This PHP page displays a message if tha data has been saved correctly and after 5 seconds it redirects the user to my index.php. I used php header function to countdown the 5 seconds and redirect the user to index.php:
header("refresh:5,url= index.php"); /* Redirect browser */
That works perfectly on Google Chrome, but on IE it seems like it just understand the "refresh" part and completely ignore the "url" redirect, because it just refresh the current page, which gives me a few errors, of course.
My doubt is: php header function has compatibility problems with IE11 (or vice versa)? I know that I can use HTML to do the same thing, but is there a way to make the "url" from php header function works with IE11?
Thanks.
you can use it to refresh page
<meta http-equiv="refresh" content="30; ,URL=http://www.metatags.info/login">
please use like this as suggested below
echo '<meta http-equiv="refresh" content="30; ,URL=http://www.metatags.info/login">'
That's not how you redirect in PHP (it's actually how you redirect in HTML, which isn't the same thing). Try;
header("Location: index.php");
I wanted to popup an alert box. After that, the site would redirect to main page. But, it seems that it directly redirect to the mainpage without alerting anything.
if($registerquery)
{
?>
<script>alert('received!')</script>
<?php
}
header("Location: mainpage.php");
exit();
?>
I wanted to do this to ensure users that the process of submission ended successfully. How can i alert something before the page redirect to mainpage and more importantly what causes this? I think the page should not have redirected before the alert box.(Before these codes, site registers what users submitted but not relevant i guess.)Thanks
You just can't do this. PHP is server-side, JS is client-side. Using a location header is server-side, so the browser never gets the JS.
Instead, try something more like:
if( $registerquery)
echo "<script>alert('received!'); location.href='mainpage.php';</script>";
and remove the header bit altogether.
so i'm creating a login_url using php framework and getLoginUrl().
if my facebook app is setted as an FBML page, something like this works fine
echo '<fb:redirect url="'.$login_url.'" />';
but i need my facebook application configured as an IFRAME page, so it will not be rendered as FBML.
whats the best way to redirect my user to the login page?
using header(); in php will not work, because header is already sent. also
echo '<script type="text/javascript"> document.setLocation("'.$login_url.'"); </script>';
has no effect.
any ideas?
at the moment
echo '<script type="text/javascript"> top.location.href = "'.$login_url.'"; </script>';
is working. but i think its not a very clean solution.
i'll accept another answer if somebody has a better way.
I have a one page site that has PHP code in it. Once the user presses 'Send', this sends the information to my email, then displays a messagebox saying that the action was a success to the user - great.
After the messagebox is closed, the website stays at website.com/report.php. Is there a way to redirect it back to the original page.
Also, any way to change the icon in the messagebox that pops up? Here is the code that I have:
<script language="JavaScript">alert("Your request has been sent. I will contact you soon!");</script>
Thanks.
Look into window.open and window.location
Place it after your alert()
http://www.tizag.com/javascriptT/javascriptredirect.php
Also, to answer your messagebox icon question: No, it is browser-dependent and not modifiable.
If you want to do that, your are going to need to fake it with html/css and javascript.
<script language="JavaScript">
alert("Your request has been sent. I will contact you soon!");
window.location.assign("http://website.com");
</script>
If you want to change the icon in alert box or make it look a little fancy, you could try YUI dialog
Use this code to display the alert:
function displayAlert(message, redirect) {
alert(message);
window.location.href = redirect;
}
Then, you can use code like:
displayAlert("This is the message", "http://redirect.the/user/here");
Use the php header command
<?php
header("Location: http://www.example.com/");
exit;
?>
To do a redirect in PHP, use header("Location: page.php"); for this. Before and after this your code shouldn't be sending any other output to the response. Eventually use exit(); to terminate the script afterwards.
If you need the page which was requested right before this page, then best what you can do is to include its URL as request parameter of the link to report.php and use it as redirect destination. E.g.
report
and in the report.php pass it as hidden input field:
<input type="hidden" name="referrer" value="<?php echo getParam("referrer"); ?>">
And after submitting the report do:
header("Location: " . getParam("referrer") . ")"; // getParam() returns sanitized GET parameter.
An alternative is to use the $_SERVER['HTTP_REFERER'] header (yes, including the typo) for this, but this is just not that reliable as it may be disabled or spoofed by the client.
I believe a more elegant solution is to simply present the user with a confirmation page (instead of an alert box), and place a link to the previous page there.
That would at lease work for all users.
For those users with javascript a little Ajax (jQuery) could submit the form for you, and display the confirmation nessage. All without leaving the page the user is on (negating the need for any fancy redirects).
Towards the end of your php, use this:
header('location: home.php');
This will cause the browser to load the original page.
I don't believe that the standard alert box can be altered, aside from the message. You can't change the title or the buttons, either.
Frank
I was wondering if there was any way through php or javascript I could tell the browser to go back to the page it came from, or even better not load the page at all (the later being probably impossible).
The reason for this is that I have written a small php script that will take parameters from the url and post a tweet for me discreetly while I am at work.
ex.
tweet.php?user=myname&pass=mypass&message=My message goes here
Though it works, I get stuck with a white page. It would be nice if I could have the browser go back to the page it was just on, so the pause between work would be minimal.
Thank you for the help!
javascript: history.go(-1);
The JavaScript function for this is window.back(). Have your PHP script produce something like the following to have browsers automatically "bounced back" to the submitting page:
<html>
<head>
<title>Success</title>
</head>
<body onload="window.back()">
<h1>Success</h1>
</body>
</html>
Non-JS browsers will see a "success" message, JS browsers will get bounced back.
You could do the following in PHP to redirect back to the previous page:
<?php
$ref = $_SERVER['HTTP_REFERER'];
header('refresh: 10; url='.$ref);
?>
Depending on the browser, either an HTTP response code of 204 or 205 might cause it to not leave the current page.
If use use a PHP HEADER, you can redirect to another point on the site. Minimal Pause work (as long as the process isn't very long).
In tweet.php, use the header function to redirect back to the referer
Sending people back to the page without any success message would be very confusing. I would make the call with AJAX and provide some feedback to the user that the action was performed successfully, very much like the voting system here on SO works.