page load

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
roice
Forum Commoner
Posts: 35
Joined: Tue Mar 02, 2010 9:14 am

page load

Post by roice »

Hello,
I built PHP function that recognize if the user OS is mobile or regular computer. if its mobile the script will redirect the user to the site mobile version. the problem is that the site first got loaded and than after it finish it redirect the user to the mobile version.
How can I set it so my PHP function will load first?

Thank you in advance,
Roi.
dejvos
Forum Contributor
Posts: 122
Joined: Tue Mar 10, 2009 8:40 am

Re: page load

Post by dejvos »

Do you redirect by header() function?

The code bellow could work.

Code: Select all

<?php
if(is_mobile($_SERVER)){
header('Location: mobile.site.com');
exit;
}else{
show_page();
}
?>
Last edited by dejvos on Mon Jul 19, 2010 8:31 am, edited 1 time in total.
roice
Forum Commoner
Posts: 35
Joined: Tue Mar 02, 2010 9:14 am

Re: page load

Post by roice »

Thanks dejvos,
Do I have to put the header code in the top of my page/code?
Imean- before I print anything to the screen...?
dejvos
Forum Contributor
Posts: 122
Joined: Tue Mar 10, 2009 8:40 am

Re: page load

Post by dejvos »

Yes that's it,

you can manipulate with a header before you print anything else.
roice
Forum Commoner
Posts: 35
Joined: Tue Mar 02, 2010 9:14 am

Re: page load

Post by roice »

OK, so I must put it in the top of my pages.
By the way, is there any chance that you know how to write the code above in ASP?
dejvos
Forum Contributor
Posts: 122
Joined: Tue Mar 10, 2009 8:40 am

Re: page load

Post by dejvos »

Unfortunately I don't know that. Try google.
roice
Forum Commoner
Posts: 35
Joined: Tue Mar 02, 2010 9:14 am

Re: page load

Post by roice »

OK,
Thank you!
Post Reply