digital-ether 399 Nearly a Posting Virtuoso Team Colleague

It again doesn't work ?

var xmlObj = xmlHttp.responseXML.documentElement;
                alert(xmlObj);

i put this alert message.when explorer it displays [Object] and in Mozilla it displays [Object element]

after this code i put

master.value=xmlObj.childNodes[0].firstChild.nodeValue; 
                alert(master.value);

then this alert is not working i think this makes an exception ?

Yes, the exception occurs at

master.value=xmlObj.childNodes[0].firstChild.nodeValue;

it seems.

In your catch block place an

alert(e);

So we can see what the exception is.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

kk thankzzz.....
is there any method in java like "selectionStart"

Do you want to get the Text that the user has currently selected?

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

I misspelled responseXML. It should be

var xmlObj = xmlHttp.responseXML.documentElement;
digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Try removing the different DOM parsing functions and just have XMLHttpRequest return XML.

function ajax()
{
var name=document.getElementById('name').value;
getXmlHttp();
var myurl="<%=request.getContextPath()%>/AjaxController?type=ajax&name="+name;
alert(myurl);
xmlHttp.open("GET", myurl , true);
xmlHttp.onreadystatechange = useHttpResponseSuggestId;
xmlHttp.send(null);
}

function useHttpResponseSuggestId()
{
if (xmlHttp.readyState == 4)
{
if(xmlHttp.status == 200)
{
var textout = xmlHttp.responseText;
alert(textout);

var xmlObj = xmlHttp.responseXml.documentElement;

var master = document.getElementById('ajaxname');
master.value=xmlObj.childNodes[0].firstChild.nodeValue; 


}
}
}
digital-ether 399 Nearly a Posting Virtuoso Team Colleague

thankzzz....
am using struts framework and <layout:textarea> is provided in it..
it has no property like "id" (ie..<textarea id="">)....
its syntax is like this..
<layout:textarea property="' key=""></layout:textarea>

"property" is used to represent the textarea ....

and wht is ment by "getElementById"..plzzz help

You'll need to find out how to render HTML attributes using struts.

-----

Re: getElementById

Once the HTML is rendered on the page, the browser will create a DOM (Document Object Model) representation of the HTML for programmatic access from JavaScript.

The DOM is a W3C specification that models XML data as Objects. It is quite simple. Take for example some XML:

<root>
  <child1 id="child1_id">Im a child of root</child1>
  <child2 id="child2_id">
    <subchild1 id="subchild1_id">Im a child of child2</subchild1>
  </child2>
</root>

There are many ways to model this XML document. The model used in browsers is the DOM. So in JavaScript, if you have a reference to the XML Document you could traverse it and select elements (DOM nodes) as well as manipulate it.

If the XML document reference is: XMLDoc, then the root would be:

XMLDoc.documentElement;

<child1> would be:

XMLDoc.documentElement.firstChild

or

XMLDoc.documentElement.childNodes.item(0);

or

XMLDoc.documentElement.getElementsByTagName('child1').item(0);

or

XMLDoc.documentElement.getElementsById('child1_id');

(These are all example of DOM methods for selecting Nodes/Elements).

getElementsById('child1_id') selects the child Node/Element with the id attribute 'child1_id'.

In HTML, the DOM is already created by the browser and available through document object. So you can use document to select any HTML element using …

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

btw: once you have the value of the string, you need to do some matching with regex or similar to get what you want out of the string.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

haii friends....
i want to select a particular string from textarea...i need it in javascript....
am using the tag <layout:textarea>
i did not need the whole ,but only a part...plzz help me...

What markup language are you using?

In HTML a text area is just <textarea>.

You'll need a reference to the DOM node representing the text area, example:

textarea HTML

<textarea id="mytext">
</textarea>

select whats inside the textarea with JS

// get the textarea by its id
var txt = document.getElementById('mytext');
// theres the contents inside the textarea
var value = txt.value;
digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Problem is when i run this code in IE it works fine.It takes the second try method in the index.jsp
When it comes to mozilla it throws an exception from the first try method as "Please use a new browser! This browser does not support XML!"

so can u help me please

Do you have firebug installed on Firefox?

Try viewing your XMLHttpRequest in Firebug and seeing if the response is well formatted.
What version of FF is it btw?

