Web Developer
Saturday, 12 September 2020
Monday, 22 June 2020
Sunday, 21 June 2020
isset function
<?php
$var1 = 'test';
if(isset($var1)) {
echo "The variable $var1 is set, so it will print. </br>";
var_dump(isset($var1));
}
?>
output
$var1 = 'test';
if(isset($var1)) {
echo "The variable $var1 is set, so it will print. </br>";
var_dump(isset($var1));
}
?>
output
The variable test is set, so it will print. bool(true)
- <?php
- $x = 9;
- //TRUE because $x is set
- if ($resultX = isset ($x)) {
- echo "Variable 'x' is set.";
- }
- echo var_dump(isset($resultX)). "</br>";
- $y = NULL;
- //False because $y is Null
- if (isset ($y)) {
- echo "Variable 'y' is not set.";
- }
- echo var_dump(isset($y)). "</br>";
- $z ='\0';
- //TRUE because \0 and NULL are treated different
- if ($resultZ = isset ($z)) {
- echo "Variable 'z' is set.";
- }
- echo var_dump(isset($resultZ));
- ?>
var_dump
echo
- Outputs one or more strings separated by commas
- No return valuee.g.
echo "String 1", "String 2"
print
- Outputs only a single string
- Returns
1, so it can be used in an expressione.g.print "Hello"or,if ($expr && print "foo")
print_r()
- Outputs a human-readable representation of any one value
- Accepts not just strings but other types including arrays and objects, formatting them to be readable
- Useful when debugging
- May return its output as a return value (instead of echoing) if the second optional argument is given
- There are two more functions similar to print_r() which are var_export(), and var_dump(). They display the private and protected properties of objects.
- print_r (mixed $var_name, boolean $return_output)
var_dump()
- Outputs a human-readable representation of one or more values separated by commas
- Accepts not just strings but other types including arrays and objects, formatting them to be readable
- Uses a different output format to
print_r(), for example it also prints the type of values - Useful when debugging
- No return value
var_export()
- Outputs a human-readable and PHP-executable representation of any one value
- Accepts not just strings but other types including arrays and objects, formatting them to be readable
- Uses a different output format to both
print_r()andvar_dump()- resulting output is valid PHP code! - Useful when debugging
- May return its output as a return value (instead of echoing) if the second optional argument is given
var_dump
hat dumps the information about the variables.
<?php
//PHP program to demonstrate the working of var_dump function
$x = 25;
//dump integer variable
var_dump ($x);
echo "</br>";
$y = 32.5;
//dump float variable
var_dump ($y);
echo "</br>";
$bvalue = true;
//dump boolean variable
var_dump ($bvalue);
?>
int(25)
float(32.5)
bool(true)
float(32.5)
bool(true)
<?php
//dump strings
$msg1 = "Hello Alex";
var_dump ($msg1);
echo "</br>";
$msg2 = "Welcome to javatpoint";
var_dump ($msg2);
?>
string(10) "Hello Alex"
string(21) "Welcome to javatpoint"
string(21) "Welcome to javatpoint"
how to get the current page url in php
- <?php
- if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on')
- $url = "https://";
- else
- $url = "http://";
- // Append the host(domain name, ip) to the URL.
- $url.= $_SERVER['HTTP_HOST'];
- // Append the requested resource location to the URL
- $url.= $_SERVER['REQUEST_URI'];
- echo $url;
- ?>
or
- <?php
- $protocol = ((!emptyempty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
- $CurPageURL = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
- echo "The URL of current page: ".$CurPageURL;
- ?>
to get the current page url
- <?php
- $curPageName = substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
- echo "The current page name is: ".$curPageName;
- echo "</br>";
- ?>
new line starts php
- <?php
- echo nl2br("New line will start from here\n in this string\r\n on the browser window");
- ?>
New line will start from here in this string on the browser window
- <?php
- echo "One line after\n another line";
- echo " One line after\r\n another line";
- ?>
One line after another line One line after another line
Friday, 19 June 2020
php mail local host server
| smtp server | ||
| open the file from sendmail | ||
| sendmail.ini | ||
| smtp_server=mail.mydomain.com | smtp.gmail.com | get the smtp server |
| change to gmail server | ||
| smtp_port=25 | 587 | change to port |
| smtp_ssl=auto | tls | change the ssl |
| auth_username= | emailid | write the emial id |
| auth_password= | password | write the password |
| force_sender= | emailid | write theemial id |
| hostname= | localhost | write the host |
| uncomment ;error_logfile=error.log to error_logfile=error.log | create the error.log file | |
| uncomment ;debug_logfile=debug.log to debug_logfile=debug.log | create the debug.log file | |
| php.ini | ||
| xampp/php/php.ini | ||
| [mail function] | ||
| ; For Win32 only. | ; For Win32 only. | |
| ; http://php.net/smtp | ; http://php.net/smtp | |
| SMTP=localhost | ;SMTP=localhost | comment the local host |
| ; http://php.net/smtp-port | ; http://php.net/smtp-port | |
| smtp_port=25 | ;smtp_port=25 | comment the port |
| ; For Win32 only. | ||
| ; http://php.net/sendmail-from | ||
| sendmail_from = | ;sendmail_from = | coment the sendmail from |
| ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). | ||
| ; http://php.net/sendmail-path | ||
| ;sendmail_path = | sendmail_path = C:\xampp\sendmail\sendmail.exe | |
| extension=php_openssl.dll | check this enabls or not | checks theis |
| check in errror log | ||
| debug | ||
| myaccountsignin | ||
| allowlesssecureapps | ||
| <?php | ||
| $to = "recievver mailid";//change receiver address | ||
| $subject = "hai vamsi"; | ||
| $message = "This is simple text amessage."; | ||
| $header = "From:vamsikrishnaengineer@gmail.com \r\n"; | ||
| $result = mail ($to,$subject,$message,$header); | ||
| if( $result == true ){ | ||
| echo "Message sent successfully..."; | ||
| }else{ | ||
| echo "Sorry, unable to send mail..."; | ||
| } | ||
| ?> | ||
Thursday, 18 June 2020
php include and require
|
pho include and require
|
|
|
in php page, if require file is not
found, it wil stop the execution of remaining and include - if include file
is not found, it wll generete error and execute remaing script
|
|
|
include only
generates a warning, i.e., E_WARNING, and continue the execution of the
script.
|
|
|
require generates a
fatal error, i.e., E_COMPILE_ERROR, and stop the execution of the script.
|
|
|
1. include 'filename ';
|
|
|
2. Or
|
|
|
3. include ('filename');
|
|
|
php requirre
|
|
|
PHP require is similar to include, which is also used to include
files. The only difference is that it stops the execution of script if the
file is not found whereas include doesn't.
|
|
|
1. require 'filename';
|
|
|
2. Or
|
|
|
3. require ('filename');
|
|
php forms
|
php get form
|
|
|
form1.html
|
|
|
1. <form action="welcome.php" method="get">
|
|
|
2. Name: <input type="text" name="name"/>
|
|
|
3. <input type="submit" value="visit"/>
|
in html page , whenever it submits, it redircts to welcome.pho
|
|
4. </form>
|
|
|
welcome.php
|
|
|
1. <?php
|
|
|
2. $name=$_GET["name"];//receiving name field value in $name variable
|
it gets the value
|
|
3. echo "Welcome, $name";
|
it prints the value
|
|
4. ?>
|
get willl show in url
|
|
php post form
|
|
|
form1.html
|
|
|
1. <form action="login.php" method="post">
|
|
|
2. <table>
|
|
|
3.
<tr><td>Name:</td><td> <input type="text" name="name"/></td></tr>
|
post will not show in url
|
|
4.
<tr><td>Password:</td><td> <input type="password" name="password"/></td></tr>
|
|
|
5. <tr><td colspan="2"><input type="submit" value="login"/> </td></tr>
|
|
|
6. </table>
|
|
|
7. </form>
|
|
|
login.php
|
|
|
1. <?php
|
|
|
2. $name=$_POST["name"];//receiving name field value in $name variable
|
|
|
3. $password=$_POST["password"];//receiving password field value in $password variable
|
|
|
4.
|
|
|
5. echo "Welcome: $name, your password is: $password";
|
|
|
6. ?>
|
Subscribe to:
Comments (Atom)
