Archive

Archive for the ‘Bugs’ Category

Session Funda in PHP

March 5, 2010 Leave a comment

Hey guys,
It took me some time to understand basics of Session in php.
If you create a logout.php to end user session, the right sequence is as follows

session_start();
session_unset();
session_destroy();

he difference between both session_unset and session_destroy is as follows:

session_unset just clears out the sesison for usage. The session is still on the users computer. Note that by using session_unset, the variable still exists.

Using session_unset in tandem with session_destroy however, is a much more effective means of actually clearing out data. As stated in the example above, this works very well, cross browser:

session_unset();
session_destroy();

I noticed that in firefox, one could simply use sesison_unset and the session would be cleared. When trying this on IE, I was horrified to find out that the data was still there, so I had to use session destroy.
(Ref : http://www.php.net/manual/en/function.session-unset.php)

session_unset() is like doing a session_unregister() on all registered variables. They can still be re-registered by calling session_register() whereas after session_destroy, they cannot.

If you want to clear all sessions:
$_SESSION = array();

Categories: Bugs, PHP, tricks

Problem while Sending mail through PHP

March 5, 2010 Leave a comment

Guys,
Today i faced one problem while sending mail to mail account residing on my server.
I went through the link and found the solution.

The tag at the end of mail() function :
“-femail@domain.com”
ie. mail($sendto,$subject,$message,$headers,”-femail@domain.com”);
works great.
This is a sendmail command line flag. You can use -f to set the sender (“envelope from”) address. The PHP mail() function takes five parameters, including two optional ones that follow the three required ones you’re probably used to.

Categories: Bugs, PHP

Increase PHP memory limit

December 9, 2009 Leave a comment

Hey,

I got error Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 13050 bytes) in my file /home/developer/Sachin/API/performance.php on line 227
You can view memory limit using

1. If your memory is set to 8M, continue with next step
2. Open your php.ini file. If your server is a Webune Dedicated Server with Redhat, Centos or Fedora, you can run the following command to edit the php.ini file:
3. VIM /etc/php.ini (you can view its location in phpinfo())
4. Code:
memory_limit = 64M ; Maximum amount of memory a script may consume (6MB)
5. Save the changes.
6. Restart Apache Server with the following command
Code:
/etc/init.d/httpd restart
7. Done

or
Youcan set the memory limit within a file using ini_set() function:
at ini_set(‘memory_limit’, ’64m’); in your php page.

Categories: Bugs, mysql, PHP

Problems while setting the Cookie

November 14, 2007 Leave a comment

Hi,

Today i faced one problem while setting the COOKIE. We should not echo or output(e.g.while integrating with html) before calling setcookie() function.The Cookie will not be set in this case.So take care will integrating HTML with PHP (especially without using SMARTY)
If output exists prior to calling this function, setcookie() will fail and return FALSE. If setcookie() successfully runs, it will return TRUE. This does not indicate whether the user accepted the cookie.

Categories: Bugs

some important things about css

October 30, 2007 Leave a comment

1. Image replacement technique:

It’s always advisable to use regular HTML markup to display text, as opposed to an image. Doing so allows for a faster download speed and has accessibility benefits. However, if you’ve absolutely got your heart set on using a certain font and your site visitors are unlikely to have that font on their computers, then really you’ve got no choice but to use an image.Say for example, you wanted the top heading of each page to be ‘Buy widgets’, as you’re a widget seller and you’d like to be found for this phrase in the search engines. You’re pretty set on it being an obscure font so you need to use an image:

<h1><img src=”widget-image.gif” alt=”Buy widgets” /></h1>This is OK but there’s strong evidence to suggest that search engines don’t assign as much importance to alt text as they do real text (because so many webmasters use the alt text to cram in keywords). So, an alternative would be:

<h1>Buy widgets</h1>Now, this obviously won’t use your obscure font. To fix this problem place these commands in your CSS document:

