Thursday, 9 December 2010

php – Cannot modify header information – headers already sent by (php header already sent error)

This error comes when you print any thing before php hreader command or sometime single spaces allowed before any file starting place or printing or getting values from $_COOKIE or $_SESSION or set cookie or set session etc…

Example Error Code:
<?php
print “text”;
header(‘Location: http://www.example.com/’);
?>

Solution :

<?php
function JSRedirection($url)
{?>
<script type=”text/javascript”>
<!–
window.location = “<?=$url?>”
//–>
</script>
<?}
print “test”;
JSRedirection(“http://www.example.com/”);

?>

Above is by use of js redirect function. But we can solved it by php functions only.

Example 1:

<?php
header("location: 1.html");
header("location: 2.html"); //replaces 1.html
?>


This redirects to 2.html since the second header replaces the first.

Example 2:

<?php
header("location: 1.html");
echo "send data";
header("location: 2.html"); //1.html already sent
?>


This redirects to 1.html since the header is sent as soon as the echo happens. You also won't see any "headers already sent" errors because the browser follows the redirect before it can display the error.

Example 3:

<?php
ob_start();
header("location: 1.html");
echo "send data";
header("location: 2.html"); //replaces 1.html
ob_end_flush(); //now the headers are sent
?>


Wrapping the previous example in an output buffer actually changes the behavior of the script! This is because headers aren't sent until the output buffer is flushed.

OR

Need to write <?php ob_start(); ?> at first line of html part when you main body is common for all pages.

like:

<?php ob_start(); ?>

<html> ……  <?php include_once “<included part of files >”;  ?>  …… </html>

Monday, 22 November 2010

Few Useful Sites To Subscribe

Here I am listing few of the very useful information/resource providing sites that keeps you awake about the things in current trends to buisness,social media, market, entrepreneurship , design , technology.

http://techcrunch.com/
http://sanderssays.typepad.com/sanders_says/
http://www.smashingmagazine.com/
http://sethgodin.typepad.com/seths_blog/
http://dilbert.com/
http://www.leadershipnow.com/leadingblog/
http://www.ted.com/
http://www.spring.org.uk/
http://www.fastcompany.com/
http://www.boomberg.com/
http://www.ft.com

Please add your comment if I missed any important site.

 

Web 2.0 Vs Web 1.0


  • Web 2.0 is about communities, Web 1.0 was about companies

  • Web 2.0 is about blogs, Web 1.0 was about home pages

  • Web 2.0 is about peer to peer, Web 1.0 was about client-server

  • Web 2.0 is about XML, Web 1.0 was about HTML

  • Web 2.0 is about writing, Web 1.0 was about reading

  • Web 2.0 is about tags, Web 1.0 was about taxonomy

  • Web 2.0 is about wireless, Web 1.0 was about wires

  • Web 2.0 is about sharing, Web 1.0 was about owning

  • Web 2.0 is about RSS, Web 1.0 was about portals

  • Web 2.0 is about trade sales, Web 1.0 was about IPOs

  • Web 2.0 is about web applications, Web 1.0 was about web forms

  • Web 2.0 is about APIs, Web 1.0 was about screen scraping

  • Web 2.0 is about broadband, Web 1.0 was about dialup

  • Web 2.0 is about bandwidth costs, Web 1.0 was about hardware costs

  • Web 2.0 is about Google, Web 1.0 was about Netscape


 

Thursday, 18 November 2010

PHP Add and Remove Querystring Variables

function add_querystring_var($url, $key, $value) {

$url = preg_replace('/(.*)(\?|&)' . $key . '=[^&]+?(&)(.*)/i', '$1$2$4', $url . '&');

$url = substr($url, 0, -1);

if (strpos($url, '?') === false) {

return ($url . '?' . $key . '=' . $value);

} else {

return ($url . '&' . $key . '=' . $value);

}

}

 

function remove_querystring_var($url, $key) {

$url = preg_replace('/(.*)(\?|&)' . $key . '=[^&]+?(&)(.*)/i', '$1$2$4', $url . '&');

$url = substr($url, 0, -1);

return ($url);

}

EXE in PHP (Make Executable or Make Desktop Application in PHP)

Hello Friends,

I m a web developer and i always use PHP as web scripting server side language but before some days when i found that now it is possible to make EXE in PHP means now you can make Executable or make Desktop application by PHP. Isn’t it Great?

There are many complier available on web by which you can create EXE in PHP.

This program runs through dos and windows only,I don’t know About Linux.If you want to make Executable in PHP then firstly download PHP EXE Compiler/Embedder from Here.

Try to explain you some more things about this.

 

1.First Download zip from Here.

2. Now unzip it and open Command prompt and then go to its directory.

3. Start > run… ‘cmd’
4. Use the “cd..” command to change directory.

5. Place PHP script to be compiled next to bamcompile.exe (same directory)
6. in the cmd prompt, at that directory, type:
ex: “bamcompile test.php”
variations:
“bamcompile -c test.php” gives compression.
-e:something.dll allows a DLL to be embedded

Readymade examples are given in Zipped files which you have downloaded, just try it out.