You can also tell if its well formatted or not by testing for the existence of xmlHttp.responseXML.

You should really be using xmlHttp.responseXML anyway, since any browser supporting XMLHttpRequest will support the responseXML property.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

You can also replace:

var x= new DOMParser().parseFromString(textout, 'text/xml');
xmldom.async="false";
xmldom.loadXML(x);
alert(xmldom);
xmlObj=xmldom.documentElement;

with:

var xmldom = new DOMParser().parseFromString(textout, 'text/xml');
xmlObj=xmldom.documentElement;

this is the correct usage of DOMParser().

It is however still better for you to get the XMLHttpRequest response as XML instead of the way it is done in your example where you are retrieving it as Text and then using browser specific XML/DOM parsers to convert the text to XML.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Actually the problem may be in this code

if(xmlHttp.status == 200)
{
var textout = xmlHttp.responseText;
try
{
var x= new DOMParser().parseFromString(textout, 'text/xml');
xmldom.async="false";
xmldom.loadXML(x);
alert(xmldom);
xmlObj=xmldom.documentElement;
var master = [document.getElementById('name'),document.getElementById('password'),
document.getElementById('realname'),document.getElementById('email'),
document.getElementById('title'),document.getElementById('desc')];
var length=xmlObj.childNodes.length;
for(var i=0;i<master.length;i++)
{
master.value = xmlObj.childNodes.firstChild.nodeValue;
}
}

I am getting the textout value as xml in IE but didnt get the values in Mozilla browser

Good Call.

You should use

var textout = xmlHttp.responseXML;

instead of

var textout = xmlHttp.responseText;

and remove the DOMParser() functions.

You have to either make sure your server sends the correct XML headers when serving the response.

eg in PHP:

header('Content-Type: text/xml');

OR you can force the browser to treat the response as XML.

xmlHttp.overrideMimeType('text/xml');

Then the XML document will be available for traversal/manipulation using DOM Interface.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Sorry if I wasn't clear. DOM nodes do not have a native addChild() method. You have a create a function that will do that for you.

See: http://www.quirksmode.org/blog/archives/2005/12/xmlhttp_notes_c.html

First try doing:

function handleInfo(){
    if(http.readyState == 4){
        var response = http.responseXML; // get XML, not TXT
        document.getElementById('ChtPlc').appendChild(response.documentElement.cloneNode(true)); // add Child Nodes, not innerHTML
    }
}

That will probably only work in Firefox. But its a starting point.

Another solution is to iterate through each xml Node in the response, recursively, and create the corresponding DOM elements in your Document.

eg:

/**
* Clones XML nodes to the current Document's DOM
*/
function cloneXMLtoDOM(Node) {
	var DOMNode;
	if (Node.nodeName == '#text') {
		DOMNode = document.createTextNode(Node.data);
	} else {
		// clone root node
		DOMNode = document.createElement(Node.nodeName);
		// clone the attributes
		for(var i = 0; i < Node.attributes.length; i++) {
			DOMnode.setAttribute(Node.attributes[i].nodeName, Node.attributes[i]);
		}
		// recursively clone the child nodes
		if (Node.hasChildNodes()) {	
			for(var i = 0; i < Node.childNodes.length; i++) {
				DOMNode.appendChild(cloneXMLtoDOM(Node.childNodes[i]));
			}
		}
	}
	return DOMNode;
}

I haven't tested that fully so there may be bugs. Tested in FF2.0, IE6 and IE7.

This is how you would implement it in your code:

// after including the cloneXMLtoDOM() function

function handleInfo(){
    if(http.readyState == 4){
        var response = http.responseXML; // get XML, not TXT
        document.getElementById('ChtPlc').appendChild(cloneXMLtoDOM(response.documentElement)); // add Child Nodes, not innerHTML
    }
}

A good DOM ref: http://www.howtocreate.co.uk/tutorials/javascript/domstructure

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Can't see why your codes doesn't invoke xmlHttp=new XMLHttpRequest(); bit odd.

var xmlHttp;
function getXmlHttp()
{
try {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
try {
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
alert("Please use a new browser!");
return false;
}
}
}
}

Just a suggestion:

What you want to do when creating an XMLHttpRequest() Object is to test for the W3C implementation before IE6 and older implementation. The reason is that IE7 still supports the IE6 XHR object which is created via ActiveX.

