PHP - Session Expiry/times
I've simply set some sessions....
$_SESSION['LoggedIn'] = 1; $_SESSION['UserID'] = $row["UserID"]; They don't seem to last very long, usually when I close my browser and go back on later, they'll expire. I want them to last permanently unless the user logs out. How do I do this? Thanks in advance. Similar TutorialsHello guys, I am new to PHP. I need some help. I am trying to build a web app, in which I have login functionality. I want to keep the logged in user session active for around 3-4 months. But in my case as soon as I close the browser, session data is lost and I need to login again. Can anyone help me with this. Hello, I am struggling here. Basically I have integrated a Google Maps API with a website to show the location of the next session. This script will take the next session and return its location, so the lat and long can be fetched from another table and fed into the API. Here is the timetable in a MySQL table: I am trying to do/say the following: * Show current session (if in progress) * Show next session. (Only to be fetched from db when the previous session has expired) * If there are no sessions left on today's date, show next session on next day with sessions. How could I write this as a PHP query in order to the fetch the location data? Thanks, George. I'm trying to get an expiry date to work on my project.... but at the moment... it doesnt seem to be working. Heres the code for the main news submission form: Code: [Select] <form action='newsubmit.php' method='POST'> Title: <input type='text' name='title' /><br /> Story: <input type='text' name='story' /><br /> Upload Image: <a href="#" onclick="window.open('fileuploadprocess.php','mywindow','width=450,height=300,toolbar=no,location=no,directories=no,s tatus=no,menubar=no,scrollbars=yes,copyhistory=yes,resizable=yes')"> Click here</a> <?php require_once('../../../2740/recaptcha/recaptchalib.php'); $publickey = "6Ldbd8ASAAAAAL96lIWHSDRmoaVJhgQJuKQwXNbd"; echo recaptcha_get_html($publickey); ?> <input type='submit' name='submit' value='Submit' /> <input name='reset' type='reset' value='Reset' /> </form> Heres the code for the submission page: Code: [Select] <?php include_once("functions.php"); session_start(); $submit = clean_string($_POST['submit']); $title = clean_string($_POST['title']); $story = clean_string($_POST['story']); $datetoday = date('Y-m-d', $expires); $daystoexpire = '7'; $expires = time() + (86400 * $daystoexpire); $userid = $_SESSION['userID']; $newsimage = $_SESSION['imagelocation']; $message = ''; require_once('../../../2740/recaptcha/recaptchalib.php'); $privatekey = "6Ldbd8ASAAAAAFz8VT29H5w4WLNjsbI-mFY2QkaC"; $resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); $message = ""; if ($submit == 'Submit') { if (!$resp->is_valid) { // What happens when the CAPTCHA was entered incorrectly $errMessage = $resp->error; $message = "<strong>The reCAPTCHA wasn't entered correctly. Please try again.</strong><br />" . "(reCAPTCHA said: $errMessage)<br />"; } else { // Process valid submission data here if ($title && $story) { //process details here if (strlen($title) > 80) { $message = "The title you have provided is too long. Please <a href='news_entry.php'>try again</a>"; } else { if (strlen($story) > 300) { $message = "The news story you have provided is too long. Please <a href='news_entry.php'>try again</a>"; } else { require_once("db_connect.php"); if ($db_server) { mysql_select_db("a200458721"); //Insert news story into news table $query = "INSERT INTO news (usersID, title, story, image, datetoday, expires) VALUES ('$userid', '$title', '$story', '$image', '$datetoday', '$expires')"; mysql_query($query) or die("User insert failed. " . mysql_error() . "<br />" . $query); $message = "News Story Successfully Submitted! Return to <a href='index.php'>homepage</a>"; } } } } else { $message = "Failed to connect to database"; } if ($expires < time()) { // Expired! } require_once("db_close.php"); } } else { $message = "please fill in all the required fields"; } echo $message; mysql_close($db_server); ?> At the moment, this is the error its throwing up: I'm not sure why its saying about the 1970 date either... User insert failed. Incorrect datetime value: '1303391514' for column 'expires' at row 1 INSERT INTO news (usersID, title, story, image, datetoday, expires) VALUES ('13', 'NEWS TITLE GOES HERE', 'NEWS STORY', '', '1970-01-01', '1303391514') Any ideas on why its throwing me up the error? We are working on a new student application system. Due to privacy laws, everything will be done behind https. However, this is one of many systems looked after by the system administrators. I would like to safeguard against the situation several years down the road when the certificate expires. There are several administration pages that will be checked frequently by the graduate admin assistant. While this person has no technical background, a warning several months before the certificate expires would allow her to remind the technical staff to renew the certificate. I know I can use curl to connect to my own server, but that seems like a long way to do it (and an extra https connection). Is there any way to get the certificate information for the current https connection from the server or from the php runtime? Hello all, I'm collecting date/time information via a form and would like to convert the info into something that I can stick in my MySql database (a timestamp???). I'm collecting the current month (variable name: month-- of the form "mm"), day (variable name: day -- of the form "dd"), year (variable name: year -- of the form "yyyy"), time of day (variable name: time -- of the form "h:00"), and before or after noon (variable name: ampm -- of the form "am" or "pm"). Any suggestions as to how to change this into a quantity that I can store as a value and then use to compare to other date/times would be appreciated. Thanks! in this page http://maximaart.com/newscp/ i have this problem Code: [Select] Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/maximasy/public_html/newscp/index.php:1) in /home/maximasy/public_html/newscp/index.php on line 2 my source code is <?php session_start(); include_once("config.php"); include_once("functions.php"); $errorMessage = ''; if (isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) { if ($_POST['txtUserId'] === "$user" && $_POST['txtPassword'] === "$pass") { // the user id and password match, $_SESSION['basic_is_logged_in'] = true; require("main.php"); exit;?> I am trying to create an index page which contains registration and login field the problem that i get is on successful login a warning is displayed session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\Eventz.com\index.php:116) in C:\xampp\htdocs\Eventz.com\index.php on line 235 This is the login part of my index.php this tag is inside an html table below the login form I also have a registration form and its php code above the login form Code: [Select] <?php if (isset($_REQUEST['pass'])) { $id=$_POST['id']; $pass=$_POST['pass']; $conn =mysql_connect("localhost","root",""); if (!$conn) { die('Could not connect: ' . mysql_error()); } /* checking connection....success! */ $e=mysql_select_db('test', $conn); if(!$e) { die(''.mysql_error()); } else { echo 'database selected successfully'; } if (isset($_REQUEST['id']) || (isset($_REQUEST['pass']))) { if($_REQUEST['id'] == "" || $_REQUEST['pass']=="") { echo "login fields cannot be empty"; } else { $sql=mysql_query("Select email,password from login where email='$id' AND password='$pass'"); $count=mysql_num_rows($sql); if($count==1) /* $count checks if username and password are in same row */ { session_start(); $_SESSION['id']=$id; echo "</br>Login Successful</br>"; } else { echo "</br>invalid</br>"; echo "please try to login again</br>"; } } } } ?> Any help or suggestion would be appreciated I am having trouble resolving an error. Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/s519970/public_html/header.php:27) in /home/s519970/public_html/admin/login.php on line 2 What I can gather is I can't use "header (Location: 'admin.php')" after i've used session_start(). I have tried to replace the header (Location: 'admin.php') with this: echo "<script>document.location.href='admin.php'</script>"; echo "<script>'Content-type: application/octet-stream'</script>"; I've been trying to read up on solutions but haven't been able to get it sorted. If anyone can offer some advice that would be greatly appreciated as im new to php. Code: [Select] <?php session_start(); if(isset($_SESSION['user'])) echo "<script>document.location.href='admin.php'</script>"; echo "<script>'Content-type: application/octet-stream'</script>"; ?> <div id="loginform"> <form action="dologin.php" method="post"> <table> <tr> <td><span>Username:</span></td> <td><input type="text" name="username" /></td> </tr> <tr> <td><span>Password:</span></td> <td><input type="password" name="password" /></td> </tr> <tr> <td colspan="2" align="right"><input type="submit" name="login" value="Login" /></td> </tr> </table> </form> </div> I have tried using require_once('yourpage.php'); before my <head></head> tags in the header document where I've specified the html information but this doesn't seem to work. I've been advised to use ob_start("ob_gzhandler"); but I am not sure how to implement this. Any advice is greatly appreciated! I'm making a simple login system with MySQL and PHP (very simple, I'm just starting with PHP). The MySQL portion is done, but I need to ensure only people who are logged in can see certain content. To check if people are logged in, my website checks that they have the $_SESSION['user'] variable set. If it is set, then it lets them continue through the website, if not, it tells them to login. Is that enough security, or can people simply inject a session cookie into their browser to spoof that they are logged in? My idea was to generate a session key cookie when they login (just a random string of letters and numbers) and store that in the database, then on every page, check to make sure their session key is the same thing that's in the database. Is this necessary? It seems expensive. hi everyone. i'm wondering what the best way is to create a session variable and pass it to an iframe. i need to do something along these lines, but it doesn't seem to pass the ID. Any hints on how i should accomplish this? Code: [Select] session_start(); $_SESSION['ID']=$_GET['ID']; // id from previous page $ID=session_id(); <iframe src="iframepage.php?ID=<?php echo $ID; ?>" style="width:680px; height:200px;" noresize="noresize" frameborder="0" border="0" scrolling="Yes" allowtransparency="true" /> </iframe> Just curious how other people feel about this. I am working on an application where a lot of info is pulled from MySQL and needed on multiple pages.
Would it make more sense to...
1. Pull all data ONCE and store it in SESSION variables to use on other pages
2. Pull the data from the database on each new page that needs it
I assume the preferred method is #1, but maybe there is some downside to using SESSION variables "too much"?
Side question that's kind of related: As far as URLs, is it preferable to have data stored in them (i.e. domain.com/somepage.php?somedata=something&otherdata=thisdata) or use SESSION variables to store that data so the URLs can stay general/clean (i.e. domain.com/somepage.php)?
Both are probably loaded questions but any possible insight would be appreciated.
Thanks!
Greg
Edited by galvin, 04 November 2014 - 10:30 AM. Evening! I've been iffing and ahhing over this and well im not too sure, hence the post. Code: [Select] // Redirects if there is no session id selected and echos the error on the previous page if(!isset($_GET['get']) || ($_GET['getget'])){ header("Location: #.php?error"); } So it should simply check if get is set if it isnt then see if getget is set? If not redirect and show the error. Now ive tried it and even when get/getget is set it still redirects, probably something silly. Care to share anyone? Harry. Hello All, I have tried to find a solution for this issue for days. The script was working fine until yesterday when all of a sudden I get this warning. Quote Warning: imagecreatefrompng(http://domain.com/images/broadcast1.png) [function.imagecreatefrompng]: failed to open stream: Connection timed out in /home/domain/public_html/logo/logo1.php on line 8 line 8 is: $image_1 = imagecreatefrompng($file_1); Where $file_1 = "http://domain.com/images/broadcast1.png"; The exact code is working perfectly fine in a different server I have, both servers are running Centos with PHP5 + GD fully enabled. The image http://domain.com/images/broadcast1.png (~5Kb) is loading very fast when open through a browser. Please please help me resolve this, I have tried many different things and even uninstall and install GD again but n luck. Thank you so much for your help. I need help with a query.
I've got a table that stores references to calls that come in to our office. It has a datetime field, and for the purposes of the query, it's the only thing in this table that is important.
I've got another table that stores appointment information. The appointment start time is also a datetime field. For this query, this start time is the only thing in this table that is important.
I need to know how many times in the last year there was a day when we had at least 150 calls come in and made at least 1 appointment.
SELECT COUNT(*) FROM appointments a LEFT JOIN ( SELECT DATE(time) FROM calls WHERE <there are at least 150 calls on a day> ) c ON DATE(a.start_time) = c.time WHERE a.start_time >= CURDATE() - INTERVAL 1 YEARTo make things difficult, I guess the time would have to be converted to a day, because I'm looking for all days where there was an appointment, and the datetime field is too specific. I've been looking online for 30 mins or so, and was hoping somebody here could point me in the right direction. I'm not making much progress by myself. Edited by sKunKbad, 06 October 2014 - 01:17 PM. Hi all I am trying to edit a piece of code to change possible times for a booking system. This is the code I have: $count=0; for($b=$startTime;$b<$endTime;$b++){ if($count==$tempVar2){ $availability .= "</td><td align='left' valign='top'>"; } if(in_array($b,$reservedArray)){ $availability .= $b.":00 ".($b<12?"am":"pm")." - ".($b+1).":00 ".($b+1<12?"am":"pm")." - Booked.<br>"; } else { $availability .=$b.":00 ".($b<12?"am":"pm")." - ".($b+1).":15 ".($b+1<13?"am":"pm")."- <input type=\"checkbox\" value=\"".$b."\" name=\"time[]\" ><br>"; } $count++; } It gives me the following times: 09:00 am - 10:15 am 10:00 am - 11:15 am 11:00 am - 12:15 am 12:00 pm - 13:15 pm 13:00 pm - 14:15 pm 14:00 pm - 15:15 pm 15:00 pm - 16:15 pm 16:00 pm - 17:15 pm How can I change it so I can have the following times available: 10:00 am - 10:30 am 10:45 am - 11:15 am 11:30 am - 12:00 pm 12:15 pm - 12:30 pm etc... Many thanks for you help Pete. Hello friends, i'm getting error due to using an function for 3 times in same time if i've 3 results and i want to base36_encode the 3 output it only encode one and then gives me error Cannot redeclare base36_encode() (previously declared) here is the code // this is the encode function // function base36_encode($base10){ return base_convert($base10,10,36); } // i'm getting output here as 3 times (id) // $id = base36_encode($line[id]); echo "$id<br>"; the out but should be like this id1 id2 id3 all have been base36 encoded but it only show the 1st one id1 and the rest gives me the error above... so how can i make it works for all results not only the 1st one thanks everybody Hi everyone, I'm trying to add up the current time with a specified amount of seconds and insert it in a database afterwards. When I add say: 500 seconds to the current time it adds a whole lot more and I get a number few thousands higher than I want. Can anyone help me???. Gr Ryflex I have a form created that seems to work across most devices/connection.. but for some reason some phones, Androids specifically so far, seem to time out when the form is submitted using the mobile network. This has happened on multiple android phones. Doesn't seem to have an issue with iPhones. I also had a problem with a Surface tablet when connected to an android wireless signal.. tethering, the same phone that had the issue.
So what happens is once the form is submitted, it hangs for a while and then it'll say "No data received - Unable to load the webpage because the server sent no data. Reload this webpage Press the reload button to resubmit the data needed to load the page. Error code: ERR_EMPTY_RESPONSE" and then after i refresh, it submits and goes through without a problem. Sometimes it refreshsed by itself after flashing this error and goes through.
Another time, using the Surface Pro, wifi and IE, I got the error "Forbidden" you don't have permission to access /new-window-2.php on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
You can see an example of one of the forms here - connecttopros(dot)com/windows.php
And some of the code is attached below. I'm lost. I've tried using a different server completely, twice, and it didn't fix the issue, so it must be the way the php is put together? Thanks for your help!
Attached Files
Php Freaks.zip 12.25KB
1 downloads Hi guys, i got the following code i wrote which displays a small pop up on screen if the user has mail, and display a little icon. The problem is it displays a new icon for each new mail message. How can i make it so it only display 1 icon no matter how many unread mail the user has. Or even better if not too complicated display a number next too the image? Code: [Select] <? require'xxxxxxxxxxxxxxxxx.php'; mysql_select_db("membership") or die( "Unable to select database"); $sql=("SELECT * FROM user_alerts WHERE user_id = '".($_SESSION['user_id'])."'") or die (mysql_error()); if ($query=@mysql_query($sql)) { if (mysql_num_rows($query) > 0) { while ($req=mysql_fetch_array($query)) { if ($req['messageRead'] == 'NO') { ?> <div> <img src="xxxxxxxxxxxxxx.png" width="32" height="32" alt="unread mail" /> <a href="http://www.xxxxxxxxxxxx/account=account">You have Mail!</a> <div id="boxes"> <div style="top: 199.5px; left: 551.5px; display: none;" id="dialog" class="window"> <h2>You have new mail!</h2> <br /> <p>Visit your account page to read it.</p> <br> <a href="#" class="close">Close Window</a> </div> <!-- Mask to cover the whole screen --> <div style="width: 1478px; height: 602px; display: none; opacity: 0.8;" id="mask"></div> </div> </div> <? } } } } You can ignore most of the div stuff but that's pretty much it. It should check my database for any entries with the users session id in the column called 'user_id'. and only show the image if it then finds an entry with 'NO' in the 'messageRead' column. It currently shows the images for each entry it finds. Thanks for any help |