Hi; I have a mobile script from detectmobilebrowsers.com that will redirect the user to my mobile site however I also wish that when the URL "http://mysite.com/?mobile=no" is entered a session will be created that won't redirect the user on every page of my site...

$mobile=$_GET['mobile'];
	if(isset($_SESSION['mobile'])){
		if($_SESSION['mobile']==="no"){
			complete();
		}
	}
	if($_SESSION['mobile']==="no"){
		complete();
	}
	if($_SESSION['mobile']!="no"){
		checkMobile();
	}
	function checkMobile(){
		// MOBILE CODE TAKEN OUT TO SAVE SPACE
		gotoMobile();
	}
	function gotoMobile(){
		echo "<script>window.location='http://m.MySite.org/';</script>";
	}
	function complete(){
		echo "<h1 align='center'>Redirecting...</p>";
	}

Sorry if I seem confusing but in short terms: Mobile Detection (which is set)... make session mobile=no if user does wishes to view full site and when that session is created it is checked on everypage (same php script) and if I set my session for no mobile I want that to stay on everypage...

Thanks in Advanced :)

Member Avatar for diafol

As opposed to a separate mobile site you mat want to check out responsive design using media queries. Just a thought.

something like this?

//$mobile=$_GET['mobile'];

// user want normal site
if(isset($_GET['mobile']) AND $_GET['mobile']==="no"){
 		$_SESSION['mobile']="no"; 
		}
// we saved know: normalsite	
if(isset($_SESSION['mobile']) AND $_SESSION['mobile']==="no"){
 		 complete();
		}		
// we saved know: mobilesite
if(isset($_SESSION['mobile']) AND $_SESSION['mobile']==="yes"){
 		 gotoMobile();
		}	
// we  don't know so		
checkMobile();
	

function checkMobile(){
		// MOBILE CODE TAKEN OUT TO SAVE SPACE
		// this is a havy fuction so lets save the result to speed things up nex time
        if (  mobile )
        	{
        	$_SESSION['mobile']="yes";
        	gotoMobile();
        	}
        else {
        	$_SESSION['mobile']="no";
        	 complete();;
        	}
     	}
     	
function gotoMobile(){
		echo "<script>window.location='http://m.MySite.org/';</script>";
	}
function complete(){
		echo "<h1 align='center'>Redirecting...</p>";
	}

@ardav I don't like media queries because all cssfiles are loaded even if they are not used and on a mobile device you don't have bandwith to wast. just my 0.02$

Member Avatar for diafol

Fair comment - how about starting with css for mobile and scaling up?

I find that on mobile device you have to be very carefull not to put to much info on a page. There just isn't enough room to display more. This requeres a different aprouch to the html and other functonalty -> different .js
Makes more sence to me to put the php that doesn't change in to a sepearte file and include it

Member Avatar for diafol

Yes, using RD for complicated sites is probably a bad idea. However, if devised a few simple ones (mobile up) that seem to work OK on mobile and desktop. I try to avoid HTML changes as this should be semantic anyway. If you have loads of images, videos, animations etc, I can see why RD would be a headache, especially if the site is produced desktop down.

Here is an example of session issue. The point of reference, the answer is a session variable, come into play if you define a session variable $ _SESSION [" nextValidSubmission "]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.