Simple example to replace the code above. See if it works:

xmlHttp=null;
function getXmlHttp() {

xmlHttp=null;
// code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  xmlHttp=new XMLHttpRequest();
  }
// code for IE
else if (window.ActiveXObject)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
else alert("Please use a new browser!");
return xmlHttp;
}

ref: http://www.w3schools.com/xml/xml_http.asp

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

I built a web page form, where the action is set to "mailto" to my email address. I already scripted the client side using Javascript and I wish to know if I can use Javascript for server side scripting as well?

I do not know PHP, nor Perl, and prefer not to learn another scripting language, simply, because I have not the time.

Thanks for any comment.
ineuw

Yes, you can use JS server side. However, you'll probably be surprised that it may not handle like the client side JS since you are working with a different environment and model. Instead of an Event based model it would be just a Request/Response model (or whatever it would be called).

I haven't used it myself, but just guessing.

PHP is actually a very simple language. If you grasp JS, PHP should be easy with a good reference to use. It may be easier that server side JS.

Usually, its how the language is implemented that takes time to learn. PHP on the client side for instance is a pain since its totally object oriented, when there are better languages to handle that. PHP on the server side is simple since it is very good at manipulating xHTML as a string.

If I were to guess, JS on the server side would mean manipulating HTML as an Object. It would be quite tedious. JS does not handle strings as well as PHP also.

Just giving you …

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

I don't think you can use is_int() since all HTTP data is considered strings. There is no type distinction in HTML FORMS or HTTP GET/POST responses.

You could check for range:

if ($var > 0 && $var < 100) {

}

Or you can use something like:

if (intval($var) > 0) {}

this would make strings equal to 0. So would work unless you also wanted to test specifically for 0.

if (intval($var) > 0 || $var === '0') {}

if anything, you could revert to using regex. But for simple tests I wouldn't invoke Regex as its a pretty heavy application for such a simple task.

I'm sure there is a simple solution to your problem.

OmniX commented: Thanks for the helpful advice =) +1
digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Thanks, In your reply I see that you did not understand my question well, I do not want to remove a text and that is not my problem.
My problem is that the text being removed and being created automatically, So If you have the answer please give me it with one or two examples. :-/

I thought your problem was:

The problem was:
when the user selects a text ... the text becomes unselected automaticially !!

This will happen because of:

function handleInfo(){
    if(http.readyState == 4){
        var response = http.responseText;
        document.getElementById('ChtPlc').innerHTML = document.getElementById('ChtPlc').innerHTML+response;
    }
}

you want to actually insert DOM nodes, not replace innerHTML.

function handleInfo(){
    if(http.readyState == 4){

        var response = http.responseXML; // get XML, not TXT

        document.getElementById('ChtPlc').addChild(response); // add Child Nodes, not innerHTML
    }
}

Where Element.addChild() is a pseudo function that will clone your XML and insert it as a child of document.getElementById('ChtPlc').

Sorry if I'm misreading your question? I can be a bit dim at times..

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Attach DOM nodes to your Document instead of replacing innerHTML. Any text selection will disappear when you remove text, then replace it with new text.
When attaching DOM nodes, only the added HTML Node is injected into your HTML, and the text selection will remain. It will also not flicker in older browsers (innerHTML replacement on an element with overflow had that bug).

It is also more efficient when you'll run into a long list of element. Its easier to work with also as its actual DOM elements and not dead HTML injected via innerHTML.
Eg: if you get 1000 elements, you may want to trim the last one off, thats easier with actual dom nodes.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Thanks digital-ether,

Did you have any example, because i couldn't understand how we can display user profile details? FB Server returned only $userId then we should pass this $userId in FBML "<fb:name uid='".$userId.
"' useyou='false' possessive='false'/>" and FBML could only parse by the FB Server. And my server couldn't capable to rendered the FBML to HTML. That's the problem currently i faced it.

To get user info you have to use the "facebook.users.getInfo" method I believe. Pass it the userid and get the info.

I think you don't need to parse the FBML on the server side. I haven't read the docs, but I don't see why they would put this complexity on the developer. Instead you'd probably just parse the FBML to the client side that load's a widget or something like that in place of it. (I really don't want to read their docs on a proprietary XML format that is supposed to make your life easier.. lol)

