I'm using Codeigniter and I did the internationalization using :
CI-internationalization
I would like to add /en by default when the user access my site :
www.mysite.com -> www.mysite.com/en
What is the best way to achieve that ?
Thank you.
HTML redirects
The simplest way to redirect to another URL is with the Meta Refresh tag. You can place this meta tag inside the <head> at the top of any HTML page like this:
<meta http-equiv="refresh" content="0; URL='http://www.new-site.com/en'" />
The content attribute is the delay before the browser redirects to the new page, above example it is set to 0 seconds.
JavaScript redirects
Redirecting to another URL with JavaScript is pretty easy, we simply have to change the location property on the window object:
window.location = "http://www.new-site.com/en";
OR
window.location.href = "http://www.new-site.com/en";
OR
window.location.assign("http://www.new-site.com/en");
OR
window.location.replace("http://www.new-site.com/en");
PHP redirects
<?php
header('Location: http://www.new-site.com/en', true, 301);
exit();
?>
This has to be set before any markup or content of any other sort, however there is one small hitch. By default the function sends a 302 redirect response which tells everyone that the content has only been moved temporarily. Considering our specific use case we'll need to permanently move the files over to our new website, so we'll have to make a 301 redirect instead.
The optional true parameter above will replace a previously set header and the 301 at the end is what changes the response code to the right one
Source: https://css-tricks.com/redirect-web-page/
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>
Testing page
</title>
<meta http-equiv="refresh" content="0; URL='new/test.html'" />
</head>
<body>
Old page
</body>
</html>
second/new page
<html>
<head>
<title>new site
</title>
</head>
<body>
this is new page.
</body>
</html>
Related
I am new to working with facebook APIs, but i want a facebook share button on my website which share that specific data on user's timeline after log in to facebook. I have already read some documents on that and make a page for testing purpose on my localhost. But there is a problem
the page is,
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<script>
function fbs_click(){
u=location.href;
t=document.title;
d='param kumar';
window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'t='+encodeURIComponent(t)+'&d'+encodeURIComponent(d),'sharer','toolbar=0,status=0,width=626,height=436');
return false;
}
</script>
<body>
<div>
<h2>Some content of my website pages..</h2>
</div>
<div id="fb">
If a tag can have multiple values, just put multiple versions of the same tag on your page. The first tag (from top to bottom) is given preference during conflicts.
Share on FB
</div>
</body>
</html>
But when I click on the share on Fb button, after log in to Facebook it shows a blank page.
Can any one help me out. thanks
Your url //localhost/paramRND/FbShare.php it will not work for it.add url which is live.
OR
You can make your local machine accessible by using localtunnel . You'll need to (temporarily) change some URLs used in your app code / html so links point to the temporary domain, but at least facebook can reach your machine.
I am trying to get my website to redirect to the home page after it submits the contact form, and goes to the thank you page. I have it working well, other than redirecting AFTER thank you page, it works for if I delete thank you page. I know I need an of statement after the line and then the header(www.google.com) type thing, but not sure what to put for the if statement.
I uploaded my contact form files into the dropbox link below, if someone could get me on the right track that would be awesome. Thanks in advance.
https://www.dropbox.com/sh/2zrci8b04989u3d/gEc3u6rPK4
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
<title>Thank you!</title>
<link rel="STYLESHEET" type="text/css" href="contact.css">
</head>
<body>
<script>
window.onload=function() {
setTimeout(function() {
location.replace("index.php");
},3000); // wait 3 seconds
}
</script>
<h2>Thank you...</h2>
click here if you are not redirected in a few seconds
</body>
</html>
Without looking at the pages since I am on my phone, put this in thank you page
<script>
window.onload=function() {
setTimeout(function() {
location.replace("somepage.php");
},3000); // wait 3 seconds
}
</script>
<h2>Thank you...</h2>
click here if you are not redirected in a few seconds
Try something like this, in case the user does have javascript disabled:
<?php
header( "Refresh: 5 url=http://yourdomain.com/" );
?>
<!DOCTYPE html>
<html>
<!-- HTML CODE GOES HERE -->
</html>
The number 5 in the header() function is the amount of seconds before the page redirects the user the url.
The header function Must come before any html and/or php outputs
You can do this in 3 ways.
1 - Html redirect :
<!doctype html>
<head>
<META http-equiv="refresh" content="0;URL=http://www.example.com">
</head><body></body></html>
2 - PHP Header redirect :
<?php
header('Location: http://www.example.com');
?>
<!doctype html><html><head></head><body></body></html>
3 - Javascript Redirect :
<!doctype html><html><head>
<script>
window.location.assign("http://www.example.com");
</script>
</head><body></body></html>
I use the fololowing code for all links going outisde my website:
if ($_GET["url"])
{
$urll = base64_decode($_GET["url"]);
header("Location: ".$urll);
exit();
}
How can I show the Google Analytic's tracking code before the user is redirected so the page is tracked?
Could I just use a print statement?
Thanks.
If you wanted to track the hit with GA, then you will have to do something other than a redirect using HTTP headers. With that, you can't guarantee that the page content will be parsed and executed. I think in most browsers any content would be ignored.
Instead you will need to serve a page (could be blank) and use a javascript and/or meta redirect and place the GA code in there so it gets called prior to the redirect.
Something like this should work:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="refresh" content="1;URL">
<title>Redirect</title>
</head>
<body>
Redirecting...
<script type="text/javascript">
// put GA code here...
window.location = "URL";
</script>
</body>
</html>
You can't display any characters before a HTTP Header. It will cause the PHP to throw errors. You should do all of your tracking collection prior to putting them onto the page that has the 'Location:' Header on it.
I was learning PHP and trying to redirect pages based on if the cookie is set or not so below is the code I used to set the cookie on the first page
<?php
setcookie("test","logged in",time()+60,'/');
?>
Now on the testing page I delete the cookie but it doesn't get deleted below is the code
<?php
setcookie("test", 0, time()-(60*60*24*7));
if(isset($_COOKIE['test']))
{
echo "u had logged in";
}
else
header("Location: index.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
</body>
</html>
What exactly is the problem ?
Cookies are only set when a page is transmitted to the browser and are only read when they're sent to the server as a part of a HTTP request.
As such:
If you delete a cookie, it won't disappear until the next page load.
If you set a cookie, the value can't be read until the next page load.
A common way of dealing with this is to set/delete a cookie and then perform a re-direct.
Changes made to cookies are only visible to the server on refresh. If you reload the testing page, you shouldn't see the "logged in" text.
I have a test.php page
in this page , there is a url . i need to execute that url (here database updation is doing).This is my code
<?php
$username ='testUsername';
if($_GET['age']!=''){
header('location:www.test.com/update.php?age='.$_GET['age'].'&username='.$username); //need to updatethe age of this username
$show ='hello';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php echo $show ?>
</body>
</html>
i know this code is not going to work properly.How can i write in a good way.I donot want to redirect the page.I just need to execute that link
Just call file_get_contents on the url in question instead of setting the location header to that value.
Since the update.php file is hosted on an external website, the only thing you can do is get the contents of the output of the file. (Use file_get_contents to get that output.) That is, it will call the file (with your parameters) and you can fetch the HTML result of it—nothing more. It would be a major security problem if server files could be executed on external websites.
If you need to include the code in update.php without redirecting, you can do so with the include or require functions.
require() is identical to include()
except upon failure it will ... halt
the script whereas include() only
emits a warning (E_WARNING) which
allows the script to continue.
Use the IMG tag. <img widht=0 height=0 src="<?='location:www.test.com/update.php?age='.$_GET['age'].'&username='.$username ?>" />