Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- **To store current date,time in a COOKIE**
- <?php
- $intwomonths = 60*60*24*60 + time();
- setcookie('lastvisit', date("G:i- m/d/y"),$intwomonths);
- if(isset($_COOKIE['lastvisit']))
- {
- $visit = $_COOKIE[lastvisit];
- echo "your last visit was-".$visit;
- }
- else
- echo "you have got some stale cookies!";
- ?>
- **To store page view counts in SESSION**
- <?php
- session_start();
- if(isset($_SESSION['count']))
- {
- echo "Your session count: ".$_SESSION['count']."<br />";
- $_SESSION['count']++;
- }
- else
- {
- $_SESSION['count'] = 1;
- echo "Session does not exist";
- }
- ?>
- **XHTML form**
- <form>
- <fieldset>
- <legend>Log In</legend>
- <label>Username: <input type="text"></label>
- <label>Password: <input type="password"></label>
- <input type="submit" value="Submit">
- </fieldset>
- </form>
- **READ A FILE**
- <html>
- <head>
- <title>Reading a file using PHP</title>
- </head>
- <body>
- <?php
- $filename = "tmp.txt";
- $file = fopen( $filename, "r" );
- if( $file == false ) {
- echo ( "Error in opening file" );
- exit();
- }
- $filesize = filesize( $filename );
- $filetext = fread( $file, $filesize );
- fclose( $file );
- echo ( "File size : $filesize bytes" );
- echo ( "<pre>$filetext</pre>" );
- ?>
- </body>
- </html>
- **WRITE A FILE**
- <?php
- $filename = "/home/user/guest/newfile.txt";
- $file = fopen( $filename, "w" );
- if( $file == false ) {
- echo ( "Error in opening new file" );
- exit();
- }
- fwrite( $file, "This is a simple test\n" );
- fclose( $file );
- ?>
- <html>
- <head>
- <title>Writing a file using PHP</title>
- </head>
- <body>
- <?php
- $filename = "newfile.txt";
- $file = fopen( $filename, "r" );
- if( $file == false ) {
- echo ( "Error in opening file" );
- exit();
- }
- $filesize = filesize( $filename );
- $filetext = fread( $file, $filesize );
- fclose( $file );
- echo ( "File size : $filesize bytes" );
- echo ( "$filetext" );
- echo("file name: $filename");
- ?>
- </body>
- </html>
Add Comment
Please, Sign In to add comment