If you really have to parse FBML then you should be able to with PHP. FBML is just XML.
see: http://www.php.net/xml

Why not just use their REST API?

If you use their REST API it may be simpler. REST is very simple and is a standard. FBML means a learning curve for something you cant use on other projects.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

By the way, they have a client library on this page: http://developers.facebook.com/resources.php

I'm sure there are some examples in there.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Just looked at the Facebook API briefly.

It looks like the login is the only thing that has to be implemented by the facebook website and not your application. You have to generate an Authentication Token for a user, then pass this token to facebook.com/login.php. After the user authenticates, you then request the users sessionid through an API Request.

After that, you just include the users sessionid in each request to facebook's api. You'll get results that you can then embed in your HTML.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Basically my question is that can i do call the Facebook API and showing the result in my server or not. The scenario is that we can make the request and call FB API as a client and When FB Server get back the response to my server then we can display all the responded result in HTML format to in my server.

You Can. (Unless your PHP install does not allow outgoing socket connections).

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Only other thing I can think of that would require more than basic PHP is if they require secure HTTP such as Secure Socket Layers (SSL) or some form of encryption not built directly into core PHP. This would then require extra libraries to be compiled into PHP. PHP supports open source libs for most all the major security enhancements of HTTP. It just depends on your ability to install them on your system.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Hi Everyone,

I just want to know that can I implement a Facebook api on my server? It means all the facebook feature should be display in my server. Please anyone have any knowledge about this featured had provided by facebook then please guide me.

Thanks
Dheeraj

In general, to access remote HTTP Based API's, PHP needs to allow outgoing socket connections. This is a setting in PHP.ini named "allow_url_fopen" (I'm quite sure thats what its called). Most hosting will have this setting to yes but a few shared hosting will not allow it.

Other than that, I don't believe you need anything else.

What you need to do to be sure, is download any sample PHP scripts they may have and test it on your server.

Most the time, sample scripts provided by API providers will use CURL, which is less availalbe on shared hosting then PHP sockets/streams. So you can always replace any CURL with the native PHP equivalents such as fsockopen(), fopen(), file_get_contents() etc.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Ok, after doing some reading, I think I got an idea of how to structure the table, client_logs. I can have a row for the client, with a specific date, and then all the fields from the page for that date. Then when I want to pull up a specific day of log entry, I can query the db with SELECT * FROM client_logs WHERE client='value', date='value' That is what I got from my research on this, but it looks like digital-ether, has a slightly different method, which sounds like it might save time in the long run. Any suggestions/critiques/ways to do it better on this approach?

Thats pretty much the same as what I mentioned.
Do you have a separate table for clients?

So you're query would be like: SELECT * FROM client_logs WHERE client={clientid}, date='{timestamp}' LIMIT 1 where the {clientid} is the index of the client's row in the clients table and {timestamp} is any date/time format.

Note the LIMIT 1. It's good practice to let the DB know that you only want a single entry. The reason is that the DB stops iterating through its index as soon as it reaches the first valid row. Otherwise, it goes through all rows. If you have something like 100 000 rows, this makes a huge difference.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

I don't really know how to explain this easily. I guess I will layout the project I am trying to do, and the problem I am having with it, and maybe someone could explain it better to me.
I am trying to build an online food journal for a fitness/nutrition company. I have a form page made out that will allow their clients to input their eating habits for the day.
http://befit4riding.com/food_journal.html
I was thinking that I would have a db for each client, and each day would be a new table. I need to be able to store each day of data and keep it accecible for a later time. I also need to email the data to the company each time new data is submitted. Turns out, the server I am working on only allows 1 db. So how do I organize the tables so that they are all under the same client, but I can have multiple clients? Is there some kind of 'sub-table' (db/table/sub-table)? If I am not explaining myself adequately, please ask some specifics and I will be happy to try again.

notes on the page. I didn't have it automatically input the date, because sometimes people don't update everyday, so they need to be able to come in and put in multiple days at once, but have the correct date for each one. Eventually I might put in a calendar function, but I would have to learn that one and …

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Is it possible to include the character < in a regular expression? I don't seem to be able to find a reference to it anywhere and am unable to build a regex with just this one character.

Yes, there is nothing special about the < character.