h1
{
background: url(widget-image.gif) no-repeat;
height: image height
text-indent: -2000px
}Be sure to change “image height” to whatever the height of the image is (e.g. 85px)! The image, with your fancy font, will now display and the regular text will be safely out of the way, positioned 2000px to the left of the screen thanks to our CSS rule. Please note, this can cause accessibility issues as any user with images turned off won’t be able to see the text.

2. CSS box model hack alternative:

The box model hack is used to fix a rendering problem in pre-IE 6 browsers on PC, where by the border and padding are included in the width of an element, as opposed to added on. For example, when specifying the dimensions of a container you might use the following CSS rule: #box
{
width: 100px;
border: 5px;
padding: 20px
}This CSS rule would be applied to:

<div id=”box”>…</div>

This means that the total width of the box is 150px (100px width + two 5px borders + two 20px paddings) in all browsers except pre-IE 6 versions on PC. In these browsers the total width would be just 100px, with the padding and border widths being incorporated into this width. The box model hack can be used to fix this, but this can get really messy.

A simple alternative is to use this CSS:

#box
{
width: 150px
}

#box div
{
border: 5px;
padding: 20px
}And the new HTML would be:

<div id=”box”> <div>..</div></div>Perfect! Now the box width will always be 150px, regardless of the browser!

3.Centre aligning a block element

Say you wanted to have a fixed width layout website, and the content floated in the middle of the screen. You can use the following CSS command: #content
{
width: 700px;
margin: 0 auto
}You would then enclose <div id=”content”> around every item in the body of the HTML document and it’ll be given an automatic margin on both its left and right, ensuring that it’s always placed in the centre of the screen. Simple… well not quite – we’ve still got the pre-IE 6 versions on PC to worry about, as these browsers won’t centre align the element with this CSS command. You’ll have to change the CSS rules:

body
{
text-align: center
}

#content
{
text-align: left;
width: 700px;
margin: 0 auto
}This will then centre align the main content, but it’ll also centre align the text! To offset the second, probably undesired, effect we inserted text-align: left into the content div.

3.vertically aligning with CSS

Vertically aligning with tables was a doddle. To make cell content line up in the middle of a cell you would use vertical-align: middle. This doesn’t really work with a CSS layout. Say you have a navigation menu item whose height is assigned 2em and you insert this vertical align command into the CSS rule. It basically won’t make a difference and the text will be pushed to the top of the box.

Hmmm… not the desired effect. The solution? Specify the line height to be the same as the height of the box itself in the CSS. In this instance, the box is 2em high, so we would insert line-height: 2em into the CSS rule and the text now floats in the middle of the box – perfect!

I also found the following link very useful:

http://css-code.assistprogramming.com/fixing-overflowhidden-in-ie.html

The Submit Button Problem

July 20, 2007 3 comments

The problem is coupled with the use of the HTML 4.0 tag <button></button>. This tag was designed to extend the usage of the <input type="submit"/> and give you the ability to make any peice of HTML a “button” by placing its contents within a “button” container (between the tags). You can create image buttons, colored text buttons, or a myriad of other things. Hence, the following peice of HTML would serve as a fine “add” button for our “Add Collections” dialog.

<button type="submit" name="action" value="addCollection">Add</button>

This is where IE deviates from the HTML specification. Below is the URL produced by Firefox and the URL produced by IE upon clicking the submit button.

IE: plog-manage.php?action=Add&name=...
Firefox: plog-manage.php?action=addCollection&name=...

As you can see, Internet Explorer passes the text “Add” as the value of “action”. Firefox does the proper thing and sends the value placed in the “value” attribute, whereas IE sends the content inserted between the button tags. As a result, the PHP code which checked the value of action from the $_REQUEST array had a value it didn’t know what to do with, “Add”.

So the solution turned out to be pretty simple, reverting the code back to the tried and true <input type="submit" name="something" value="somethingelse".../> tag. Both browsers reliably send the “value” attribute when building a POST or GET URL encoded string from an input tag.

