home|Jobs|Members|Downloads|Templates|Projects|links|Contact us |PHP News|
Welcome to PHP India, group, developers, Programmers, Freelancers, Outsourcing
PHP Resources
· Home
· Akaar
· Career/Jobs
· Disclaimer
· Downloads
· FAQ
· Feedback
· Free Web Services and Tools
· Members List
· PHP NEWS
· PHPClasses
· Private Messages
· Project Bidding
· Recommend Us
· Search
· Stories Archive
· Submit News
· Surveys
· Templates For You
· Top 10
· Topics
· Web Links
· World Visitors
· Your Account

Earn money from your website

Ready Templates


Website templates

Flash intro templates

Logo templates

Corporate Identity

Free Cliparts For You

Free Icons

Free Images

Free Fonts

Free Logo Types

Free Flash Buttons

Free 3D objects


Who is where
Membres:

Visiteurs:
01: 123.125.66.115 -> News
02: 178.154.161.29 -> Web_Links
03: 38.107.191.95 -> Your_Account
04: 38.107.191.96 -> FAQ
05: 38.107.191.97 -> 4ndisclaimer
06: 38.107.191.98 -> Feedback
07: 38.107.191.99 -> Downloads
08: 65.55.3.197 -> Your_Account
09: 66.249.68.111 -> News
10: 67.195.114.240 -> Downloads
11: 70.62.98.66 -> News
12: 72.30.161.219 -> More_News
13: 80.41.195.193 -> Downloads
Par Surf

Total Visits
We received
5351334
page views since May, 2003

New Download
· 1: NASDAQ 100
· 2: Outlook Express Spam Filter
· 3: Module for affiliate program of www.bravenet.com.
· 4: Phpnuke module to resell thousands of templates
· 5: Dataentry Screen Builder for MySQL
· 6: Akaar Documentation
· 7: Akaar with Standard Smarty Application
· 8: Akaar Demo Application
· 9: Script to send an Email From Data submitted on Form
· 10: File To display nice paging op page

Top Downloads
· 1: Script to send an Email From Data submitted on Form
[Downloads: 6912 x]
· 2: File To display nice paging op page
[Downloads: 5175 x]
· 3: Akaar Demo Application
[Downloads: 2465 x]
· 4: Module for affiliate program of www.bravenet.com.
[Downloads: 2158 x]
· 5: Phpnuke module to resell thousands of templates
[Downloads: 1963 x]
· 6: Akaar Documentation
[Downloads: 1953 x]
· 7: Dataentry Screen Builder for MySQL
[Downloads: 1885 x]
· 8: Akaar with Standard Smarty Application
[Downloads: 1879 x]
· 9: TemplateTamer
[Downloads: 1753 x]
· 10: NASDAQ 100
[Downloads: 1716 x]

FAQs
· PHP and Database (5)
· PHP AND HTML (1)
· PHP and other languages (4)
· PHP-General Information (6)
· PHP-Installation (12)
· Problems While working with PHP (10)
· Where can I obtain PHP? (6)

Visitors
Top Ten Visitor Countries for This Site

See all Countries

PHP India, group, developers, Programmers, Freelancers, Outsourcing FAQ (Frequently Asked Questions)



Category: Main -> Problems While working with PHP

Question
·  I would like to write a generic PHP script that can handle data coming from any form. How do I know which POST method variables are available?
·   I need to convert all single-quotes (') to a backslash followed by a single-quote ('). How can I do this with a regular expression? I'd also like to convert " to \" and to \\.
·  All my " turn into \" and my ' turn into ', how do I get rid of all these unwanted backslashes? How and why did they get there?
·   When I do the following, the output is printed in the wrong order:
<?php
function myfunc($argument)
{
    echo $argument + 10;
}
$variable = 10;
echo "myfunc($variable) = " . myfunc($variable);
?>
what's going on?

·   Hey, what happened to my newlines?
<pre>
<?php echo "This should be the first line."; ?>
<?php echo "This should show up after the new line above."; ?>
</pre>

·  I get the message 'Warning: Cannot send session cookie - headers already sent...' or 'Cannot add header information - headers already sent...'.
·   I need to access information in the request header directly. How can I do this?
·  When I try to use authentication with IIS I get 'No Input file specified'.
·  My PHP script works on IE and Lynx, but on Netscape some of my output is missing. When I do a "View Source" I see the content in IE but not in Netscape.
·  When I try to use authentication with IIS I get 'No Input file specified'.

Answer
·  I would like to write a generic PHP script that can handle data coming from any form. How do I know which POST method variables are available?

PHP offers many predefined variables, like the superglobal $_POST. You may loop through $_POST as it's an associate array of all POSTed values. For example, let's simply loop through it with foreach, check for empty() values, and print them out.
<?php
$empty = $post = array();
foreach ($_POST as $varname => $varvalue) {
    if (empty($varvalue)) {
        $empty[$varname] = $varvalue;
    } else {
        $post[$varname] = $varvalue;
    }
}

print "<pre>";
if (empty($empty)) {
    print "None of the POSTed values are empty, posted:
";
    var_dump($post);
} else {
    print "We have " . count($empty) . " empty values
";
    print "Posted:
"; var_dump($post);
    print "Empty:
";  var_dump($empty);
    exit;
}
?>

Superglobals: availability note: Since PHP 4.1.0, superglobal arrays such as $_GET , $_POST, and $_SERVER, etc. have been available. For more information, read the manual section on superglobals