eg:

preg_match("/</", "<div>some text</div>", $matches);

Is there a specific way you're using <?

The most common use in PHP is:

preg_match("/<(.*?)>/", "<div>some text</div>", $matches);

which matches: <div> and </div>.

Taffd commented: Specific and to the point. Helped a lot. +1
digital-ether 399 Nearly a Posting Virtuoso Team Colleague
foreach($vised as $vised1)
{
	 
 $check_array = array_search($vised1, $vised);
  if (!$check_array)

There is an error (2 actually) in the logic in the part above.

The check $check_array = array_search($vised1, $vised); always checks for a value $vised1 that is always present in $vised, since the foreach() loop goes through each index of $vised, and saves a copy of the value to $vised1.

The part above can be rewritten as:

foreach($vised as $check_array=>$vised1)
{
 if (!$check_array)

The other problem I think is that you're thinking $check_array returns true or false? Instead it returns the index. So if you were actually checking if a value existed in an array, you'd use:

if ($check_array !== false)

which will also check for the TYPE to make sure it is the same type on each side of the comparison operator.
Otherwise when an index such as 0 or ' ' exist in an array, those indexes are casted to boolean before the comparison is made, thus you get a false when the index actually exists.

I'm not sure exactly how you're going about this, but it should probably something like:

$links = mysql_query("select * from tracking"); // is this all the links (the larger set)?
$clicked = mysql_query("select * from members where members.username ='toasty'"); // is this the links already clicked (smaller set) ?

$x = mysql_fetch_array($clicked); // id's of clicked links?

$vised = explode(",",$x['adid']);


		while ($row = mysql_fetch_row($links))
		{
			$check_array = array_search($row[1], $vised); // check if column 1 exists in the visited …
digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Hi,
I am creating a folder through php code. but the permissions for that folder is not setting.
I identified the problem is apache is different usergroup,FTP is different user group.
so i want to know how can i change user group of apache. or how can i add apache,php in root access.

Regards
Bala

Do you have root access?

If so you can use chown to change the ownership the file to the one you need (such as your ftp user).
http://en.wikipedia.org/wiki/Chown

If you don't, you might want to consider using an ftp client written in PHP to create directories/files for you, with your ftp user. This way you can then access it via ftp yourself.
http://www.radinks.net/ftp/php/

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Have you included the MIME type header to the .php file so that its treated as xsl?

If not, in your .php file put:

header('Content-Type: text/xml');

see: http://www.dpawson.co.uk/xsl/sect2/mimetypes.html
for others.

make sure you place the header() call before any output is made, or else see ob_start() in the php.net manual. http://php.net/ob_start/

If you would rather use an xsl extension you can use mod_rewrite in apache to have the .xsl resource handled by your .php file.

Dsiembab commented: thanks +1
digital-ether 399 Nearly a Posting Virtuoso Team Colleague

inititially the cms, the php will follow with time.

If your site is a blog site, wordpress (http://wordpress.org/) is really good.
If you have a more general site, Joomla (http://joomla.org/) and Drupal (http://drupal.org/) are the top ones for PHP.

Heres some resources on choosing a CMS:

http://www.cmsmatrix.org/ - select a list of CMSs and cross reference features.
http://opensourcecms.com/ - Try demo's of open source CMS's.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

If you want to write the PHP code yourself, you'll need to learn:

1) How to create HTML Forms.
2) How to have PHP handle HTML form submission.
3) How to connect to a database with PHP
4) Saving data to the database
5) Retrieving data from the database
6) Creating a Login Form and Authenticating Login requests
7) Persist HTTP Requests using PHP Sessions

The other option is to use a CMS, then you'll have to learn how to setup the CMS, and the admin interface of the CMS.

Which would you prefer?

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

thank you so much for helping me paksender....

digital ether: That could quite possible be it.. I was on a windows server and I just switched it to unix but I dont know if it is completely switched right now.

The domain is still resolving to an IIS server. Did you change the DNS entries for your domain to point to the new server?
I just tested right now and I still get a response from an IIS server.

HTTP Request:

GET /index2.php HTTP/1.0
HOST: arbortreeland.com

HTTP Response:

