PHP - Need Help With A Redirect For Mobile
Hoping someone can help me i know very little about php anyways i am trying to get this to work on my eccommerce site which is all in php. Here is the instructions i have i did upload the files all i need help with is where to put the single line of code for the redirect.
Installation 1. Create a subdomain on your server called 'm'. (Ex: m.example.com) * Depending on what kind of hosting you have, the procedure to do this may be either editing configuration files and restarting the server, accessing a control panel, or having a system administrator set it up. 2. Upload the files from the 'm' directory to the document root for your new subdomain. 3. Your mobile site is working! Just visit your m subdomain to see it. Setting up auto redirect If your website is in PHP, you can use phpMobilizer to set up automatic redirection to your mobile site for mobile devices. 1. First you will need to determine where to place the redirect code. Usually you would want to place it in a common include file, such as a config file, a database connection file or a header file. 2. Add the following line of code before any html or text output. * require_once('/home/path/to/subdomain/m/mobilize.php'); * Edit the path so it is pointing directly to the mobilize.php file, which will be in the subdomain's document root. 3. Visit your website with a mobile device and verify it redirects you! Similar TutorialsAnybody know a good mobile website redirect function? Cant find a good one. Thanks in advance! Jason I'm trying to put together a script that redirects visitors based on their IP, user agent and/or referral url. Basically I want the script to scan these three factors from the visitor, if any of them turn out to match my redirect-requirement it redirects the user. I know the code is horribly coded, I'm incredibly new to the php-scene and consider myself a complete noob. As you can see I want redirected visitors to go to google.com and un-redirected to msn.com(examples). Really thankful for all the help I can get! Right now nothing works, any suggestions? <?php function redirect($page) { Header( "HTTP/1.1 301 Moved Permanently" ); header('Location: ' . $page); exit; } $referrals=array('pitchingit.org','referral2'); $badAgents = array("useragent1", "useragent2"); $deny = array("78.105.191..*","100.101.103..*"); if (in_array($_SERVER['HTTP_REFERER'], $referrals, FALSE)) { header("Location: http://www.google.com"); } else { header("Location: http://www.msn.com"); } if(in_array($_SERVER['HTTP_USER_AGENT'],$badAgents)) { redirect("http://www.google.com/"); exit(); } $add=$_SERVER['REMOTE_ADDR']; foreach ($deny as $ip) { if (preg_match("^.$add.*^",$ip)) { redirect("http://www.google.com"); } } redirect("http://www.msn.com"); ?> I have a site with seperate content and design for pc and mobile devices... What is the best way to detect and serve the correct content... 1. htaccesss file to detect the devise and then serve... 2. config.php file to detect devise and then serve appropriate files?.. ... im guessing it is version 2 that way you can still allow mobile users to access the full website.... kind regards J.. Hi, I would like to add some advertisment banners the link to landing pages. in the regular webdevelopment I use cookies. how do I do it with mobile? does it support cookies? please enlight me. Thank you. What doctype do i use for mobile webpages when that mobile webpage contains PHP ? I'm useing the w3c reccommended ones but the PHP doesn't work at all but if i remove the php then all is fine..is there a way to combine the two? Hey gues, My question is: how is the easy'est way to redirect i mobile visitor to: mobile.domain.com, when visiting: domain.com? Thanks:). Hi, I am bit confused as never done mobile website.
I was thinking we have to use jquery to create a website into mobile.
is it possible we can use only php/mysql and html?
Is it mean that mobile website is smaller version or is it mean we have to use some certain technologies like jquery, html5.
How google/other search engines will know this is mobile version and other is general website for computers.
I was thinking differently but today i donwload free version of mobile website and in coding they only used html css? what about php can we use it too without jquery for database.
sorry to ask realy basic question. I am trying to create a first mobile website.
any advice / hints will be much appreciated.
If any of you have developed mobile apps before I could really use some advice, please. I have never made one, and would like to for my website. I just need to query my database and display the information. From what I have been able to put together so far, I know that I can use css and jquery fine. My main question is: can I use php to query the mysql database? Pretty much I am a novice, so if using these languages together will not work, please feel free to suggest combinations that would be better. Although, I am trying to avoid as much object oriented stuff as I can, because I just don't get it entirely, but I'll still take the suggestion. Thanks. Hi everyone This is not really about php code...sorry. But i want some advice if you dont mind. I am working on a system, but i would like it to be available for PC use, aswell as for mobile use. What would be the best? To create two websites, one for mobile other for PC, and upload them to .mobi and .com domains, or should i create only one... I need this to be as user-friendly as possible...because the clients who are going to use this, is those ppl that is not comfortable with a PC, not to mention the web. Thanks Hi I am trying to create a site that determines the device's screen size. Most mobile phone browsers does not have javascript, so to determine the width and height of the screen I cannot use Javascript. Does anyone know how i can test whether a mobile phone is used to visit the site and what that phone's screen resolution is, so that I can redirect it to the right folder. Thanks in advance Hello, How can I send SMS to mobile phone using PHP? Please point me to a tutorial for achieving this. Also, what software will be needed to do this? I have some videos stored above web root. I then have a PHP file that acts as a proxy to hand the videos to the user. The reason for this is so not just anybody can download the videos. They have to be authenticated. If I am on the PC, it prompts for a download so I know the script is working. When I try it on my iPad, I get the big play button but with a cross through it. When I try it on my iPhone, the movie interface loads, but I am then prompted with "Cannot play movie: The server is not correctly configured" What could that be referring to? My script is below: <?php include("config.php"); //just includes session_start and db connection if ($_SESSION['user']['authed'] == true) { session_write_close(); $id = $_GET['id']; $query = mysql_query("SELECT filename FROM episodes WHERE id = '$id'"); $row = mysql_fetch_array($query); $filename = "../../media/".$row['filename']; header( 'Content-Description: File Transfer' ); header( 'Content-Type: application/octet-stream' ); header( 'Content-Disposition: attachment; filename='.basename( $filename ) ); header( 'Content-Transfer-Encoding: binary' ); header( 'Expires: 0' ); header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' ); header( 'Pragma: public' ); header( 'Content-Length: ' . filesize( $filename ) ); ob_clean(); flush(); readfile( $filename ); exit; } ?> This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=355495.0 Hey everyone! I'm an absolute beginner with PHP but in my struggle with a project, I keep seeing 'PHP' so here I am, asking for help from the experts. I have a client who wants a basic 'mobile version' of their website to be displayed automatically when people view it on a mobile device (iPhone, Android especially). I've tried a couple of JavaScript solutions but, for some reason, they wouldn't work on Android (despite the author of the code specifying that it 'should do'). This has led me to look into a server-side solution. If the user visits the site, e.g. www.mysite.com on a mobile device, I want it to redirect to the subdomain m.mysite.com (I could even use www.mysite.com/mobile). On this 'mobile version' there should be a link to view the full site (and vice versa). Does anyone know of any tried and tested methods to achieve this? I'm literally pulling my hair out now with this. Thank you so much in advance. Have a great day. Regards Darryl Hi I got a different and typical (for me) requirement from client. Client have a mobile. He will upload XML file from his mobile to my web address (http://111.111.111.111:8080/directoryname/ In my web address, i have to fetch that request (means take XML file) and insert those details into database by using php. Can anyone tell me how can i do this? Hello, Supposing I have site dealing in online money transfer, how do I extend the access to users with low grade mobile phones without GPRS. I would want a user to be able to transfer money online using a just about any handset however primitive. I have a form created that seems to work across most devices/connection.. but for some reason some phones, Androids specifically so far, seem to time out when the form is submitted using the mobile network. This has happened on multiple android phones. Doesn't seem to have an issue with iPhones. I also had a problem with a Surface tablet when connected to an android wireless signal.. tethering, the same phone that had the issue.
So what happens is once the form is submitted, it hangs for a while and then it'll say "No data received - Unable to load the webpage because the server sent no data. Reload this webpage Press the reload button to resubmit the data needed to load the page. Error code: ERR_EMPTY_RESPONSE" and then after i refresh, it submits and goes through without a problem. Sometimes it refreshsed by itself after flashing this error and goes through.
Another time, using the Surface Pro, wifi and IE, I got the error "Forbidden" you don't have permission to access /new-window-2.php on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
You can see an example of one of the forms here - connecttopros(dot)com/windows.php
And some of the code is attached below. I'm lost. I've tried using a different server completely, twice, and it didn't fix the issue, so it must be the way the php is put together? Thanks for your help!
Attached Files
Php Freaks.zip 12.25KB
1 downloads Hi, how can i detect if my website is being open in mobile type all devices instead of computer Please help Hi people. I'm very new to PHP and am building the www.airfieldcards.com website for pilots to use free of charge. I have made a subdomain "m" which I am going to use for the "mobile version" of the site. I have made the "information" showing card but need to make a menu as the first thing that the user sees when he logs onto the site via a mobile device (iPhone / android etc) It needs to take "username" from the database (this is the airfield name) Then list them in order (alphabetically) Then make a link out of the word to the ?"id" from the DB and display the relevant card. In other words. When the user visits http://m.airfieldcards.com the are greeted with the following Abbots Bromley Alderney Andrewsfield Here is the php that shows the actual "phone" version of the card. Code: [Select] <?php $host = 'localhost'; $usr = "username"; $password = 'thepassword'; $db_name = 'TheNameOfTheDB'; function cr($string){ $clean_string = str_replace("rn","<BR>",$string); return $clean_string; } if (!isset($id)) $id = $_GET['id']; mysql_connect ("$host","$usr","$password") or die ('Error During Connect:<br>'.mysql_error()); mysql_select_db ("$db_name") or die ('Error Selecting DB:<br>'.mysql_error()); $read_query = "select * from users where user_id = '$id'"; $results = mysql_query($read_query); $rs = mysql_fetch_array($results); ?> <!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> <style type="text/css"> <!-- body table { } body,td,th { font-size: x-large; } --> </style> <body> Airfield Name: <? echo $rs["username"]; ?> <table width="480" border="1" cellspacing="0" cellpadding="2"> <tr> <td bgcolor = #E6F8EB><span class="xx_large_font">Height Above</span></td> <td bgcolor = #E6F8EB><div align="right"><span class="xx_large_font"><strong><? echo $rs["height_above"]; ?></strong></span></div></td> </tr> <tr> <td bgcolor = #dbeff8><span class="xx_large_font">Mb Difference</span></td> <td bgcolor = #dbeff8><div align="right"><span class="xx_large_font"><strong><? echo $rs["mb_diff"]; ?></strong></span></div></td> </tr> <tr> <td bgcolor = #E6F8EB><span class="xx_large_font">Alternative</span></td> <td bgcolor = #E6F8EB><div align="right"><span class="xx_large_font"><strong><? echo $rs["alternative"]; ?></strong></span></div></td> </tr> <tr> <td bgcolor = #dbeff8><span class="xx_large_font">General Location</span></td> <td bgcolor = #dbeff8><div align="right"><span class="xx_large_font"><strong><? echo $rs["general_location"]; ?></strong></span></div></td> </tr> <tr> <td bgcolor = #E6F8EB><span class="xx_large_font">Grid Reference</span></td> <td bgcolor = #E6F8EB><div align="right"><span class="xx_large_font"><strong><? echo $rs["location_grid"]; ?></strong></span></div></td> </tr> <tr> <td bgcolor = #dbeff8><span class="xx_large_font">Runway Num</span></td> <td bgcolor = #dbeff8><div align="right"><span class="xx_large_font"><strong><? echo $rs["runway_numbers"]; ?></strong></span></div></td> </tr> <tr> <td width="240" bgcolor = #E6F8EB><span class="xx_large_font">Circuit Dir</span></td> <td width="240" bgcolor = #E6F8EB><div align="right"><span class="xx_large_font"><strong><? echo $rs["circuit_direction"]; ?></strong></span></div></td> </tr> <tr> <td bgcolor = #dbeff8><span class="xx_large_font">Cirtuit Height</span></td> <td bgcolor = #dbeff8><div align="right"><span class="xx_large_font"><strong><? echo $rs["circuit_height"]; ?></strong></span></div></td> </tr> <tr> <td bgcolor = #E6F8EB><span class="xx_large_font">Runway m</span></td> <td bgcolor = #E6F8EB><div align="right"><span class="xx_large_font"><strong><? echo $rs["runway_length"]; ?></strong></span></div></td> </tr> <tr> <td bgcolor = #dbeff8><span class="xx_large_font">OHJ Height</span></td> <td bgcolor = #dbeff8><div align="right"><span class="xx_large_font"><strong><? echo $rs["ohj_height"]; ?></strong></span></div></td> </tr> <tr> <td bgcolor = #E6F8EB><span class="xx_large_font">Surface</span></td> <td bgcolor = #E6F8EB><div align="right"><span class="xx_large_font"><strong><? echo $rs["surface"]; ?></strong></span></div></td> </tr> <tr> <td bgcolor = #dbeff8><span class="xx_large_font">Radio Freq</span></td> <td bgcolor = #dbeff8><div align="right"><span class="xx_large_font"><strong><? echo $rs["radio_frequency"]; ?></strong></span></div></td> </tr> <tr> <td bgcolor = #E6F8EB><span class="xx_large_font">Callsign</span></td> <td bgcolor = #E6F8EB><div align="right"><span class="xx_large_font"><strong><? echo $rs["radio_callsign"]; ?></strong></span></div></td> </tr> <tr> <td bgcolor = #dbeff8><span class="xx_large_font">Type</span></td> <td bgcolor = #dbeff8><div align="right"><span class="xx_large_font"><strong><? echo $rs["radio_type"]; ?></strong></span></div></td> </tr> <tr> <td bgcolor = #E6F8EB><span class="xx_large_font">Other Radio</span></td> <td bgcolor = #E6F8EB><div align="right"><span class="xx_large_font"><strong><? echo $rs["other_radio"]; ?></strong></span></div></td> </tr> <tr> <td bgcolor = #dbeff8><span class="xx_large_font">Fuel</span></td> <td bgcolor = #dbeff8><div align="right"><span class="xx_large_font"><strong><? echo $rs["fuel"]; ?></strong></span></div></td> </tr> <tr> <td bgcolor = #E6F8EB><span class="xx_large_font">Landing Fee</span></td> <td bgcolor = #E6F8EB><div align="right"><span class="xx_large_font"><strong><? echo $rs["landing_fee"]; ?></strong></span></div></td> </tr> <tr> <td bgcolor = #dbeff8><span class="xx_large_font">Opp Hrs</span></td> <td bgcolor = #dbeff8><div align="right"><span class="xx_large_font"><strong><? echo $rs["operating_hours"]; ?></strong></span></div></td> </tr> <tr> <td bgcolor = #E6F8EB><span class="xx_large_font">Maintenance</span></td> <td bgcolor = #E6F8EB><div align="right"><span class="xx_large_font"><strong><? echo $rs["maintenance"]; ?></strong></span></div></td> </tr> <tr> <td bgcolor = #dbeff8><span class="xx_large_font">Hangarage</span></td> <td bgcolor = #dbeff8><div align="right"><span class="xx_large_font"><strong><? echo $rs["hangarage"]; ?></strong></span></div></td> </tr> <tr> <td bgcolor = #E6F8EB><span class="xx_large_font">Parking</span></td> <td bgcolor = #E6F8EB><div align="right"><span class="xx_large_font"><strong><? echo $rs["parking"]; ?></strong></span></div></td> </tr> <tr> <td bgcolor = #dbeff8><span class="xx_large_font">Food</span></td> <td bgcolor = #dbeff8><div align="right"><span class="xx_large_font"><strong><? echo $rs["food"]; ?></strong></span></div></td> </tr> <tr> <td bgcolor = #E6F8EB><span class="xx_large_font">School</span></td> <td bgcolor = #E6F8EB><div align="right"><span class="xx_large_font"><strong><? echo $rs["school"]; ?></strong></span></div></td> </tr> <tr> <td colspan="2"><span class="xx_large_font">Remarks:<? echo $rs["remarks"]; ?></span></td> </tr> <tr> <td colspan="2"><span class="xx_large_font">Warnings:<? echo $rs["warnings"]; ?></span></td> </tr> <tr> <td bgcolor = #E6F8EB><span class="xx_large_font">Website</span></td> <td bgcolor = #E6F8EB><div align="right"><span class="xx_large_font"><strong><? echo $rs["weblinks"]; ?></strong></span></div></td> </tr> <tr> <td width="240" bgcolor = #dbeff8><span class="xx_large_font">Operator</span></td> <td width="240" bgcolor = #dbeff8><div align="right"><span class="xx_large_font"><strong><? echo $rs["operator"]; ?></strong></span></div></td> </tr> </table> <p class="xx_large_font"> </p> <p> </p> </body> </html> </html> Any help would be really appreciated. Thanks in advance. I have a simple detection for mobile devices and it works fine but it has gotten a bit bloated so I tried to put the list in an array. I don't get errors but it doesn't work. Here is what I tried $useragents = array("iPhone","iPod","incognito","webmate","Android","dream","CUPCAKE","blackberry9500","blackberry9530","blackberry9520","blackberry9550","blackberry 9800","webOS","s8000","bada","Googlebot-Mobile"); if (in_array(1, $useragents)) { $phones = strpos($_SERVER['HTTP_USER_AGENT'], $useragents); } if ($phones == true) { include_once './template/phones.php';} Please assist |