|
Global.asax files are used with ASP.Net applications, not PHP. You should post in that forum instead. PHP applications can do similar things, however, if you do something like:
<pre lang="PHP">
There really isn't a direct analog for the global.asax file in php.
|
|
|
|
|
I want to know how can I detect the client language so if it's arabic then leave it as www.mydomain.com but if it's english then redirect to www.mydomain.com/en?
|
|
|
|
|
If the user's browser is set up properly, you can use $_SERVER['HTTP_ACCEPT_LANGUAGE'] to find out which languages they prefer to use.
|
|
|
|
|
does PHP has global file similar to the global or config files in ASP.NET or I should add the language check in every php file in my website?
|
|
|
|
|
No, you would normally put anything you need to use on multiple pages into an include file, then load it on every page using include , require , include_once or require_once .
... unless you are using a framework, then there should be somewhere already that you can put code to execute on each request - but that will depend on the framework.
Or you could possibly skip checking it in PHP at all, and use a .htaccess file to redirect to a different path depending on the Accept-Language header.
|
|
|
|
|
when I check $_SERVER['HTTP_ACCEPT_LANGUAGE'] on Chrome it gives: "en-GB,en;q=0.8"
any idea what "q=0.8" means?
My logic is impeccable; my arithmetic lets me down.
|
|
|
|
|
It means Microsoft estimates your command of the English language is 80%, which is pretty good actually. More here[^]
|
|
|
|
|
Luc Pattyn wrote: It means Microsoft estimates your command of the English language is 80%
Microsoft? Surely it must be Google Chrome who made the estimate?
...and how does it (dare it!) make that estimate?!?
My logic is impeccable; my arithmetic lets me down.
|
|
|
|
|
You never have tried Google Translate, have you? Google knows zilch about languages.
|
|
|
|
|
You can redirect using user's timezone also..
|
|
|
|
|
Hi,
I am currentlly using this code to populate news from my database. I want to know how can I make the same paging the result with NEXT and PREVIOUS button?
<?php
$conn = mysql_connect('mysql.jassimrahma.com', 'jassimxxxxx', 'xxxxxxx');
mysql_select_db("jassimrahma", $conn);
$result = mysql_query("SELECT news_id, news_title, date_format(created_date, '%d %M %Y') as 'news_date' FROM news ORDER BY created_date DESC, news_id DESC", $conn);
$affected_rows = mysql_num_rows($result);
echo "<table width='100%' cellpadding='3' cellspacing='3'>";
while ($i < $affected_rows)
{
$news_id = mysql_result($result, $i ,"news_id");
$news_title = mysql_result($result, $i ,"news_title");
$created_date = mysql_result($result, $i ,"news_date");
echo "<tr>";
echo "<td align='center' valign='top'>";
echo "<img src='http://www.jassimrahma.com/images/news_arrow.jpg' alt='Jassim.com News' />";
echo "</td>";
echo "<td align='left' valign='top'>";
echo "<a href='http://www.JassimRahma.com/$news_id' target='_blank'>$news_title</a>";
echo "</td>";
echo "</tr>";
$i++;
}
echo "<tr><td align='center' valign='top'></td><td align='left' valign='top'><a href='http://www.JassimRahma.com/news' target='_self'><img src='images/more_news.jpg' alt='Technology News - JassimRahma.com' /></a></td></tr>";
echo "</table>";
?>
|
|
|
|
|
try the link. It might help you
|
|
|
|
|
Hi,
What's the best way to determine the mobile device then redirect to the /mobile?
Regards,
Jassim
|
|
|
|
|
|
|
Detecting if its a mobile device
Please follow the above link. It looks good
but how can I implement it? Do i have to put it in every page? is it possible to put it in one place for the entire application?
|
|
|
|
|
You could do either one of the two.
But I would suggest creating a generic php file with this piece of code in a method. Including that php file in every page and calling that method.
EG:
dection.php <-- contains the check + redirect
Sample index.php:
<?php include_once('detection.php');?>
<!-- rest of document -->
|
|
|
|
|
sorry but need more help plz
that mentioned code will be placed in a separet file.. that's file.. but it will be between tage? right? then followed by the if($mobile === true)?
so is the following code correct?:
<?php
function detect_mobile()
{
$_SERVER[
$mobile_browser =
$agent = strtolower($_SERVER[
if(preg_match(
$mobile_browser++;
if((isset($_SERVER[
$mobile_browser++;
if(isset($_SERVER[
$mobile_browser++;
if(isset($_SERVER[
$mobile_browser++;
$mobile_ua = substr($agent,0,4);
$mobile_agents = array(
);
if(in_array($mobile_ua, $mobile_agents))
$mobile_browser++;
if(strpos(strtolower($_SERVER[
$mobile_browser++;
// Pre-final check to reset everything if the user is on Windows
if(strpos($agent,
$mobile_browser=0;
// But WP7 is also Windows, with a slightly different characteristic
if(strpos($agent,
$mobile_browser++;
if($mobile_browser>0)
return true;
else
return false;
}
$mobile = detect_mobile();
if($mobile === true)
header(
?>
|
|
|
|
|
That would indeed work. If you put the entire function in the external php file and the code below in all files that need the check for mobile devices.
if (detect_mobile()) {
header('Location: blog');
}
Please note though that the redirect that you put in you code would not work as is. You would need to replace the 'blog' part with a URL to the mobile site.
|
|
|
|
|
I am now getting this error:
Parse error: syntax error, unexpected T_VARIABLE in /home/jassimrahma/JassimRahma.com/detection.php on line 4
this is what I put in my index.php 1st line:
<?php
include_once('detection.php');
if (detect_mobile()) {
header('Location: http://m.jassimrahma.com');
}
?>
and detection.php is here:
<?php
function detect_mobile()
{
$_SERVER[
$mobile_browser =
$agent = strtolower($_SERVER[
if(preg_match(
$mobile_browser++;
if((isset($_SERVER[
$mobile_browser++;
if(isset($_SERVER[
$mobile_browser++;
if(isset($_SERVER[
$mobile_browser++;
$mobile_ua = substr($agent,0,4);
$mobile_agents = array(
);
if(in_array($mobile_ua, $mobile_agents))
$mobile_browser++;
if(strpos(strtolower($_SERVER[
$mobile_browser++;
// Pre-final check to reset everything if the user is on Windows
if(strpos($agent,
$mobile_browser=0;
// But WP7 is also Windows, with a slightly different characteristic
if(strpos($agent,
$mobile_browser++;
if($mobile_browser>0)
return true;
else
return false;
}
?>
|
|
|
|
|
|
Put it in the initial page. That is the first page user would open. such as index page or login page.
If it figured out that the client device is mobile save that information to session. As a matter of fact its not a big deal. you dont even need to remember whether it is a mobile device or not. But If the set of functions are different for mobile and pc then you can use the session variable to determine about which function to call.
more over when it would redirect to page allocated for mobile do not put any link to those mobile page that redirect to pc pages
|
|
|
|
|
Please suggest best online resource to learn BackTrack 5's new functionality.
Thanks
|
|
|
|
|
This one[^].
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
How to configure mail in the xampp server. I am new to PHP and learning it . I wish to send emails where should I configure it in Xampp .Thanks in Advance
|
|
|
|