Jump to content

Recommended Posts

An example straight from the manual:

 

function get_user_browser()
{
    $u_agent = $_SERVER['HTTP_USER_AGENT'];
    $ub = '';
    if(preg_match('/MSIE/i',$u_agent))
    {
        $ub = "ie";
    }
    elseif(preg_match('/Firefox/i',$u_agent))
    {
        $ub = "firefox";
    }
    elseif(preg_match('/Safari/i',$u_agent))
    {
        $ub = "safari";
    }
    elseif(preg_match('/Chrome/i',$u_agent))
    {
        $ub = "chrome";
    }
    elseif(preg_match('/Flock/i',$u_agent))
    {
        $ub = "flock";
    }
    elseif(preg_match('/Opera/i',$u_agent))
    {
        $ub = "opera";
    }
   
    return $ub;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/151110-users-browser/#findComment-793846
Share on other sites

Instead of starting a new topic, basically I had this working and storing it to mysql satabase, but working on it today and some how managed to stuff it up!

 

 

<?
include 'dbc.php';


	$userAgent = strtolower($_SERVER['HTTP_USER_AGENT']);

        // Identify the browser. Check Opera and Safari first in case of spoof. Let Google Chrome be identified as Safari.
        if (preg_match('/opera/', $userAgent)) {
            $name = 'opera';
        }
        elseif (preg_match('/webkit/', $userAgent)) {
            $name = 'safari';
        }
        elseif (preg_match('/msie/', $userAgent)) {
            $name = 'ie';
        }
        elseif (preg_match('/mozilla/', $userAgent) && !preg_match('/compatible/', $userAgent)) {
            $name = 'firefox';
        }
        else {
            $name = 'unrecognized';
        } 

$query = "INSERT INTO browser (browser) VALUES ('$name')";
mysql_query ($query, $linkme)
or die ("Could not add the data to table");
	   
	   
        ?>

 

It saying "Could not add the data to table", but I had it previously working and cannot remember what I changed!

Link to comment
https://forums.phpfreaks.com/topic/151110-users-browser/#findComment-797127
Share on other sites

Right got it to work, basically was a problem with mysql table, but now I have run in to another error, basically I've got a a session which is started when the user as logged in, this get the users_id. bascially i want to get that user Id and store it to my database, below is the code im trying:

 

<?
include 'dbc.php';


$user_id = $_REQUEST['uid'];
$page = strtolower($_SERVER['PHP_SELF']);
	$userAgent = strtolower($_SERVER['HTTP_USER_AGENT']);

        // Identify the browser. Check Opera and Safari first in case of spoof. Let Google Chrome be identified as Safari.
        if (preg_match('/opera/', $userAgent)) {
            $name = 'opera';
        }
        elseif (preg_match('/webkit/', $userAgent)) {
            $name = 'safari';
        }
        elseif (preg_match('/msie/', $userAgent)) {
            $name = 'ie';
        }
        elseif (preg_match('/mozilla/', $userAgent) && !preg_match('/compatible/', $userAgent)) {
            $name = 'firefox';
        }
        else {
            $name = 'unrecognized';
        } 

	  	$query = "INSERT INTO browser  (browser, page_visted, user_id) VALUES ('$name', '$page', '$user_id')";
		mysql_query ($query, $linkme) or die (mysql_error());
	   
	   
        ?>

 

uid is the name of my session that get the user’s ID, I’m using the following code to do this  $_SESSION['uid'] = $assoc['id'];

Link to comment
https://forums.phpfreaks.com/topic/151110-users-browser/#findComment-797165
Share on other sites

uid is the name of my session that get the user’s ID, I’m using the following code to do this  $_SESSION['uid'] = $assoc['id'];

 

Where?  I don't see any trace of sessions in your code.

 

Couple things I noticed:

  1) Don't use short tags () always use <?php

  2) Make sure you put "session_start();" at the top of your page before you assign the id from the session.

Link to comment
https://forums.phpfreaks.com/topic/151110-users-browser/#findComment-797183
Share on other sites

Right made the adjustments (cant believe i forgot the session tags) I am now not getting any error message but its not adding to the database. Below is the current code I have.

 

<?php 
session_start();

include 'dbc.php';


$user_id = $_REQUEST['uid'];
$page = strtolower($_SERVER['PHP_SELF']);
	$userAgent = strtolower($_SERVER['HTTP_USER_AGENT']);

        // Identify the browser. Check Opera and Safari first in case of spoof. Let Google Chrome be identified as Safari.
        if (preg_match('/opera/', $userAgent)) {
            $name = 'opera';
        }
        elseif (preg_match('/webkit/', $userAgent)) {
            $name = 'safari';
        }
        elseif (preg_match('/msie/', $userAgent)) {
            $name = 'ie';
        }
        elseif (preg_match('/mozilla/', $userAgent) && !preg_match('/compatible/', $userAgent)) {
            $name = 'firefox';
        }
        else {
            $name = 'unrecognized';
        } 

	  	$query = "INSERT INTO browser  (browser, page_visted, user_id) VALUES ('$name', '$page', '$user_id')";
		mysql_query ($query, $linkme) or die (mysql_error());
	   
	   
        ?>

Link to comment
https://forums.phpfreaks.com/topic/151110-users-browser/#findComment-797197
Share on other sites

Right made the adjustments (cant believe i forgot the session tags) I am now not getting any error message but its not adding to the database. Below is the current code I have.

 

What does the error message say?

 

uid is the name of my session that get the user’s ID, I’m using the following code to do this  $_SESSION['uid'] = $assoc['id'];

 

I'm confused...  In the statement above you claimed you were using sessions, but in your code you don't use them.  If you're referring to this line, that's not using sessions.

 

   $user_id = $_REQUEST['uid'];

Link to comment
https://forums.phpfreaks.com/topic/151110-users-browser/#findComment-797209
Share on other sites

What does the error message say?

 

There isn't one. Just dont add to the database

 

I'm confused...  In the statement above you claimed you were using sessions, but in your code you don't use them.  If you're referring to this line, that's not using sessions.

 

I've declared the session when the user logs in this is on the home page. I will post my homepage hopefully that'll clear up what I'm tryna explain

 

Loginpage/hompage

 

<?php 
session_start();

include 'dbc.php';
include 'browser.php';


$user_name = mysql_real_escape_string($_POST['uname']);

if ($_POST['Submit']=='Login')
{
$md5pass = md5($_POST['pwd']);
$sql = "SELECT id,user_name FROM users WHERE 
            user_name = '$user_name' AND 
            user_pwd = '$pwd' AND user_activated='1'"; 
         
$result = mysql_query($sql) or die (mysql_error()); 
$num = mysql_num_rows($result);
$assoc = mysql_fetch_assoc($result);

    if ( $num != 0 ) { 

   $_SESSION['user']= $user_name;
   $_SESSION['uid'] = $assoc['id'];
      
      list($user_id,$user_name) = mysql_fetch_row($result);

      
         
      if (isset($_GET['ret']) && !empty($_GET['ret']))
      {
      header("Location: $_GET[ret]");
      } else
      {
      header("Location: index.php");
      }
      //echo "Logged in...";
      exit();
    } 

header("Location: index.php?msg=Invalid Login");
//echo "Error:";
exit();      
}

?>

 

Link to comment
https://forums.phpfreaks.com/topic/151110-users-browser/#findComment-797221
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.