3 users online. Create an account or sign in to join them.Users
Mobile Device Detection
This is an open discussion with 73 replies, filed under Extensions.
Search
Does anybody have an example of how the delegate should work? I've been having problems with;
public function getSubscribedDelegates() {
return array(
array(
'page' => '/frontend/',
'delegate' => 'MobileRedirection',
'callback' => array(
'url' => &$url,
'devices' => &$devices,
'result' => $result
)
),
);
}
From the Extension class docs the callback in your array should contain a string, which is a public method in your extension driver. For example:
array(
'page' => '/frontend/',
'delegate' => 'MobileRedirection',
'callback' => 'doMyRedirect'
)
And your callback method:
public function doMyRedirect($context) {
}
Inside this method $context will hold whatever has been passed from the MobileRedirection delegate call.
I'm trying to use this extension for our site and want to enable the redirect functionality. Currently my mobile site is using the same Symphony installation and I just have a page named "m".
When I enter "m" or "/m" in my "Redirect URL" preferences, I get a "too many redirects" sort of message on the iPhone.
Am I doing this right? Is there a way to "disable" the redirect on the mobile page itself? Or should it do that automatically?
Under 'Redirect URL' try entering http://url.com/m or http://localhost/symphonyinstallation/m ignore, that seems to do the same... i am using http://m.domain.com
see http://symphony-cms.com/discuss/thread/38410/#position-17
Thanks Nick, appreciate the explanation.
@TheJester12, I was having a simalar problem with the too many redirects when trying to redirect to a mobile page, i.e. mydomain.com/m. I solved it with the following lines of code in the extension.driver.php
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
$pageURL = rtrim($pageURL, "/");
$url = rtrim($url, "/");
if($can_redirect && $pageURL != $url){
redirect($url);
}
This code tests to see whether the current URL is the redirect URL. If it is then it doesn't do the redirect. I also removed the trailing slash before doing the comparison in case the user forgets to include it in the preferences section. Credit for getting the current URL in php is here
Hope this helps
Thanks bunches!
Hey Dave, I'm curious if you could be more specific as to where and how to use your code above? I tried adding it awhile ago with no avail. Is this something that could be added to the extension as a pull request?
@TheJester12 In the custom preferences in the backend I put this for the Redirect URL
http://www.mydomain.com/mobile/
Then in the extensions.driver.php I replaced the line (I think line 132):
if ($can_redirect) redirect($url);
with:
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
$pageURL = rtrim($pageURL, "/");
$url = rtrim($url, "/");
if($can_redirect && $pageURL != $url) redirect($url);
When I get a spare minute I'll put in a pull request but I'd bit interested to know if you get this working.
I still have problems using this code. I get a "too many redirects" message when I visit the page on my iPhone. My mobile page is a typical symphony page. I tried naming it "m", and I tried naming it "mobile", but both end up with url's like http://website.com/m/m/m/m/m/m/m/m/m... you get the idea.
Appreciate the help!
Hmmm, it looks like what might be happening is that the variables $pageURL and $url never become equal when you are on your mobile page. If they do not become equal then you will end up in the redirect infinite loop.
Can you comment out the last line of code:
if($can_redirect && $pageURL != $url) redirect($url);
and just echo out $pageURL and $url ? Something like:
echo($pageURL); echo($url);
Then visit your mobile page and see if these two variables are the same. If they are not can you post them up so I can see them?
Any progress with the above?
I have a multilingual site and think there might be a conflict/firing order issue with the redirects here.
EDIT The code from the solution to this issue on the Symphonists github version seems to have solved it: https://github.com/symphonists/mobiledevicedetection/issues/4
If I use the ?not-mobile cookie to set a no redirect cookie but I want to re-enable the ability to detect mobile again on the page for whatever reason what's the best approach to do this?
Is it worth adding a query such as ?redirect=not-mobile and ?redirect=mobile so that the cookie can be cleared as such or does this already exist?
EDIT
Looked in driver extension file and think the ?is-mobile allows the redirect to be re-enabled I'm guessing right?
Create an account or sign in to comment.
You don't need 5.3 if you use https://github.com/kirkstrobeck/mobiledevicedetection