[ Back to Top ]

·   I need to convert all single-quotes (') to a backslash followed by a single-quote ('). How can I do this with a regular expression? I'd also like to convert " to \" and to \\.

The function addslashes() will do this. See also mysql_escape_string(). You may also strip backslashes with stripslashes().
directive note: magic_quotes_gpc: The PHP directive magic_quotes_gpc defaults to on. It essentially runs addslashes() on all your GET, POST, and COOKIE data. You may use stripslashes() to strip them.

[ Back to Top ]

·  All my " turn into \" and my ' turn into ', how do I get rid of all these unwanted backslashes? How and why did they get there?

The PHP function stripslashes() will strip those backslashes from your string. Most likely the backslashes magically exist because the PHP directive magic_quotes_gpc is on. directive note: magic_quotes_gpc:
The PHP directive magic_quotes_gpc defaults to on. It essentially runs addslashes() on all your GET, POST, and COOKIE data. You may use stripslashes() to strip them.

[ Back to Top ]

·   When I do the following, the output is printed in the wrong order:
<?php
function myfunc($argument)
{
    echo $argument + 10;
}
$variable = 10;
echo "myfunc($variable) = " . myfunc($variable);
?>
what's going on?

To be able to use the results of your function in an expression (such as concatenating it with other strings in the example above), you need to return() the value, not echo() it.

[ Back to Top ]

·   Hey, what happened to my newlines?
<pre>
<?php echo "This should be the first line."; ?>
<?php echo "This should show up after the new line above."; ?>
</pre>

In PHP, the ending for a block of code is either "?>" or "?> " (where means a newline). So in the example above, the echoed sentences will be on one line, because PHP omits the newlines after the block ending. This means that you need to insert an extra newline after each block of PHP code to make it print out one newline.

Why does PHP do this? Because when formatting normal HTML, this usually makes your life easier because you don't want that newline, but you'd have to create extremely long lines or otherwise make the raw page source unreadable to achieve that effect.

[ Back to Top ]

·  I get the message 'Warning: Cannot send session cookie - headers already sent...' or 'Cannot add header information - headers already sent...'.

The functions header(), setcookie (), and the session functions need to add headers to the output stream but headers can only be sent before all other content. There can be no output before using these functions, output such as HTML. The function headers_sent() will check if your script has already sent headers and see also the Output Control functions.

[ Back to Top ]

·   I need to access information in the request header directly. How can I do this?

The getallheaders() function will do this if you are running PHP as an Apache module. So, the following bit of code will show you all the request headers:
<?php
$headers = getallheaders();
foreach ($headers as $name => $content) {
    echo "headers[$name] = $content<br>
";
}
?>

See also apache_lookup_uri(), apache_response_headers(), and fsockopen()

[ Back to Top ]

·  When I try to use authentication with IIS I get 'No Input file specified'.

The security model of IIS is at fault here. This is a problem common to all CGI programs running under IIS. A workaround is to create a plain HTML file (not parsed by PHP) as the entry page into an authenticated directory. Then use a META tag to redirect to the PHP page, or have a link to the PHP page. PHP will then recognize the authentication correctly. With the ISAPI module, this is not a problem. This should not effect other NT web servers. For more information, see: http://support.microsoft.com/support/kb/articles/q160/4/22.asp

[ Back to Top ]

·  My PHP script works on IE and Lynx, but on Netscape some of my output is missing. When I do a "View Source" I see the content in IE but not in Netscape.

Netscape is more strict regarding html tags (such as tables) then IE. Running your html output through a html validator, such as validator.w3.org, might be helpful. For example, a missing

might cause this.

Also, both IE and Lynx ignore any NULs () in the HTML stream, Netscape does not. The best way to check for this is to compile the command lineversion of PHP (also known as the CGI version) and run your script from the command line. In *nix, pipe it through od -c and look for any characters. If you are on Windows you need to find an editor or some other program that lets you look at binary files. When Netscape sees a NUL in a file it will typically not output anything else on that line whereas both IE and Lynx will.


Also, both IE and Lynx ignore any NULs () in the HTML stream, Netscape does not. The best way to check for this is to compile the command line version of PHP (also known as the CGI version) and run your script from the command line. In *nix, pipe it through od -c and look for any characters. If you are on Windows you need to find an editor or some other program that lets you look at binary files. When Netscape sees a NUL in a file it will typically not output anything else on that line whereas both IE and Lynx will.

[ Back to Top ]

·  When I try to use authentication with IIS I get 'No Input file specified'.

The security model of IIS is at fault here. This is a problem common to all CGI programs running under IIS. A workaround is to create a plain HTML file (not parsed by PHP) as the entry page into an authenticated directory. Then use a META tag to redirect to the PHP page, or have a link to the PHP page. PHP will then recognize the authentication correctly. With the ISAPI module, this is not a problem. This should not effect other NT web servers. For more information, see: http://support.microsoft.com/support/kb/articles/q160/4/22.asp and the manual section on HTTP Authentication .

[ Back to Top ]



Web site powered by PHP-Nuke

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest © 2002 by www.php-india.net
You can syndicate our news using the file backend.php or ultramode.txt
Connection timed out (110)
Web site engine's code is Copyright © 2002 by PHP-Nuke. All Rights Reserved. PHP-Nuke is Free Software released under the GNU/GPL license.
Page Generation: 0.078 Seconds