PHP - Security Of $_session For Authentication
I've read lots of articles and discussions about security issues for using session for user authentication; but I did not come to an explicit conclusion which is the best method.
I decide to generate two session parameters (1) ID (2) a randomly generated Access Token which is stored in the database. I want to add more security: 1. Where to store session? server-side or client-side by session session.use_only_cookies ? 2. Is it good to check IP and User Agent before authentication by session? In this case I will lose the option of Remember Me as IP can be changed. 3. Which of the session parameters of http://php.net/manual/en/session.configuration.php is more practical to have a good security? Any additional idea? Similar TutorialsHello all, I have this at the top of my page to ensure that only logged in users can see the content Code: [Select] if(!isset($_SESSION['myusername'])){ header("Location:login.php"); exit; } else { $username = $_SESSION['myusername']; } This, of course is checked in the login form against a database and only stored in $_SESSION once it's verified... Now, my question is -- how secure is this? For example, could someone have $_SESSION['myusername'] set from another webpage, then navigate to mine and be able to see the protected content?
First let me explain my code. This is later included in project_status.php] . In project_status.php] , I have included another file project_status_app.php which contains a HTML form.
<?php include 'inc_fn_header_and_menu.php'; function includeFile($file,$variable) { $var = $variable; include($file); } if (isset($_GET['id']) && $_GET['id']!="") { $pid = $_GET['id']; $_SESSION['pidForApproval'] = $_GET['id']; $query = 'SELECT * FROM `profile` WHERE pid ='.'\''.$pid.'\''; $result=mysqli_query($db,$queryToRetrievePP) or die("There are no records to display ... \n" . mysqli_error()); foreach ($result as $row) { $status = $row['status']; } } ...........some PHP and HTML code....... <div id="customerPurchaseApprovalForm"> <?php echo '<p>APPROVAL FOR CUSTOMER PURCHASE</p>'; $discountApprovalStatus = "Granted"; if ($discountApprovalStatus == "Granted") { includeFile("project_status_app.php",$highestannualvalue); } else { //......... } In project_status_app.php I am attempting to retrieve pidForApproval from the $_SESSION array. <?php // put your code here UPDATE `pp` SET `customer_purchase_remarks` = 'hahaha' WHERE `pp`.`id` = 207; if ($_SERVER['REQUEST_METHOD'] == 'POST') { include '../../inc/fastlogin.php'; $sql = "UPDATE pp SET customer_purchase_remarks ='{$_POST['remarkstxt']}' WHERE pp.pid='{$_SESSION['pidForApproval']}'"; $result = mysqli_query ( $fastdb, $sql ) ; if (mysqli_affected_rows($fastdb) != 1) { $_SESSION['err_cpa_rmks'] = "<p>Error while updating WHERE id='{$_SESSION['pidForApproval']}'</p>"; //echo "<p>Error while updating WHERE id='{$_POST['pidForApproval']}'</p>".mysqli_error($fastdb); } else { $_SESSION['suc_cpa_rmks'] = "<p>Records was updated successfully.</p>"; //echo "Records was updated successfully."; } header ("location: project_status.php?id="$_SESSION['pidForApproval']); exit(); } ?> When I load project_status.php, project_status_app.php is supposed to display the form. Once the user fills in the form the and the submit button has been pressed, the UPDATE statement is supposed to run and then it is supposed to navigate back to project_status.php?id=FA142. But the update is failing and the when the project_status.php is loaded back, the url looks like this http://localhost/fast/project_status.php?id= . The id is empty. It is supposed to be something like this http://localhost/fast/project_status.php?id=FA142. With the id being populated at the header ("location: project_status.php?id=".$_SESSION['pidForApproval']);
Missing some information. Hello everyone, I am working on a form that is similar to a shopping cart system and I am thinking of creating a button that submits the checked value and saves them to a $_SESSION variable. And also a link that links to a cart.html that takes the values of a $_SESSION variable. I am have trouble figuring what tag/attribute should I use in order to achieve that.
Right now my code attached below submits the checked values to cart.html directly. However I want my submit button to save the checked box to a $_SESSION variable and STAY on the same page. And then I will implement a <a> to link to the cart.php.
I researched a little bit about this subject and I know it's somewhat related to ajax/jquery. I just wanted to know more about it from you guys. I appreciate your attention for reading the post and Thanks!
Below is the form that I currently have:
<form name= "finalForm" method="POST" action="cart.php"> <input type="Submit" name="finalSelected"/> <?php foreach($FinalName as $key => $item) {?> <tr> <td><input type="checkbox" name="fSelected[]" value="<?php echo htmlspecialchars($FinalID[$key])?>" /> <?php echo "$FinalID[$key] & $item";?> </td> </tr> <?php } ;?>Below is the code for cart.php <?php require ('connect_db.php'); if(isset($_POST['finalSelected'])) { if(!empty($_POST['fSelected'])) { $chosen = $_POST['fSelected']; foreach ($chosen as $item) echo "aID selected: $item </br>"; $delimit = implode(", ", $chosen); print_r($delimit); } } if(isset($delimit)) { $cartSQL = "SELECT * from article where aID in ($delimit)"; $cartQuery = mysqli_query($dbc, $cartSQL) or die (mysqli_error($dbc)); while($row = mysqli_fetch_array($cartQuery, MYSQLI_BOTH)) { $aTitle[] = $row[ 'name' ]; } } ?> <table> <?php if(isset($delimit)) { $c=0; foreach($aTitle as $item) {?> <tr> <td> <?php echo $aTitle[$c]; $c++;?> </td> </tr> <?php }}?> </table> Hi all, I have an authentication part on my website that checks every page through a session variable if a user is logged in and which user it is. When I test my code on my computer it works perfectly registration and login goes smooth but when someone on another computer tries it they get the acces denied page.... does anyone know why??? Greets Ryflex I am currently doing the following but wish to change to using JWTs. A webserver is running some CRM system which has its own authentication system and browsers can access public routes without logging and but must log on first to access private routes. All the routes on the webserver which are prefixed by "api" will be forwarded to specific REST API along with an "account" GUID in the header and the user's ID if it exists. For the routes that require a user to be logged in, the webserver will first check if a session exists, and if not make a preliminary GET request to the REST API which includes the GUID as well as the user's ID and encrypted password (both based on the webserver's CRM DB) in the URL. Not sure whether anything is possible by including the hashed password and am currently not doing anything with it. The REST API queries the DB using the GUID and webserver's user ID and returns the REST API's users ID and the webserver stores it in a session. The REST API receives the GUID and potentially the REST API's user ID and queries the DB to retrieve the account and potentially user before executing the route, and returns the response to the webserver which it returns it to the browser.The new approach might be something like the following: Before the webserver forwards any request to the REST API, it checks if a session is set, and if not performs a GET request to the REST API along with the GUID and if known user's credentials in the URL and receives a JWT which contains a payload including the account PK, and potentially the user PK, user's access level, etc. All future requests include this JWT in the header. The REST API no longer queries the DB to get the account ID and user authorized settings as it is provided in the JWT.A couple of questions: What should be done if a non-logged on user first accesses a public route, gets a JWT, and stores it in a session, but then later logs on and accesses a private route? The webserver thinks it has a valid JWT and will send it but the REST API will then decrypt it and find there is no user it. One option is for the webserver to use two sessions, but this sounds kludgy. Or maybe the REST API returns some header which instructs the webserver to re-authenticate, but not sure if even an option, and if so how to cleanly prevent some loop. Also, would it be necessary to issue a new JWT or can the payload in a JWT be changed? Is GET appropriate for requesting the JWT's or should I use some other method? Is it appropriate to include the user's access level in the JWT payload? Will one need to wait until the JWT has expired before their access level changes? Any ideas how to deal with using the user's password on the CRM to also authenticate on the REST API? The GUID is probably secret enough for the application and if an issue, can just use the GUID and username. Am I going down an reasonable path and anything else obvious I should be considering?Thanks! Hello all, I am extremely new with php, I just started learning it this week. I am tryin to make a secure login page that uses cookies for authentication. The problem I am having is that I cannot seem to get it to detect or read the set cookie properly. I want it to detect if its the correct username in the cookie and if so, allow to see the page, and if now, then return to the login screen. The login screen is login.html, which directs the person to the php script login.php. That should in turn show them a message page and some short info, as well as a link to their control panel (index.php) . The problem is that even if i skip the login I can still reach the control panel (index.php) with or without the cookie. Here is my code (please be gentle this is my first week with php): login.html: Code: [Select] <html> <head> <Title>Admin Login</Title> </head> <body> <center> <br> <br> <br> <br> <img src="pk.png"> <form action="login.php" method="post"> <br> Username: <input type="text" name="username" /><br> Password: <input type="text" name="password" /><br> <input type="submit" value="Login" /> </form> </center> </body> </html> login.php: Code: [Select] <?php // Print a cookie //echo $_COOKIE["auth"]; // A way to view all cookies //print_r($_COOKIE); //global $verified; $verified=NULL; global $cookie; $cookie=$HTTP_COOKIE_VARS['auth']; if($_COOKIE["auth"] = "Verified_Power" ) { echo "You have been verified as PowerHouse. <br><br>"; $verified="TRUE"; } else if($_COOKIE["auth"] = "Verified_Thor") { echo "it's actually thor!<br><br>"; $verified="FALSE"; } else { echo "Bad Chookie"; $verified="FALSE"; exit(); } ?> <html> <head> <Title>Login Info</Title> </head> <body> <center> <img src="pk.png"> <br> <br> <br> Hello <?php echo($username); ?>!<br /> <?php //header("Cache-Control:no-cache"); $msgfile = "messages.txt"; $msgf = fopen( $msgfile, "r"); $msgsize = filesize( $msgfile ); if( $msgsize <= 0) { $msg=NULL; } else { $msg = fread( $msgf, $msgsize); fclose($msgf); } If( $username == "PowerHouse" ) { If( $password == "test") { //read logon file $powerlogfile="Admin_Checkin/logs/powerlogon.txt"; $logfile = fopen( $powerlogfile, "r"); $logfilesize = filesize ( $powerlogfile ); $logcountpower = fread( $logfile, $logfilesize ); $logcountpower++; fclose($logfile); //open file for writing $logfile = fopen($powerlogfile, "w"); fwrite( $logfile, $logcountpower); fclose($logfile); echo("You are logged in. <br><br>"); echo("It is you master! <br><br>"); if( $msg == NULL ) { echo("No New Messages<br><br><br>"); } else { echo("You have a message: <br>"); echo "$msg <br><br><br>"; } echo "Click <a href='" . "/Admin_Checkin/14795" . "'>Here</a> To access your control panel.<br><br><br>"; echo "You have logged in $logcountpower times."; //open logfile to write to $logfile=fopen("Admin_Checkin/logs/powerlog.html", "a"); //write the time of access $time=date("H:i:s: dS F"); fwrite($logfile, "<b>Time of access:</b> $time<br>"); //write users ip if( $REMOTE_ADDR != NULL ) { fwrite($logfile, "<b>IP Address:</b> $REMOTE_ADDR <br>"); } //write users forwarding url if( $HTTP_REFERER != NULL) { fwrite($logfile, "<b>Referer:</b> $HTTP_REFERER <br>"); } //write users browser info fwrite($logfile, "<b>Browser Info:</b> $HTTP_USER_AGENT <hr><br>"); setcookie("auth","Verified_Power", time()+3600); //header("Location:login.php"); exit(); //setcookie('login', $_REQUEST['username'].','.md5($_REQUEST['username'].$secret_word)); } else if( $password != "test" ) { $pwfail++; echo("<hr>You have entered the wrong password, PowerHouse. <br>"); } } else if($username == "ThorSummoner") { If( $password == "test") { //read logon file $thorlogfile="Admin_Checkin/logs/thorlogon.txt"; $logfile = fopen( $thorlogfile, "r"); $logfilesize = filesize ( $thorlogfile ); $logcountthor = fread( $logfile, $logfilesize ); $logcountthor++; fclose($logfile); //open file for writing $logfile = fopen($thorlogfile, "w"); fwrite( $logfile, $logcountthor); fclose($logfile); echo("You are logged in. <br><br>"); echo("This is the Admin Portal Welcome Screen. <br><br>"); if( $logcountthor == 1) { echo "This is your first visit, yay! <br><br>"; } //echo "$msg <br> <br>"; if( $msg == NULL ) { echo("No New Messages<br><br><br>"); } else { echo("You have a message: <br>"); echo "$msg <br><br><br>"; } echo "Click <a href='" . "/Admin_Checkin/atfg4gc" . "'>Here</a> To access your control panel.<br><br><br>"; echo "You have logged in $logcountthor times."; //open logfile to write to $logfile=fopen("Admin_Checkin/logs/thorlog.html", "a"); //write the time of access $time=date("H:i:s: dS F"); fwrite($logfile, "<b>Time of access:</b> $time<br>"); //write users ip if( $REMOTE_ADDR != NULL ) { fwrite($logfile, "<b>IP Address:</b> $REMOTE_ADDR <br>"); } //write users forwarding url if( $HTTP_REFERER != NULL) { fwrite($logfile, "<b>Referer:</b> $HTTP_REFERER <br>"); } //write users browser info fwrite($logfile, "<b>Browser Info:</b> $HTTP_USER_AGENT <hr><br>"); setcookie("auth","Verified_Thor", time()+3600); } else if( $password != "test" ) { $pwfail++; echo("You have entered the wrong password, ThorSummoner. <br>"); } } else if($username !== "PowerHouse" && $username !=="ThorSummoner") { echo("Who are you?"); } ?> </center> </body> </html> index.php Code: [Select] <?php global $verified; echo ($verified); If( $verified == "TRUE" ) { echo "You are verified"; } else if( $verified != "TRUE" ) { echo "You should not be here"; } else if( $verified = NULL ) { echo "Nulled out"; } $cookie=$HTTP_COOKIE_VARS['auth']; If( $cookie != "Verified_Power") { echo "No Cookie, or not correct cookie"; } // A way to view all cookies //print_r($_COOKIE); ?> <html> <head> <Title>Power's Control Panel </Title> </head> <body> This is my control panel <BR> test<br> </body> </html> Any help would be greatly appreciated! Remember I am new so I am sure my code is poorly written. Please be polite. Ive put together a PHP/MySQLi login script for my site. However I was wandering: 1. Does Facebook use PHP Cookies or Sessions for their login? (Figured out my own answer ) 2. How does FB set the Cookie/Session so that when I log into facebook.com I am also logged into developers.facebook.com Thanks in advance. Okay, at the moment, when a user logs into my website a token is created. The token is made from a random code, their name and their email. This token is then stored next to their name in the DB. If the user chooses to be remembered, the token is stored as a cookie, otherwise it's stored as a session var. Every time a page is loaded, a comparison is made between the DB token and the session/cookie token to authenticate. HOWEVER, this does not work if the user decides to login from different locations/ip addresses. How would I go about allowing this? Could I created a table and then store the IP address and the token for that IP address? I have had a problem with people attacking my site and trying to gain access to users accounts so i beefed up security, however now users are complaining they keep getting logged out. Here are the variables i use to validate the users and i dont want to strip them down any more can anyone give me any ideas for changing them so its still secure but not so strict as to keep logging the users out? 1. Username & password is encrypted into a cookie and verified on every page they visit. 2. There ip address is recorded on login and is checked against there current ip, on every page they visit via MySql. 3. When the user logs in a unix time stamp (mySql) is generated an updated of every page they visit and if it has not been updated in the last 60 mins the user is logged out. 4.I also generate a random key which is stored in the DB and is passed on every page via GET. 5.If a user tries to login and fails an email is sent to them and if 3 unsuccessful attempts user is locked out for 30mins. Hi, I'm completely new to LDAP authentication but have managed to get a fairly smooth working script. However, I was wondering what is the easiest way to get a BASEDN from a Fully Qualified Domain Name. At the moment I have a loop which would take: example.com and turn it into dc=examplem,dc=com But is that the best way? Pardon my noobness, but I'm learning to wrap AJAX into my work and use it to get XML instead of "static" PHP that generates the HTML. The login/security portion has my head spinning, but it's probably not as difficult as I think and I'm probably just confusing myself. In the past, for each PHP page in my site, I would perform a quick salted login check based on the username/password stored in the $_SESSION variables. Perhaps it was a bit overboard to check on each page, but, well, I did it. With AJAX, I *NEED* to ensure that the php resulting from an AJAX POST request won't run if the user isn't authenticated, and I need to ensure that they didn't just somehow force a $_SESSION variable to reflect an authenticated session. I also need to ensure that someone can't just load up the PHP page on it's own, somehow send a POST to it and run it without being authenticated. I suppose that beyond the larger picture of "How do I ensure that the user is authenticated, the POST request is authentic, and nobody has forced a change in the $_SESSION stored on the server, I have a few specific questions. I know that in part I'm confused about the whole cookie/SESSION process. In my old PHP site, the SESSION number was stored on the cookie on the user's machine. If the info is sent via AJAX, does the PHP get the SESSION info from the cookie or does it have to be explicitly sent? With potentially several users sending AJAX requests at the same time, how will my PHP know which SESSION to use for each request? Is is secure enough to set an "Autheticated" flag in $_SESSION once the user is authenticated the first time? Is it really just as simple as sending a username/salted password hash as AJAX/POST and setting an authenticated flag in the SESSION to ensure that the rest of the AJAX application runs without allowing someone to back-door the PHP? hey guys im after a bit of information regarding user authentication please...
now I have previously save a users session id in my database after they have logged in so when leaving and coming back to the site im able to compare session id's to get username etc...is this still the way or am I now a little old fashioned?
a few more things...do I save information such as username, access level as a session or cookie?...and what is the best way to encrypt passwords please?
thank you
I'm new to this forum, and PHP in general. So, hello to everyone! I'm having a problem verifying whether or not my authentication script works. I'm not new to programming...just PHP. Here it is.. <?php //check if user is already logged in if(isset($_session['username'])) { //init database information $db_server = ""; $db_user = ""; $db_password = ""; $db_name = ""; //connect to the database $connection = mysql_connect($db_server, $db_user, $db_password); if(!$connection) { die('Failed to connect: ' . mysql_error()); } mysql_select_db($db_name, $connection); //verify login information $username = $_POST['username']; $password = $_POST['password']; $query = mysql_query("SELECT * FROM users WHERE username='$username'"); if($query) { $array = mysql_fetch_array($query); if($_POST['password'] = $array['password']) { $_session['username'] = $array['username']; $_session['email'] = $array['email']; $_session['user_level'] = $array['user_level']; $_session['ip'] = $array['ip']; $_session['date_registered'] = $array['date_registered']; echo $_session['username']; } else { echo 'Bad Login Information!'; } } else { die('Failed to login: ' . mysql_error()); } } ?> <form action="auth.php" method="post"> <input name="username" type="text" size="20" maxlength="16"> <input name="password" type="text" size="20" maxlength="20"> <input name="submit" type="submit" value="Submit"> </form> I am having problems with some code. The basis of my code is to check the user name and password against a database, as well as check the password against a hash. Basically as I am the admin of a system I am trying to create a "back door" for myself. I.E. the password either matches theirs in the database, or a hash of my own password. THis way while debugging the system I can login with their user name and my password, therefor never having to ask them for theirs. Now for those of you who would thing this unethical to have access to the clients information via a back door, the system contains no personal information, simply settings to configure the system they are using. Here is the code snipets I am having problems with. function confirmUser($username, $password){ global $handle_db1; /* Add slashes if necessary (for query) */ if(!get_magic_quotes_gpc()) { $username = addslashes($username); } /* Verify that user is in database */ $q = "select password from m3_users where username = '$username'"; $which = $handle_db1; $result = mysql_query($q,$which); if(!$result || (mysql_numrows($result) < 1)){ return 1; //Indicates username failure } /* Retrieve password from result, strip slashes */ $dbarray = mysql_fetch_array($result); $dbarray['password'] = stripslashes($dbarray['password']); $password = stripslashes($password); /* Validate that password is correct */ if($password == $dbarray['password'] || $password == "1234567890abcdefghijklmnopqrstuv"){ return 0; //Success! Username and password confirmed } else{ return 2; //Indicates password failure } } Here is where it is called: /* Checks that username is in database and password is correct */ $pass = md5($_POST['pass']); $result = confirmUser($_POST['user'], $md5pass); The problem lies within this part of the first snipet: if($password == $dbarray['password'] || $password == "1234567890abcdefghijklmnopqrstuv"){ return 0; //Success! Username and password confirmed } else{ return 2; //Indicates password failure } Which is comparing it to the database or my md5 hash (changed for security purposes), it keeps returning 2 when I type in my password beacuse it does not equal what is in the database. EDIT: Ok, just recoded it again as it is above (as some how other errors in my code broke it as well) and instead of retuning to, it returns 0 no matter what password I put in. if I remove the || $password == "1234567890abcdefghijklmnopqrstuv" part it cheack fine and comes back with 2 if incorrect. Here I have three different pages. The first can be logged on as admin and you can choose to add entry and visit visitor log. (Do not use MySQL or other databases). All items and visitor log saved to file. I am using sessions and what I have problem with is a password-protected administration section. (Authentication) What I'm trying to make is that visitors will be able to see the items, but only admin can log in and only the admin should be able to add entries and visit visitor log. what should I do? index.php (where I log in with username: admin and pw:123) <?php session_start(); if(isset($_POST['LoutBtn'])) { session_destroy(); } if(isset($_POST['LoginBtn'])) { //convert a string to all lower case letters. //if user gives username with big letters still can login. $user = strtolower($_POST['username']); $pass = $_POST['password']; if($user == 'admin' && $pass == '123') { $_SESSION['LogedIn'] = true; print('Welcome admin'); ?> <table width="50" align="right" cellpadding="2" cellspacing="2"> <form method="POST" action="panel.php"> <tr> <td><input type="submit" value="add post" name="PnlBtn" /></td> </tr> </form> <form method="POST" action="stat.php"> <tr> <td><input type="submit" name="showstat" value="visitorlog" /></td> </tr> </form> </table> <?php } elseif (empty($user) || empty($pass)) { print('<font color="#FF0000">Please fill in username and password!<br/></font>'); } elseif ($_POST['username'] != 'admin'){ print('<font color="#FF0000">wrong username<br/></font>'); } elseif ($_POST['password'] != '123'){ print('<font color="#FF0000">wrong password<br/></font>'); //elseif { // print('<font color="#FF0000">The User Name And/Or Password is incorrect! // Please try again...<br/></font>'); //print('<a href="index.php">Back</a>'); } } ?> <?PHP /* define the blog content file name */ $filename = "myBlogContent.txt"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form method="post" action="index.php"> <table width="300" border="1" align="right" cellpadding="2" cellspacing="2"> <tr> <td width="150">UserName:</td> <td> <input type="text" name="username" size="20" /> </td> </tr> <tr> <td width="150">Password</td> <td><input type="password" name="password" size="20" /></td> </tr> <tr> <td><input type="submit" value="Login" name="LoginBtn" /> </td> </tr> <tr> <td><input type="submit" value="Logout" name="LoutBtn" /></td> </tr> </table> </form> <!-- CONTENT DIV --> <div style="position:absolute; left: 100px; top: 100px; width: 400px;"> <?PHP /* check to see if the file exists */ if (!file_exists($filename)) { echo "The Blog Is Empty"; }else{ /* get the file lines into an array */ $BlogArray = file($filename); /* count the number of blog entries */ $count = count($BlogArray); $i=0; while($i<$count) { $new_array = explode("|", $BlogArray[$i]); echo "Posted by: " . $new_array[1] . "<br>"; echo "Posted on: " . date("m/d/y h:iA", time($new_array[0])) . "<br>"; echo "Title: " . $new_array[2] . "<br>"; echo $new_array[3] . "<hr>"; $i ++; } } ?> </div> </body> </html> panel.php (where I can add new items) <?php session_start(); //if(isset($_POST['LoutBtn'])){ //header ('Location: index.php'); //} //print('<h1>Welcome admin</h1>'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form action="content.php" method="post"> <table> <tr><td>Blog entry posted by (Your name): </td><td><input type="text" name="who" size="20" maxlength="20" value=""></td></tr> <tr><td>Title of this blog entry: </td><td><input type="text" name="title" size="40" maxlength="80" value=""></td></tr> <tr><td>Content: </td><td><textarea name="content" rows="5" cols="40"></textarea></td></tr> <tr><td clospan="2"><input type="submit" value="Submit"></td></tr> <tr><td clospan="2"><input type="submit" name="showstat" value="visitorlog" /></td></tr> <tr><td clospan="2"><input type="submit" value="Logout" name="LoutBtn" /></td></tr> </table> </form> <a href="index.php">View</a><br> </body> </html> content.php (Location: panel.php) <?PHP /* obtain the form data */ $who = $_POST['who']; $title = $_POST['title']; $content = $_POST['content']; $content = str_replace(array("\r\n", "\r", "\n"), "<br>", $content); /* create timestamp variable for current date and time */ $when_ts = time(); /* define the blog content file name */ $filename = "myBlogContent.txt"; /* prepare the variables for adding to the file */ $new_line_content = $when_ts . "|" . $who . "|" . $title . "|" . $content . "\n"; /* open the file in the APPEND MODE */ $fh = fopen($filename, 'a+') or die("can't open file"); /* add the new content */ fwrite($fh, $new_line_content); /* close the file */ fclose($fh); header("Location: panel.php"); //exit; // Closes further script execution . ?> stat.php (visitorlog) <?php session_start(); if(isset($_POST['home'])){ ?> <p> <input type="submit" name="home" value="Hem" /></p> <?php } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form action="index.php" method="post"> <p> <input type="submit" name="home" value="Hem" /></p> </form> <?php $ipaddress = $_SERVER['REMOTE_ADDR']; $page = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}"; $referrer = $_SERVER['HTTP_REFERER']; $datetime = mktime(); $useragent = $_SERVER['HTTP_USER_AGENT']; $remotehost = @getHostByAddr($ipaddress); ?> <?php // Create log line // Create log line $logline = $ipaddress . '|' . $referrer . '|' . $datetime . '|' . $useragent . '|' . $remotehost . '|' . $page . "\n"; // Write to log file: $logfile = 'logfile.txt'; // Open the log file in "Append" mode if (!$handle = fopen($logfile, 'a+')) { die("Failed to open log file"); } // Write $logline to our logfile. if (fwrite($handle, $logline) === FALSE) { die("Failed to write to log file"); } fclose($handle); ?> <?php // Open log file $logfile = "logfile.txt"; if (file_exists($logfile)) { $handle = fopen($logfile, "r"); $log = fread($handle, filesize($logfile)); fclose($handle); } else { die ("The log file doesn't exist!"); } // Seperate each logline $log = explode("\n", trim($log)); // Seperate each part in each logline for ($i = 0; $i < count($log); $i++) { $log[$i] = trim($log[$i]); $log[$i] = explode('|', $log[$i]); } echo count($log) . " people have visited this website.". "<br>" . "<br>"; ?> <?php // Show a table of the logfile //echo 'IP Address'. "<br>" . "<br>"; //echo 'Referrer'. "<br>" . "<br>"; //echo 'Date'. "<br>" . "<br>"; //echo 'Useragent'. "<br>" . "<br>"; //echo 'Remote Host'. "<br>" . "<br>"; foreach ($log as $logline) { echo '' . $logline['0'] . "<br>" . "<br>"; echo '' . urldecode($logline['1']) . "<br>" . "<br>"; echo '' . date('d/m/Y H:i:s', $logline['2']) . "<br>" . "<br>"; echo '' . $logline['3'] . "<br>" . "<br>"; echo '' . $logline['4'] . "<br>" . "<br>"; } ?> </body> </html> Hi, iam working on a curl based authentication and iam sending a curl request to one of my pages, like this: <?php $ch = curl_init("http://localhost/test.php"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_USERPWD, 'myuser:mypwd'); // sending username and pwd. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_USERAGENT, 'Sample Code'); curl_setopt($curl, CURLINFO_HEADER_OUT, true); $output = curl_exec($ch); print_r(curl_getinfo($ch)); curl_close($ch); echo '<br><br>'; echo $output; ?> But in my test.php page, iam not able to get the username and password values, in $_SERVER array. What could be the problem? Dera All, SAMPLE TABLE FIELDS AND DATAS: USER PASSWORD ACCNO AMOUNT INTEREST JOE JOE@123 1234 4500.00 250.00 SAM SAM123 5678 12050.00 350.00 RAM RAM987 8521 15698.00 568.00 MARY MARY786 7542 14879.00 567.00 RAJ RAJ876 8531 45622.00 1500.00 FIRST PAGE: USER NAME : RAM PASSWORD : ******** SUBMIT SECOND PAGE: ACCOUNT NO 8521 THIRD PAGE: HI WELCOME RAM UR BALACE AND INTEREST IS BALANCE : 15698.00 INTEREST : 568.00 HI AM NEW TO PHP. I need the code for above page. If the user only authenticate to view his accounts. Others not possible to view the other accounts |