PHP - Php Timing Out With Session Problem
For a while now I've been getting intermittent problems with PHP either slowing down or very occasionally timing out for no apparent reason. For the first time it's happened a number of times today and there is an error message in the logs:
PHP Fatal error: Maximum execution time of 30 seconds exceeded in functions.php on line 4, referer:search.php The odd thing is that line 4 of functions.php only contains: $sess = session_id(); I've never had a problem with PHP that digging around in this forum hasn't solved but this one has me stumped. Anyone got any ideas? TIA Similar TutorialsI'm trying to run 5 php scripts that all run about ~200 MySQL commands each. The basic framwork is: 1.) Fetch a list of names from a table 2.) Names are put in an array, Loop starts 3.) For each name that is retrieved, it is matched with a name on a website (Echo for each name retrieved for logging purposes) 4.) the information retrieved from the website is stored in the table (using UPDATE) 5.) repeated for each name, until the end of the list is reached. And it works, but seldom. When I run these in a web browser, some of the scripts that fetch a larger list of names from the table times out, whereas the shorter lists will succeed in a full update. I've also tried setting these up as a Cron job (I'm using Hosting24 as my host), but the output is no better. The log shows that it runs about 8-9 names before stopping. No error, no nothing. Just end of log. I've tried using set_time_limit(); and have set it to 0 for unlimited, and even tried setting it really high (anywhere between 100 and 900 seconds), but to no avail. Is there anything else I can do? #1 my function to find out if my store is closed function determineTime() { $hour = date("H"); if (($hour < '09' || $hour >= '21')) { return true; } else { return false; } } #2 my case switch to find out if the "trip" departs in less then <24 hours or <48 hours etc..... $myDiff = dateDiff(date("m/d/Y H:i:s"), "$dep_date 05:00:00"); list($myHour, $myMinute) = split(',', $myDiff); //echo $myHour.'<br/>'; //echo $myMinute; if(!isset($myHour)) $myHour = 0; $nowTime = date("H:i:s"); $futureTime = date("H:i:s", strtotime("$nowTime + 2 hours")); //echo '<h1>*'.$nowTime.'*</h1>'; //echo '<h1>*'.$futureTime.'*</h1>'; //$departures = $db->query("$dep_query $dep_where $dep_order"); // NO TIME RESTRICTIONS switch($myHour){ default: case "": break; case ($myHour <= 24): $_SESSION['addToTotal'] = $passengers*5; if(determineTime()){ //we are closed //if the store is closed and it is TODAY do not allow the users to book a trip before 9am $departures = $db->query("$dep_query $dep_where AND trips.times > '09:00:00' $dep_order"); //run query }else{ //we are open //if open allow the user to book, but only for trips that are for 2 HOURS out and GREATER $departures = $db->query("$dep_query $dep_where AND (trips.times > '$futureTime' OR trips.times > '09:00:00') $dep_order"); //run query } break; case ($myHour > 24 && $myHour < 48): $_SESSION['addToTotal'] = $passengers*5; $departures = $db->query("$dep_query $dep_where $dep_order"); //run query break; } All my times are in H:i:s format. Somewhere for some reason that when we are closed users can still book trips that are for 5am. Hi guys, I'm trying to create a script which changes on curtain times, heres a example: 3pm - Dance Session 4pm - Indie Session 5pm - RnB Session What i want the desired outcome to be is Display current time with whats playing (say its 3pm) 3pm - Dance Session Then at 4 i want it to remove the 3pm and display the 4pm - Indie Session Is it possible? If so how? Many thanks for you time guys! J Folks, I am running Linux Commands in PHP. I am looping through the Domain list and using the below line in my Script: exec('cp -r '.$source.' '.$destination); I am using this in a Foreach Statment, so only the last Even in the loop getting executed, because, the loop is running too fast so the Linux command does not even get initiated, only the last even in loop goes through. What i have done is, i have added a line after exec(); sleep(30); This gives enough time for Linux command to get executed, but is it efficient way to handle timing liek this? Do i need to use time_limit() or something like that? Cheers Natasha Can someone propose a solution to resolve the following: I have a PHP script that runs just fine when processing small amounts of data (opening and reading CSV file and performing afew validation checks before saving to db). Issue: when attempting to process a large file, I have found the execution time exceeds the "timeout" value currently set on the server which is 60 seconds. Note: I do not want to increase this time interval as that's a security risk so need to figure out a way to break up the data - being read from the CSV file - into chunks and some way create mini-processes (I guess) to execute chunks of that data at a time until the entire file is read. Any suggestions? I have a quick question about a script I wrote that searches all .jpg images in a directory (and it's sub-directories) and makes thumbnails of them. The problem I am having is that I am getting an internal server error after about 15 seconds. I have included my script, the class it requires, and my php.ini file that resides in the root of my site. I have searched for a couple of hours online and haven't been able to come up with an answer as to why I am getting that error. The thumbnail file... Code: [Select] <?php set_time_limit(0); require_once('classes/Create_Thumbnail.php'); $filter = '.jpg'; $directory = 'media'; // Do not include a trailing slash $it = new RecursiveDirectoryIterator("$directory"); foreach(new RecursiveIteratorIterator($it) as $file) { if (!((strpos(strtolower($file), $filter)) === false) || empty($filter)) { $items[] = preg_replace("#\\\#", "/", $file); } } foreach ($items as $item) { $photo = new Create_Thumbnail($item); $photo->createThumbnail(); } ?> The Create_Thumbnail class... Code: [Select] <?php class Create_Thumbnail { private $_photo; private $_photoBasename; private $_photoWidth; private $_photoHeight; private $_photoType; private $_resizedPhoto; private $_thumbFolder; private $_thumbWidth = 125; private $_thumbHeight = 125; private $_thumbSuffix = '_thumb'; private $_thumbnail; /** * Constructor retrieves photo's basename, extension, width, and height. */ public function __construct($photo) { $this->_photo = $photo; $this->_photoBasename = pathinfo($this->_photo, PATHINFO_FILENAME); $this->_extension = pathinfo($this->_photo, PATHINFO_EXTENSION); $this->_thumbFolder = dirname($photo) . '/'; list($this->_photoWidth, $this->_photoHeight, $this->_photoType) = getimagesize($this->_photo); } /** * Method to resize the original image to a size that is much closer to the desired thumbnail size. */ public function resize() { $photoRatio = $this->calculatePhotoRatio(); if ($photoRatio != 1) { $this->_resizedWidth = round($this->_photoWidth * $photoRatio); $this->_resizedHeight = round($this->_photoHeight * $photoRatio); } else { $this->_resizedWidth = $this->_thumbWidth; $this->_resizedHeight = $this->_thumbHeight; } $resource = $this->createResource($this->_photoType, $this->_photo); $resized = imagecreatetruecolor($this->_resizedWidth, $this->_resizedHeight); imagecopyresampled($resized, $resource, 0, 0, 0, 0, $this->_resizedWidth, $this->_resizedHeight, $this->_photoWidth, $this->_photoHeight); $this->_resizedPhoto = $this->_thumbFolder . $this->_photoBasename . '_resized.' . $this->_extension; $this->createNewImage($this->_photoType, $resized, $this->_resizedPhoto); imagedestroy($resource); imagedestroy($resized); return $this->_resizedPhoto; } /** * Method to create the thumbnail. */ public function createThumbnail() { $source = $this->resize(); list($width_original, $height_original, $type) = getimagesize($source); $base_name = pathinfo($source, PATHINFO_FILENAME); $base_name = str_replace('_resized', '', $base_name); $extension = pathinfo($source, PATHINFO_EXTENSION); $source_x = ($width_original / 2) - ($this->_thumbWidth / 2); $source_y = ($height_original / 2) - ($this->_thumbHeight / 2); $resource = $this->createResource($type, $source); $thumb = imagecreatetruecolor($this->_thumbWidth, $this->_thumbHeight); imagecopyresampled($thumb, $resource, 0, 0, $source_x, $source_y, $this->_thumbWidth, $this->_thumbHeight, $this->_thumbWidth, $this->_thumbHeight); $this->_thumbnail = $this->_thumbFolder . $base_name . $this->_thumbSuffix . '.' . $extension; $this->createNewImage($type, $thumb, $this->_thumbnail); unlink($source); return $this->_thumbnail; } /** * Method to create an image resource. */ public function createResource($type, $source) { switch ($type) { case 1: $resource = imagecreatefromgif($source); break; case 2: $resource = imagecreatefromjpeg($source); break; case 3: $resource = imagecreatefrompng($source); break; } return $resource; } /** * Method to calculate the photo ratio. */ public function calculatePhotoRatio() { if ($this->_photoWidth > $this->_photoHeight) { $maximumHeight = $this->_thumbHeight; $photoRatio = $maximumHeight / $this->_photoHeight; } elseif ($this->_photoWidth < $this->_photoHeight) { $maximumWidth = $this->_thumbWidth; $photoRatio = $maximumWidth / $this->_photoWidth; } else { $photoRatio = 1; } return $photoRatio; } /** * Method to create a new image. */ public function createNewImage($type, $source, $destination) { switch ($type) { case 1: if (function_exists('imagegif')) { imagegif($source, $destination); } else { imagejpeg($source, $destination, 50); } break; case 2: imagejpeg($source, $destination, 100); break; case 3: imagepng($source, $destination); break; } } } The php.ini file... Code: [Select] file_uploads on upload_max_filesize = 150M post_max_size = 150M max_input_time = -1 max_execution_time = 0 memory_limit = 150M register_argc_argv = false I have a ptc site in php I want that all my ads will refresh at midnight in Pakistani time but server based in USA please let me know how it will happen I have a file name titulos.php and this is code please help me thanks. <tr> <td bgcolor="<?=$highlight?>"> <? require('config.php'); $sqle = "SELECT * FROM tb_ads WHERE user='$last' and ident='$id'"; $resulte = mysql_query($sqle); $myrow = mysql_fetch_array($resulte); mysql_close($con); $time=$myrow['visitime']; $crok1 = date(time()); $crok2 = date($time + (24 * 60 * 60)); if($crok1 >= $crok2) { ?><?=$bold?><a href="view.php?ad=<?=$id?>" target="_blank"><?=$description?></a><?=$boldc?><? } else { ?><del><?=$description?><del><? } ?> </td> <tD bgcolor="<?=$highlight?>"> <?=$members?> </td> <td bgcolor="<?=$highlight?>"> <?=$outside?> </td> <td bgcolor="<?=$highlight?>"> <?=$total?> </td> </tr> This topic has been moved to Linux. http://www.phpfreaks.com/forums/index.php?topic=317079.0 Hi guys , my script works perfectly in Gmail however i now need it to work in Outlook , when the form is submitted i get this error.
2014-10-25 18:49:00 SMTP ERROR: Failed to connect to server: Connection timed out (110) 2014-10-25 18:49:00 SMTP connect() failed. Mailer Error: SMTP connect() failed.
<?php require("../lib/phpmailer/PHPMailerAutoload.php"); if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['phone']) || empty($_POST['message']) || !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)) { echo "No arguments Provided!"; return false; } $m = new PHPMailer(); $m->IsSMTP(); $m->SMTPAuth = true; $m->SMTPDebug = 2; $m->Host = "smtp.live.com"; $m->Username = "test@outlook.com"; $m->Password = "pass"; $m->SMTPSecure = 'tls'; $m->Port = 465; // ive also tried 587 $m->From = "test@outlook.com"; $m->FromName = "test@outlook.com"; $m->addReplyTo('test@outlook.com ','Reply Address'); $m->addAddress('test@outlook.com', 'Some Guy'); $name = $_POST['name']; $email_address = $_POST['email']; $phone = $_POST['phone']; $message = $_POST['message']; $m->Subject = $subject; $m->Body = "You have received a new message. <br><br>". " Here are the details:<br> Name: $name <br> Phone Number: $phone <br>". "Email: $email_address<br> Message <br> $message"; $m->AltBody = "You have received a new message. <br><br>". " Here are the details:<br> Name: $name <br> Phone Number: $phone <br>". "Email: $email_address<br> Message <br> $message"; if(!$m->Send()) { echo "Mailer Error: " . $m->ErrorInfo; } else { echo "Message sent!"; return true; } ?> I'm using xampp and am trying to create a login session...these are the my php files login.php Code: [Select] <form action='login1.php' method='post'> Email: <input type='text' name='id'></br> Pass : <input type='password' name='pass'></br> <input type='submit' name='login' value='login'> login1.php Code: [Select] <?php $id=$_POST['id']; $pass=$_POST['pass']; $conn=mysql_connect("localhost","root",""); if (!$conn) { die('Could not connect: ' . mysql_error()); } $e=mysql_select_db('test', $conn); if(!$e) { die(''.mysql_error()); } else { echo 'database selected successfully'; } $sql=mysql_query("Select email,password from login where email='$id' AND password='$pass'"); $count=mysql_num_rows($sql); if($count==1) { session_start(); echo "</br>Login Successful</br>"; echo "Please wait 5 seconds "; /* redirct to the specified page */ header("refresh:5;url=empty.php"); } else { echo "please try to login again</br>"; echo "you will be redirected to the login page in 5 seconds"; /* redirct to the specified page */ header("refresh:5;url=login.php"); } mysql_close(); ?> empty.php Code: [Select] <?php session_start(); $logi=$_SESSION['id']; echo 'welcome '.$logi; ?> empty.php is supposed to display the email id from login.php I checked it about an hour ago and it was working fine but now it gives me an error Undefined index: id in C:\xampp\htdocs\littleprogress\empty.php on line 4 I didn't change anything after checking it. only cleared the history and cookies of my firefox browser what could be the problem Hello Everyone! I have 2 problems with sessions that I'd like some assistance with. 1. The session often ends after clicking any link after logging in. (sometimes it remains alive, and in those cases it stays alive until browser is closed.) 2. The function that should start a session if a cookie is found (and correct) is not working, so if the browser is closed and re-opened the session won't start the session. I'll include the code that I think is relevant. The odd part is that these problems occur in every browser, I have tried multiple tutorials (so different scripts) to creating a login form but somehow the same result appears every time. function login($username, $password, $remember = false) { $sql = mysql_query("SELECT * FROM users WHERE password = '" . md5($password) . "' AND username = '" . $username . "' LIMIT 1"); // If there are no matches then the username and password do not match if($sql === false) { return false; } else { while($u = mysql_fetch_array($sql)) { // Check if user wants account to be saved in cookie if($remember == true) { // Generate new auth key for each log in (so old auth key can not be used multiple times in case // of cookie hijacking) $cookie_auth= rand_string(10) . $username; $auth_key = session_encrypt($cookie_auth); $auth_query = mysql_query("UPDATE users SET auth_key = '" . $auth_key . "' WHERE username = '" . $username . "'"); setcookie("auth_key", $auth_key, time() + 60 * 60 * 24 * 7, "/", "mycorrectwebsite.com", false, true); } // Assign variables to session session_regenerate_id(true); $session_id = $u[id]; $session_username = $username; $session_level = $u[user_level]; $_SESSION['user_id'] = $session_id; $_SESSION['user_level'] = $session_level; $_SESSION['user_name'] = $session_username; $_SESSION['user_lastactive'] = time(); return true; } } } function initiate() { $logged_in = false; if(isset($_SESSION['user_name'])) { $logged_in = true; } // Check that cookie is set if(isset($_COOKIE['auth_key'])) { $auth_key = $_COOKIE['auth_key']; if($logged_in === false) { // Select user from database where auth key matches (auth keys are unique) $auth_key_query = mysql_query("SELECT username, password FROM users WHERE auth_key = '" . $auth_key . "' LIMIT 1"); if($auth_key_query === false) { // If auth key does not belong to a user delete the cookie setcookie("auth_key", "", time() - 3600); } else { while($u = mysql_fetch_array($auth_key_query)) { // Go ahead and log in login($u['username'], $u['password'], true); } } } else { setcookie("auth_key", "", time() - 3600); } } } And then in the header I start every page with: <?php session_start(); include("connect.php"); include("functions.php"); include("actions.php"); initiate(); ?> I have this error, and I cann't find soluiton: Code: [Select] Notice: Undefined index: ime in C:\wamp\www\web\login_public.php on line 26 Notice: Undefined index: ime in C:\wamp\www\web\login_public.php on line 27 This is the code: Code: [Select] <?php require_once("public/includes/session.php"); ?> <?php require_once("public/includes/connection.php"); ?> <?php if(!$_POST['submit']){ header('refresh:0; url=index.php');} else { $korisnik = $_POST['korisnicko_ime']; $lozinka = $_POST['lozinka']; $lozinka_db = sha1($lozinka); if ($korisnik && $lozinka){ $query = mysql_query("SELECT * FROM korisnik WHERE korisnicko_ime = '$korisnik' "); $numrow = mysql_num_rows($query); if($numrow != 0){ while ($row = mysql_fetch_assoc($query)){ $korisnik_db = $row['korisnicko_ime']; $db_lozinka = $row['lozinka']; $ime = $row['ime']; } if ($korisnik == $korisnik_db && $lozinka_db == $db_lozinka){ echo "Uspesno ste ulogovani"; $_SESSION['ime'] == $ime; echo $_SESSION['ime']; } else { echo "Lozinka je netacna"; } } else {die("Korisnik ne postoji");} } } ?> What seems to be the problem This is my first post here. G'day everyone. I'm having trouble with getting a session recognized from one page to another. I did a search and used the advice but I'm still having trouble. I have a page called checklogin.php that processes the information submitted for a member to login, and redirect it to login_success.php if the login was successful. The problem I have is when I test the session in the second page it tells me there is no session. Here's my code (I omitted the db connection code): Code: [Select] <?php // username and password sent from form $myusername=$_POST['user']; $mypassword=$_POST['pass']; ?> <? // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" $_SESSION['myusername']=$myusername; $_SESSION['mypassword']=$mypassword; header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ?> after I am redirected to login_success.php: Code: [Select] <?php session_start(); $_SESSION['myusername']; if (isset($_SESSION['myusername'])) { $loggedin = TRUE; return $loggedin; echo "logged in."; } else echo "not logged in"; ?> It echoes "not logged in". I've struggled with this for days and I don't know what's wrong. Thanks in advance. I'm writing a shopping cart type of application for booking something. The cart will holds items as arrays in the session. The problem i'm i'm having is i can store 5 items in my cart and then once i try to store any more, it just won't. I'm not getting any php errors. I'm using the codeigniter framework, so it may be a codeigniter session storage problem. Hopefully you guys can look at it and can see if you spot any bad logic that i'm overlooking. Code: [Select] <?php //generates random unique 32 character string $booking_hash = random_string('unique'); //set items foreach night foreach($room['date_rate'] as $date => $rate) { //produces random sha1 16 char length string $sha1 = random_string('sha1', 16); $session['items'][$sha1] = array( 'code' => $room['code'], 'id' => $room_id, 'title' => $room['title'], 'date' => date("n/j/Y",strtotime($date)), 'price' => $rate, 'tax_one' => money_format('%i',$room['tax_one'] * $rate), 'tax_two' => money_format('%i',$room['tax_two'] * $rate), 'sales_tax' => 0, 'guests' => $num_guests, 'booking' => $booking_hash, 'deposit' => $deposit, ); } $existing_items = $this->session->userdata('items'); if(!empty($existing_items)) { $session['items'] = $existing_items + $session['items']; } $this->session->set_userdata($session); ?> I just read some codeigniter session documentation. It says the cookie it's using can hold 4KB of data. I have no idea how much text 4KB can hold... Hi, I"m trying to make an external link to a web page. Them problem is that when my user clicks on the link they are taken to the destination web page, but they see an error "Your session has expired". At that point, they must either refresh the browser or exit out and click again in order to see the page. My question is, how can I go around this problem in my code? If at all possible, I like to be able to add something to the URL so that this does not happen. Any help or guidance is appreciated. Hi Guys, I am developer and relatively new to php although I have written a few scripts. I have a site which runs on linux/unix platform. I am facing a weird problem: - I have a php script (e.g. site.com/test/test.php) which takes a input from url, and creates a session and opens a wordpress php in another folder (e.g. site.com/wp/index.php) - I wrote a small php code in that wp/index.php which checks if session exists or not. if yes, then no problem, if not then die and show a message. Now the problem is when I run the script, it opens the wp/index.php and the page opens. Good. But when I click on any link in that page e.g about or so, then I get message which I wrote that session not found and so on... I don't know why this is happening. So if you guys can help me with this it would be great. Alternatively, I thought if I protect the wp folder (using protect folder thru cpanel) and write a php script outside which call the php inside the wp folder with a hardcoded uname & pw, then i can run the php inside without anyone knowing what the actual uname or pw is. This way if a user directly tries to access it , he wont be able to do so as uname & password box will appear. But I dunno how to call a php inside protected folder. I tried to redirect but the uname & pw box appeared. I would be grateful if anyone can help me. Thanks a lot, Cheers, GR Hi guys. Im making a script that stores different contents in sessions. And everything seems to be working fine. I previously had some problems with it, but managed to fix them. Now somehow a new problem have accrued for me. I did not do anything to it since it last worked. So i am a little confused. It keeps telling me that the session does not have any content. I think that the problem is within these two files he http://pastebin.com/T6sfzjWn and http://pastebin.com/BUAuFp6t It keeps giving me the error on line 24 from the second file. Can someone please help me and say what i am doing wrong? which is the best place to put this code : Code: [Select] if(isset($_SESSION['last_ip'])===false){ $_SESSION['last_ip']=$_SERVER['REMOTE_ADDR']; } if($_SESSION['last_ip']!==$_SERVER['REMOTE_ADDR']){ session_unset(); session_destroy(); } like this : Code: [Select] class session { public $user_on=false; public $user_id; function __construct(){ //make sure that javascript can not access session variable ini_set('session.cookie_httponly',true); session_start(); //set the last ip the user has logged on with if(isset($_SESSION['last_ip'])===false){ $_SESSION['last_ip']=$_SERVER['REMOTE_ADDR']; } if($_SESSION['last_ip']!==$_SERVER['REMOTE_ADDR']){ session_unset(); session_destroy(); } $this->check_login(); } private function check_login(){ if(isset($_SESSION['user_id'])){ global $user; $this->user_id=$_SESSION['user_id']; $this->user_on=true; $user->find_by_id($this->user_id); } else { unset($this->user_id); $this->user_on=false; } } } OR : Code: [Select] function __construct(){ //make sure that javascript can not access session variable ini_set('session.cookie_httponly',true); session_start(); $this->check_login(); } private function check_login(){ if(isset($_SESSION['user_id'])){ global $user; [b]//set the last ip the user has logged on with if(isset($_SESSION['last_ip'])===false){ $_SESSION['last_ip']=$_SERVER['REMOTE_ADDR']; } if($_SESSION['last_ip']!==$_SERVER['REMOTE_ADDR']){ session_unset(); session_destroy(); }[/b] elseif($_SESSION['last_ip']===$_SERVER['REMOTE_ADDR']){ $this->user_id=$_SESSION['user_id']; $this->user_on=true; $user->find_by_id($this->user_id); } } else { unset($this->user_id); $this->user_on=false; } } } Hello, I have the $_session code working, but after I destroy the session and I am asked to log in again, my browser doesn't ask me for my password and just logs me in. I don't understand because I have destroyed my session and I have deleted the data in $_SESSION and I have deleted the info in the cookie so it shouldn't log me in automatically. I thought it was something in my browser, but I erased my history and I never saved any password. Here's my code: This is the welcome page <?php require_once 'login.php'; $connection = new mysqli($db_hostname, $db_username, $db_password, $db_database); if ($connection->connect_error) die($connection->connect_error); if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { $un_temp = mysql_entities_fix_string($connection, $_SERVER['PHP_AUTH_USER']); $pw_temp = mysql_entities_fix_string($connection, $_SERVER['PHP_AUTH_PW']); $query = "SELECT * FROM users WHERE username='$un_temp'"; $result = $connection->query($query); if (!$result) die($connection->error); elseif ($result->num_rows) { $row = $result->fetch_array(MYSQLI_NUM); $result->close(); $salt1 = "qm&h*"; $salt2 = "pg!@"; $token = hash('ripemd128', "$salt1$pw_temp$salt2"); if ($token == $row[3]) { session_start(); $_SESSION['username'] = $un_temp; $_SESSION['password'] = $pw_temp; $_SESSION['forename'] = $row[0]; $_SESSION['surname'] = $row[1]; echo "$row[0] $row[1] : Hi $row[0], you are now logged in as '$row[2]'"; die("<p><a href=continue.php>Click here to continue</a></p>"); } else die("Invalid username/password combination"); } else die("Invalid username/password combination"); } else { header('WWW-Authenticate: Basic realm="Restricted Section"'); header('HTTP/1.0 401 Unauthorized'); die("Please enter your username and password"); } $connection->close(); function mysql_entities_fix_string($connection, $string) { return htmlentities(mysql_fix_string($connection, $string)); } function mysql_fix_string($connection, $string) { if (get_magic_quotes_gpc()) $string = stripslashes($string); return $connection->real_escape_string($string); } ?> and this is the other page: <?php session_start(); if(isset($_SESSION['username'])) { $username = $_SESSION['username']; $password = $_SESSION['password']; $forename = $_SESSION['forename']; $surname = $_SESSION['surname']; destroy_session_and_data(); echo "Welcome back $forename. <br> Your full name is $forename $surname.<br> Your username is '$username' and your password is '$password'."; } else echo "Please <a href='authenticate2.php'>Click here</a> to log in."; function destroy_session_and_data() { $_SESSION = array(); setcookie(session_name(), '', time() - 2592000,'/'); session_destroy(); } ?>
When I type the website in i first get prompt to enter my password, when I am authenticated the webpage says: You are now logged in click here to continue. When I do I am directed to another page which confirms that I am still logged in. Then I press refresh and the webpage asks me to "Click here to log in". I do, but it doesn't ask me for my password again. Why? My personal info should be destroyed. Thank you for responding. It's greatly appreciated
Hi, I my first problem is hashing passwords to md5. My second problem is defining session on value from db. There is my code but not working. Code: [Select] mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $username=$_POST['username']; $password=$_POST['password']; $hash = md5($password); $username = stripslashes($username); $password = stripslashes($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); $sql="SELECT * FROM $tbl_name WHERE where username = '$username' and password = '$hash'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ $sql2="SELECT access FROM $tbl_name WHERE username='$username' and password='$password'"; $access=mysql_query("$sql2"); session_register("username"); session_register("password"); session_register("access"); $_SESSION["access"]=$access; header("location:success.php"); } else { echo "Invalid Username or Password";Thanks for any answers. |