detect mobile device

Status
Niet open voor verdere reacties.

marc 05

Gebruiker
Lid geworden
5 sep 2006
Berichten
227
Als ik onderstaand script in de index pagina plaats van mijn standaardpagin en ik deze dan open in een IE bowser op een desktop kijg ik de volgende melding:

Parse error: syntax error, unexpected '}' in C:\domains\voorbeeld.com\wwwroot\index.php on line 10


PHP:
<?php
 // Written By Adam Khoury @ developphp.com - March 26, 2010
 // PHP mobile browser detection ready Home Page(index file that detects and redirects)
 // Simply find the device OS or browser label and place conditionals as needed
 $agent = $_SERVER['HTTP_USER_AGENT']; // Put browser name into local variable 
if (preg_match(“/iPhone/”, $agent)) {
    // Apple iPhone Device
    // Send them to iphone sized homepage for mobile
    header(“location:http://www.voorbeeld.com”); 
} else if (preg_match(“/android/”, $agent)) {
    // Google Device using Android OS
    // Send them to android sized homepage for mobile
    header(“location:http://www.voorbeeld.com/mobiel1”);
}
(preg_match(‘/opera mini/i’,$user_agent) {
    // Google Device using Android OS
    // Send them to android sized homepage for mobile
    header(“location:http://www.voorbeeld.com/mobiel2”); 
}
?>
 
Laatst bewerkt door een moderator:
Hoort er geen if voor de regel "(preg_match(‘/opera mini/i’,$user_agent) {" te staan..?
 
ja, dat had ik er later wel ingezet tijdens de test maar ging nog steeds fout.

Hieronder het orgineel script dat ik getest heb, dit geeft ook gewoon dezelfde fout, test het maar eens.:


Code:
<?php
 // Written By Adam Khoury @ developphp.com - March 26, 2010
 // PHP mobile browser detection ready Home Page(index file that detects and redirects)
 // Simply find the device OS or browser label and place conditionals as needed
 $agent = $_SERVER['HTTP_USER_AGENT']; // Put browser name into local variable 
 
if (preg_match(“/iPhone/”, $agent)) {
 
 
 
 
 
 
 

// Apple iPhone Device
 // Send them to iphone sized homepage for mobile
 header(“location: iphone_home.html”); 
 
} else if (preg_match(“/android/”, $agent)) {
 
 
 
 
 
 
 
// Google Device using Android OS
 // Send them to android sized homepage for mobile
 header(“location: android_home.html”); 
 
}
 
 
 
 
 
 
 
?>
 <html>
 <body>
 <h2>This is my regular homepage for people not using the devices defined in my script.</h2>
 <h3>If none of the user agents defined are detected, this page will display by default.</h3>
 <strong>You are viewing this page using:</strong><br />
 <em><?php echo $agent; ?></em>
 </body>
 </html>
 
En wat is regel 10 in dit script, gewoon letterlijk regel 10 of stond er in het originele bestand nog code boven?
 
er stond geen code meer boven maar er wordt gedoeld op de header location
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan