Forum Moderators: coopster

Message Too Old, No Replies

How to store each array value from HTTP Header?

         

toplisek

7:11 pm on Jan 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Script is:
<?
$accept = $_SERVER["HTTP_ACCEPT"];
$user_agent = $_SERVER["HTTP_USER_AGENT"];
$accept_charset = $_SERVER["HTTP_ACCEPT_CHARSET"];
$accept_language = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
$x_wap_profile = $_SERVER["HTTP_X_WAP_PROFILE"];
$profile = $_SERVER["HTTP_PROFILE"];
echo 'accept='.$accept.'<br />'."\n".
'accept='.$user_agent.'<br />'."\n".
'accept='.$accept_charset.'<br />'."\n".
'accept='.$accept_language.'<br />'."\n".
'accept='.$x_wap_profile.'<br />'."\n".
'accept='.$profile;
?>

How to store each value in array and than store in db each separate value by sign: '',''

Example:$accept_charset has:
accept=ISO-8859-2,utf-8;q=0.7,*;q=0.7

eeek

5:05 am on Jan 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Look at the explode function.

toplisek

8:01 pm on Jan 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



what is explode function?

coopster

5:48 pm on Jan 26, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Have you considered serialize [php.net] instead?

toplisek

7:19 am on Jan 27, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi,
I have tried as sample:
$accept_charset = $_SERVER["HTTP_ACCEPT_CHARSET"];

$accept_charset = array (serialize($charset_data), $_SERVER["HTTP_ACCEPT_CHARSET"]);

Is this correct?

How to store each value in separate variable like encoding value?

coopster

6:54 pm on Jan 27, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



It really doesn't matter how you do it, you just need to know what it looks like going in so you know how to use it on the way back out. If it were me I would likely push it all into an array using the latter part of the HTTP_ indexes as my index.
$http = array(); // initialize it 
$http['accept'] = $_SERVER["HTTP_ACCEPT"];
$http['user_agent'] = $_SERVER["HTTP_USER_AGENT"];
$http['accept_charset'] = $_SERVER["HTTP_ACCEPT_CHARSET"];
$http['accept_language'] = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
$http['x_wap_profile'] = $_SERVER["HTTP_X_WAP_PROFILE"];
$http['profile'] = $_SERVER["HTTP_PROFILE"];
$serializedHttp = serialize($http);

Stuff the serialized http variables into your column in the database [webmasterworld.com]. When you retrieve the data you unserialize it and the variables you have stored are once again in your array:
$http = unserialize($row['yourTableColumn']);

eeek

11:57 pm on Jan 27, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



what is explode function?

Don't know. I do know about the explode function:

[us2.php.net...]

toplisek

8:33 am on Jan 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi,
I have gathered all code together. Is this correct way or/and can be improved? this way wil track also Title of website.

<?

$page='http://www.mydomain.com/';
preg_match('/<title>([^<]+)</title>/', $page, $matches);

$http = array(); // initialize it
$http['accept'] = $_SERVER["HTTP_ACCEPT"];
$http['user_agent'] = $_SERVER["HTTP_USER_AGENT"];
$http['accept_charset'] = $_SERVER["HTTP_ACCEPT_CHARSET"];
$http['accept_language'] = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
$http['x_wap_profile'] = $_SERVER["HTTP_X_WAP_PROFILE"];
$http['profile'] = $_SERVER["HTTP_PROFILE"];
$serializedHttp = serialize($http);

//will be available as an array on the server.
session_start();
$db_host = "localhost";
$db_name = "...";
$db_username = "...";
$db_password = "...";

$conn = mysql_connect($db_host,$db_username,$db_password) or die("Could not connect to Server" .mysql_error());
mysql_select_db($db_name) or die("Could not connect to Database" .mysql_error());

$serializedHttp= serialize($http);
$query = "INSERT INTO globalvar VALUES ('','$matches','$accept','$user_agent','$accept_charset','$x_wap_profile','$profile')";
mysql_query($query) or die("query: $query<br>" . mysql_error());
mysql_close();

//unserialize it and the variables you have stored are once again in your array
$http = unserialize($row['globalvar']);
?>