HTTP/1.1 200 OK
Server: Microsoft-IIS/5.0
X-Powered-By: ASP.NET
Date: Sun, 01 Jul 2007 09:51:43 GMT
Content-Type: application/octet-stream
Accept-Ranges: bytes
Last-Modified: Fri, 29 Jun 2007 12:53:49 GMT
ETag: "1077a4894cbac71:3202"
Content-Length: 7111

I think the problem is that you believe you're testing the page on the new host, but in fact the domain still resolves to the old host.

A whois shows:

NS7.WORLDNIC.COM      	 205.178.190.4   	 
 NS8.WORLDNIC.COM    	205.178.189.4

as the DNS.

Sometimes it takes a day or two for DNS entries to propagate through the differnet DNS servers around the globe.

and what do you mean set up php on the server... I am paying a hosting site and they should do that right?

I mean: Is PHP installed on the machine running the IIS server?
The particular page is being handled by ASP.NET and not PHP.

You can see it in this response header:

X-Powered-By: ASP.NET

If it was handled by PHP it would be something like:

X-Powered-By: PHP/{php …
digital-ether 399 Nearly a Posting Virtuoso Team Colleague

When you send a HTTP Request to the URL, you get the HTTP Response Headers:

HTTP/1.1 200 OK
Server: Microsoft-IIS/5.0
X-Powered-By: ASP.NET
Date: Sat, 30 Jun 2007 14:28:56 GMT
Content-Type: application/octet-stream
Accept-Ranges: bytes
Last-Modified: Fri, 29 Jun 2007 12:53:49 GMT
ETag: "1077a4894cbac71:3202"
Content-Length: 7111

Notice:

Content-Type: application/octet-stream
Accept-Ranges: bytes

It does not look like your server is not sending out the correct response headers. Its treats the PHP files as a download.

Is PHP even set up on the server? Have you tried other PHP scripts successfully?

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

A good reference to look at is the Smarty template engine and see how its implemented.

http://smarty.php.net/crashcourse.php

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Yeah, I'm wondering which is the lesser evil. With the prevalence of high-speed internet access, I'm thinking that less than 4 KB worth of cookie data being passed via HTTP isn't much of a concern at all when I consider the options of storing user preferences and selections. I really see three options...

Cookies
Pros
: places the majority of the resource consumption and work on bandwidth and the client PC and not on the Web application. This seems good for Web application performance.
Cons: must be supported/enabled in the user agent, limited storage space, varying implementations of the RFC, larger HTTP requests consume more bandwidth, vulnerable to modifications

Session
Pros
: places the majority of the resource consumption and work on the server and not the client, decreases work performed by the client PC, reduces the size of HTTP requests
Cons: vulnerable to hijacking, increases the work performed by the server which can become an issue w/ a multi-user application

Database & File System
Pros: no reliance on cookies or sessions which can be unreliable for various reasons and introduce security concerns
Cons: disk access and database reads/writes are typically some of the slowest and costliest computing operations

Thoughts? What's most common? What's the best balance between resource allocation (server/client processing, memory, disk and bandwidth) application performance and security for the most common case?

I think you should sent the most frequently use stuff in cookies but less accessed preferences in the server's disk or db.

They thing about cookies …

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Well, it appears there is a total size (4 KB) and total number limit (20) per domain.

There's a way around the number limit by creating a cookie dictionary. I've done this with ASP in the past. It was not hard. I cannot find any help on Google about creating/manipulating cookie dictionaries in PHP.

Any ideas on how to implement a cookie dictionary like is possible in ASP (http://www.webcheatsheet.com/asp/cookies.php)?

Reference
http://support.microsoft.com/kb/306070

You'd have to look at how ASP implements cookie dictionary in HTTP.
PHP has a feature as you probably know of parsing "HTTP params" with array syntax as arrays. I assume this is similar to what ASP does, but parses arrays inside cookie values..

What you can do is put all the settings into an array and then convert this array into a notation that saves the array indices and values such as with PHP's serialize function, or JSON for example.

You can then "unserialize" the cookie data when you retrieve it.

There is an overhead with methods such as serialize() and JSON that you can eliminate if you just use a simple notation such as url-encoded parameters...
eg: var1=value&var2=value2 and then parse that..

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Presuming that cookie size (disk+memory) is the culprit in IE6/IE7, which seems like the most likely cause at this point, this spawns a whole other conversation about how to get the cookie size down in order to make the Web application more reliable in IE6/IE7 and balance security.

I've been in the practice of encrypting the values that I store in cookies. It always seemed to me that this enhances Web application security by not revealing some of the inner workings of the Web application even though the revelations might not be significant.

I've always considered cookies and their values as a potential platform for launching an attack on a Web-based application. So, I've always though it a best-practice for Web application security practice to encrypt cookie values.

Thoughts?

You could move your cookies to the database or the filesystem. This also removes the unnecessary HTTP bandwidth used in sending the cookies back to your server on each request.

You can get away with having just one session cookie, and one permanent cookie.
Both of these cookies are just hashes that point to the data saved in the database or filesystem...

eg: setting the data

<?php

$salt = 'longsecret...';
query("insert into http_clients ...");
setcookie('http_client_id', sha1(mysql_insert_id().$salt));

?>

eg: getting data

<?php

if ($http_client_id = isset($COOKIE['http_client_id']) ? $COOKIE['http_client_id'] : false) {

// got data in db for this client

$rows = query("
select *
from http_clients
where sha1( concat( id, '$salt' ) ) = '$http_client_id'
limit 1
");

} …
digital-ether 399 Nearly a Posting Virtuoso Team Colleague

The cookies is getting real long. IE has a shorter limit on cookies saved for a domain, I believe. Could be you're running out of space in IE. Should look that one up..

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Yeah, I don't think IE is not going through a proxy like you are thinking. What you are seeing in the HTTP activity is actually a result of Fiddler fiddling with things.

It sounds like you have used Fiddler before. Take a look at your IE proxy settings. Under most circumstances, you should not have any proxy settings. Now, start the Fiddler application. Now, go look at your IE proxy settings again. You should note how Fiddler has modified the settings in order to listen to all the HTTP traffic taking place within IE.

Fiddler acts "like a proxy" so that it can look at all the HTTP traffic. It modifies the proxy configuration of IE and points the HTTP traffic to the loop back address (127.0.0.1:8888). This is how it listens to everything that is going on. The program title is actually "Fiddler - HTTP Debugging Proxy".

As for the "Connection: close", this does appear to be a part of the HTTP/1.1 standard. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html.

Let me know what you think.

Sincerely,

Ben Roberts
Azalea Technology

I haven't used fiddler before. I recommend you use something like CAIN or Wireshark (formerly Ethereal). A "sniffer" that has to create a HTTP proxy that cannot fully implement HTTP 1.1 defeats the purpose.

Yes, Connection: close is defined in HTTP 1.1 specs. But HTTP 1.1 keeps a persistent TCP connection by default. Closing the connection means either the client or server does not support HTTP 1.1 …

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Is IE going through a Proxy?

Proxy-Connection: Keep-Alive

There is also the:

Connection: Close

response from the server. Thats odd for HTTP 1.1 .

If there is a proxy, it may be changing the HTTP Request outside what your fiddler picks up. Try testing without a proxy to single it down to IE fi you havent.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

I use WAMP which is easy to install...

http://www.wampserver.com/en/

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Hi Guys, new to this forum, kinda new to PHP in general haven't been using it long, mostly creating forms for database and custom CMS modules.

Anyway, i'm building a html email tool from the ground up and just need some help with one thing.

How do i convert values from a database field into a html form drop-down list?

I want to make a the list that display individual users and if you select a user, the value becomes that users email address

Theres two things you'll need to know.


1) How to Query the Database with PHP.
2) The structure of the HTML <select> field (drop-down list)


Assuming you're using MySQL database, look here for the functions:
http://php.net/mysql

Lets say you have a Table: Users with columns username, and email

The SQL to select usrs and email would be:

$sql = "select username, email from Users LIMIT 10";

The Structure of the HTML <select> is:

<select name="box_name" id="box_id">

<option value="value1">Label 1</option>
<option value="value2">Label 2</option>

</select>

You'll probably want to generate something like:

<select name="user_email" id="user_email">

<option value="email1">User Name 1</option>
<option value="email2">User Name 2</option>

</select>
digital-ether 399 Nearly a Posting Virtuoso Team Colleague

I want to make an html file from the rss feed and store it in .html/.htm format and make it static unless I want to change the contents by again running the specific code which gets data from the feed and again changes the contents of that page. But I am tusck in the midway on how to grab data from the feed and make static html page.

Thanks in advance!

Can you post the PHP Code you have for parsing the RSS File?

Lets say these are the steps right now.

1) Retrieve remote RSS file from URL
2) Parse RSS file into PHP Objects
3) Iterate through PHP Objects to generate HTML
4) Echo HTML