Categories: Bugs

Problem with ampersand in xml

May 11, 2007 Leave a comment

I have a process that dynamically builds xml on the fly based on some request. This application uses entity reference to represent ampersand. (&) .

Following is an example of the xml generated.
<productTitle>added from & admin</productTitle>

We have one simple way in PHP is use htmlentities  function before creating actual XML.

Perfect solution is to enclose problematic part of code into
<![CDATA[ ><, >, ', " characters> ]]>

 If u r passing XML as URL as response  then perfect solution is

: to URL encode the data, which converts special chars (like &) into codes (eg '&' -> '&'). on the other end, the data needs to be unencoded

Help:

Escape Characters

Illegal XML characters have to be replaced by entity references.

If you place a character like "<" inside an XML element, it will generate an error because the parser interprets it as the start of a new element. You cannot write something like this:

<message>if salary < 1000 then</message>

To avoid this, you have to replace the "<" character with an entity reference, like this:

<message>if salary &lt; 1000 then</message>

There are 5 predefined entity references in XML:

&lt; < less than
&gt; > greater than
&amp; & ampersand
&apos; ' apostrophe
&quot; " quotation mark

Note: Only the characters "<" and "&" are strictly illegal in XML. Apostrophes, quotation marks and greater than signs are legal, but it is a good habit to replace them.google 'URL encode'

Categories: Bugs

Error: Internet Explorer cannot open the Internet site Operation aborted

May 5, 2007 4 comments

Apparently interacting with innerHTML
JScript functionality causes IE to pop up “Internet Explorer cannot open the Internet site http://example.com. Operation aborted.” messages after loading a page.

This is generally caused by DOM operations gone wrong.

I was having this problem trying to put some html inside a DIV tag using innerHTML and solved the problem by puting the DIV inside a TABLE. Sample code for “Operation aborted”

This sample code will give you the “Operation aborted” error in IE6, while it works as expected in Opera, Mozilla and Firefox:

  <table>
   <tr>
    <td>
     <script type="text/Javascript">
      var d = document.createElement('div');
      document.body.appendChild(d);
     </script>
    </td>
   </tr>
  </table>

If the script part is moved outside the table it works in both IE6 and Firefox. (Emphasis added) It seems that this problem is caused by the fact that the SCRIPT block operating on innerHTML or DOM structures is located inside a TABLE tag. I moved the SCRIPT tags outside the TABLE tag, and viola – that fixed the problem.

Peter Janes pointed out in the comments that the issue is deeper than that, it seems to be related to the timing issues with DOM rendering.

I am going to leave it for now unless I see other problems, but using setTimeout or some other way of doing things is not out of the question.

One more way The defer attribute

The W3C HTML 4.0 specification specifies the defer attribute for script tags:

<script language=”javascript” type=”text/javascript” defer>

Originally, this is nothing more than a hint to the browser that the script inside the tags does not modify the content of the web page (by doing a document.write, for instance). Therefore the browser does not need to wait for the entire script to be parsed and evaluated, it can immediately go on parsing the HTML. On older systems this might save some parsing time.(Only in Explorer 4+ on Windows the defer attribute defers executing the script until the document has been parsed completely.)

However, Explorer 4+ on Windows has slightly changed the meaning of defer. Any code inside deferred script tags is only executed when the page has been parsed entirely. For instance, take

<body>
<script language=”javascript” type=”text/javascript” defer>
<!–
alert(document.forms[0].elements.length);
// –>
</script>

<form>
<input value=”Bla”>
</form>
</body>

Normally the alert would give an error: the document does not (yet) contain any form at the moment it is executed. By adding defer to the script tag, however, the alert is deferred until after parsing and correctly gives 1 as the length of the form.

Categories: Bugs
Follow

Get every new post delivered to your Inbox.