In order to cache the generated HTML, you would need something like:

1) Check if Local HTML file exists for the URL
2) If file exists, check last modified date of local HTML file
3) If the local file has not expired, echo local HTML file contents
4) If local file does not exist, or is expired,
Retrieve remote RSS file from URL
5) Parse RSS file into PHP Objects
6) Iterate through PHP Objects to generate HTML
7) Cache HTML to local file
8) Echo HTML

You can identify each remote RSS URL uniquely by creating a hash of the URL. Then name your local files after this hash.

A hash is a "unique" fixed length …

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Thanks very much. I have alraedy created the feed and reader. As i am dealing with many domains. So I was told to put less load in the site with rss feed. that's why I have to save the rss data after some interval of days.

Can you plz provide me the reference material or tutorial link or anything that you think is appropriate.

thanks in advance.

Do you want to cache the RSS feed or the HTML file you create from the RSS Feed.
Usually, you would just cache the RSS feed (XML file) but caching the HTML file should be no different.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

I have the same problems with encoding in a different content - XML files.

For your prob..
Does excel support utf-8 fully?

Question I'm asking myself, how does excel determine encoding?

When saving to the database, is the database data stored as UTF-8?

PHP functions are also non-utf8 aware. For example: strlen() on a UTF-8 string would return the number of bytes in the string, not the number of UTF-8 chars which would be less since a single char is encoded in multiple bytes..

Does your code use some PHP string functions?

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Hi,Will anyone plz suggest me on how to build a html file from rss feed and store it in a webserver or is it possible to make and store html file from the contents of mysql database using php and then store the html file in the webserver. Thanks in advance!

Yes, you can save the HTML created from RSS feeds to files on the web server or to the database.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Parsing an RSS file w/ PHP can be done in many different ways.

Usually they consist of these steps:

1) The RSS feed text is imported into PHP as a string.
2) The RSS feed text is then parsed by PHP into PHP Objects that represent the data in the RSS file (Feed Items, titles, description etc.)
3) The Objects are then used to create HTML output or some other format.

The easiest way to get started is to use an existing RSS Feed Parser for PHP.
A popular and simple one being Magpie RSS Parser.
http://magpierss.sourceforge.net/

A simple usage from the pages:

require_once 'rss_fetch.inc';

$url = 'http://magpie.sf.net/samples/imc.1-0.rdf';
$rss = fetch_rss($url);

echo "Site: ", $rss->channel['title'], "<br>
";
foreach ($rss->items as $item ) {
	$title = $item[title];
	$url   = $item[link];
	echo "<a href=$url>$title</a></li><br>
";
}
digital-ether 399 Nearly a Posting Virtuoso Team Colleague

awesome..

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Try using the is_array() function which returns true only if the argument is an array. That way you can make sure you're only passing arrays to array_filter().

eg:

if (is_array($array)) {
   $filtered_array = array_filter($array, 'filter_function_name');
}

or maybe:

if (is_array($array)) {
   $filtered_array = array_filter($array, 'filter_function_name');
} else {

   // maybe its a string so make it an array
   $array = array($array);
   $filtered_array = array_filter($array, 'filter_function_name');

}
digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Thanks.

I removed the $field_name == 0 and it worked

Its probably better if you used floatval() and intval() to validated integers and floats instead of regex as it is faster and less server intensive.

Eg, if you want to check is a string "equates" to a float:

if($float = floatval($str)) {
// ok
} else {
// not ok
}

Notice the single = . This allows you to assign the float value, as well as validate it at the same time.

digital-ether 399 Nearly a Posting Virtuoso Team Colleague

Hi,

However, heres one that also make sure you dont match a string such as "4." or "." but matches "0.4" or ".4" for example:

// validate as an int or float
function is_number($str) {
	if (preg_match("/^[0-9]*\.?[0-9]+$/", $str) && !empty($str)) {
		return true;
	}
	return false;
}