PHP - "remember Me" Session/cookie Problems.
What I'm trying to accomplish is your average session login w/ a cookie-based "remember me" feature.
I can log in fine, I can set cookies, I can access those cookies, and I can use that data to log in just as if the user had logged in manually. The problem is logging out. But the bigger problem is figuring out why. You see, it works perfect. It logs in and it log out, so long as I am outputting data to the page. I was outputting a session variable and the cookies I set to make sure they were all working right; and they were. But then as soon as I disable those echoes, all of a sudden it won't log out anymore. So then I turn them on to see what the data says and BAM, I'm logged out. I log back in fine, I log back out fine, so I turn em off again. I log in fine. I can't log out. I try multiple times. I close my browser and open a new one. Still logged in. I try a few more times, still logged in. I turn the output back on, load the page again and I'm logged out. So... WTF? (my code to follow) Similar TutorialsCan someone please help me with an array problem i can not figure out. I need the array to be numbered from 1 to how ever many fields that are needed in the form and have a mysql field name and the title of the field also in the array. 1, "mysql_field_name", "Title of form field" 2, "", "" and so on then the form will be shown based on the array. I have the following draft code which I am working with. any suggestions on how i may do this array ? Code: [Select] <?php $options = array( '1'=> array('fieldtext'=>'option1', 'mysqlfield'=>'option1'), '2'=> array('fieldtext'=>'option2', 'mysqlfield'=>'option2'), '3'=> array('fieldtext'=>'option3', 'mysqlfield'=>'option3'), '4'=> array('fieldtext'=>'option4', 'mysqlfield'=>'option4'), ); // $options = array(1 => "option1", "option2", "option3", "option4"); // the line above works but i want to include the name of the mysql field as well. $userid = 1; ?> <div style="align: center; margin: 12px; font-family:Tahoma;"> <br><br><?php if ($_POST['Update'] != "Update") { // check if form submitted yet, if not get data from mysql. $res = db_query("SELECT * FROM `users` WHERE `userid` = '" . $userid . "'"); foreach($options as $key => $value) { $_POST[$key] = mysql_result($res, 0, $value); } $ok_to_update = "no"; } elseif ($_POST['Update'] == "Update") { // check if form submitted yet, if so get POST data. // error checking // foreach($options as $key => $value) { // $_POST[$i] = ""; // } $ok_to_update = "yes"; } if ($_POST['Update'] == "Update" && $ok_to_update == "yes") { // $res = db_query("INSERT INTO `users` () VALUES ()"); // add user details to database. ?><p><br><br><br>Thank you for updating</p><?php } else { ?><form name="form1" method="post" action=""> <?php foreach($options as $key => $value) { ?><p><?php echo($value); ?>: <input type="text" name="<?php echo($key); ?>" value="<?php echo($_POST[$key]);?>"></p> <?php } ?> <input name="Update" type="submit" value="Update"> </form> <?php } ?> </div> Hello all, I'm using sessions to store a username/password For example, I have the following at the top of all my source files: Code: [Select] <?php session_start(); if(!isset($_SESSION['myusername'])){ header("Location:login.php"); exit; } else { $username = $_SESSION['myusername']; $permissionLevel = $_SESSION['mypermissionlevel']; } ?> Now, I'd like to add a "Remember Me" checkbox so they can store their login info (securely!) so they don't have to log in all the time.... How do I do this? Thanks Hi, bit stuck on how to find and replace "<" and ">" with "<" and ">". I basically have a database record that outputs to screen and I need the code in the <code> tags to be rendered to the screen. I therefore need it to go through the whole array variable from the db and change the symbols just inside the code tags. Please be aware that the code tags might happen more than once here's an example below Code: [Select] <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1> </code> <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1> </code> the desired output would be: <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1 </code> <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1 </code> help on this would be great Cheers Rob Hi guys,i was trying to figure out how to work with <select> tag, remember/set the value that was being selected before. The values are fetched from the database..From other forums I've been, they said that $_SESSION will do the work but I'm having trouble where to put it inside my code.. Please take a look at this Code: [Select] <form name="form1" action="do_set.php"> <?php $sql="SELECT school_year FROM admin_sy ORDER BY school_year ASC" or die (mysql_error()); $result=mysql_query($sql); echo "Set schoolyear: <select name=SY value=''>"; while($row=mysql_fetch_array($result)) { echo "<option value=$row[school_year]>$row[school_year]</option>"; } echo "</select>"; ?> <br> Sem: <select name="sem"> <option value="1st">1st</option> <option value="2nd">2nd</option> <option value="Summer">Summer</option> </select> <input type="Submit" name="submit" value="Set"> </form> as you can see, 'school_year' are fetched from a database. now my problem is, when i select a specific year, the value should be "remembered" after i click set or refresh the page or go back from the previous page. this will be useful so the user will be able to know what school year has already been set. hope you guys can help.. thanks in advance. Hi guys I am a newbie with PHP and I have been trying to solve this problem for 3 days.. Ive set up a booking form on my website to be sent directly to my email once the client clicked on the send button.. The problem I am having while checking these pages on wamp is that the booking form is ok but when I click on the send button the following message error appears "Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\fluffy_paws\booking_form2.php on line 27" When I check online I have this message "500 - Internal server error. There is a problem with the resource you are looking for, and it cannot be displayed." Are my codes wrong??? My webhosting is Blacknight.com , Im on Windows Vista, my internet is a dongle with O2 ireland Thanks for your help! Hi guys I'm struggling a bit, I need to replace a word that occurs multiple times in text with an array("up","down","forward","backwards") of words. $find = "left"; $replace = array("up","down","forward","backwards"); $text = "left left left left"; echo str_replace($find,$replace,$text); The Output is: array array array array Did try this with a foreach statement as well, but no luck. Is there a better way of doing this? Thanks Hi All, first of all. Sorry for signing up to the site and then immediately asking for help. I hate doing it but always seems to be the way people get involved with forums these days and it seems I am no different... So thank you in advance if you are kind enough to answer! Among many personal flaws, my issue is a technical one regarding the ability to retain session variables. Unfortunately whilst the website itself is not complicated, the problem is not as simple as just running session_start(); and letting it get on and do its own thing. So the problem exists around a relatively simple contact form and the basic Turing test that it uses to prove the user is human. The script adds a value to the $_SESSION variable and then on the next page load, tests to see if the variable is still there. As per this little function: function cookiesEnabled() { if ($_SESSION['cookiesEnabledTest']) $_SESSION['cookiesEnabled'] = true; else $_SESSION['cookiesEnabledTest'] = true; } Now for what must be 95% of all users, the variable is still there, proving the the session is being maintained as the user navigates the site. Unfortunately a small group of computers appear to be having difficulties with this for a not too clear reason. The computers have varying browser user agents indicating that they are all (so far) using one of the following: MSIE 8 MSIE 7 MSIE 7 in what appears to be MSIE 6 compatibility mode Now in testing, I can't get MSIE 8 or MSIE 7 to produce the same effect, with exception to MSIE 8 in "InPrivate" browsing mode. In this mode it is easy to see that there is no cookie txt file being created and thus no way of the browser to pass back the session id on the next page load. I can't think of any detail that I have missed out, but if there is anything I have left unclear, please let me know! Thanks again! Felix cant work out this mysql syntax error "operation":"medupdate","medid":"","name":"ibo","medyear":"5","medmonth":"21","medday":"1","recuser":1,"SuccFail":"fail","SuccFailMessage":"error occured You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '''WHERE med_id=' at line 2","ResultData":""} Code: [Select] $sql="update metodology set med_description='".$req['name']."', med_year='".$req['medyear']."', med_month='".$req['medmonth']."', med_day='".$req['medday']."', med_recorddate= now(), med_recorduserid= 1'"; $sql.= " WHERE med_id=".$req['medid']; Code: [Select] <?php session_start(); $index="1"; $_SESSION[$index]=2; echo "$_SESSION[$index]"; ?> Hi good day check how to have a variable "$index" inside session.. I'm trying to post to a (SMF) simplemachines 2.0 forum using curl. I have logged in and I have tried sending all the fields, but when I try to post, I receive this message: "The following error or errors occurred while posting this message: Your session timed out while posting. Please try to re-submit your message." Do any of you know why this happens? Is the problem that when I visit the posting url, they give me a cookie that expires if I leave the posting url? I don't think the form is invalid, it looks like it has to do with the session. People at the simplemachines forum can have this problem when they try to post the ordinary way, but that is because of an inactivity period. Can my problem be because of a cookie? I am getting the following error when using composer: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? Just started. I am pretty sure composer.json wasn't changed. journalctl doesn't show anything. Maybe Doctrine related, however, nothing seems to help.
Any ideas? [michael@devserver www]$ php -v PHP 7.3.4 (cli) (built: Apr 2 2019 13:48:50) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.4, Copyright (c) 1998-2018 Zend Technologies with DBG v9.1.9, (C) 2000,2018, by Dmitri Dmitrienko [michael@devserver www]$ composer -V Composer version 1.4.2 2017-05-17 08:17:52 [michael@devserver www]$ yum info composer Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirror.us.oneandone.net * epel: mirror.rnet.missouri.edu * extras: mirror.us.oneandone.net * remi-php73: mirror.bebout.net * remi-safe: mirror.bebout.net * updates: mirror.us.oneandone.net Installed Packages Name : composer Arch : noarch Version : 1.8.4 Release : 1.el7 Size : 1.8 M Repo : installed From repo : epel Summary : Dependency Manager for PHP URL : https://getcomposer.org/ License : MIT Description : Composer helps you declare, manage and install dependencies of PHP projects, : ensuring you have the right stack everywhere. : : Documentation: https://getcomposer.org/doc/ [michael@devserver www]$ composer update Loading composer repositories with package information Updating dependencies (including require-dev) [ErrorException] "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? update [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--lock] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [--no-suggest] [--with-dependencies] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [-i|--interactive] [--root-reqs] [--] [<packages>]... [michael@devserver www]$
This topic has been moved to Linux. http://www.phpfreaks.com/forums/index.php?topic=318175.0 I'm just doing a tutorial, learning PHP/mySQL for the first time, and have been having problems getting PHP to talk to mySQL, so to speak. The tutorial is from he http://www.youtube.com/watch?v=Gei4AYkpAi8&feature=player_detailpage#t=276s Here is the code: <?php $link = mysql_connect('http://192.168.0.8:3307', 'ddd1600', ''); if (!$link) { die('Could not connect: ' . mysql_error()); } // make foo the current db $db_selected = mysql_select_db('test', $link); if (!$db_selected) { die ('Could not connect: ' . mysql_error()); }else{ echo "It worked!"; } $sql = "INSERT INTO `test`.`Table2` ( `ID` , `name` , `content` ) VALUES ( NULL , 'apples', 'are grown by Australians.');" ; ?> My server is on my private network, by the way. Thanks! PS: If it helps, here is the error message from Chrome browser or any other browser: Warning: mysql_connect() [function.mysql-connect]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp\htdocs\PhpProject1\index.php on line 4 Warning: mysql_connect() [function.mysql-connect]: [2002] php_network_getaddresses: getaddrinfo failed: No such host is known. (trying to connect via tcp://http:3306) in C:\xampp\htdocs\PhpProject1\index.php on line 4 Warning: mysql_connect() [function.mysql-connect]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp\htdocs\PhpProject1\index.php on line 4 Could not connect: php_network_getaddresses: getaddrinfo failed: No such host is known. Hi, I currently have an if, elseif, else program that starts off with Code: [Select] if( $v_name == "" || $v_msg == "" ) echo "something" how do I turn this into a switch? but the very next elseif I have Code: [Select] elseif( strcspn( $_REQUEST['msg'], '0123456789' ) == strlen( $_REQUEST['msg'] ) ) echo "something" is it possible to turn this into a switch with 2 different strings like that to evaluate? I have a registration form on my website and after Registration I want the user to activate first his account. I don't have problem on sending this email to the user. What I want to appear is like this.. GoodDay "username", Blah Blah! how can you actually do that? I know that you can do that through session variables but the thing is email's can't accept scripts on sending emails. how can I get the value from a session variable for example and convert it to plain html text so that i can OUTPUT it to the email.. HELP PLEASE! This topic has been moved to PHP Installation & Configuration. http://www.phpfreaks.com/forums/index.php?topic=347922.0 Hey guys! I have the following doubt: I have a php file that does the following alongside with other code not displayed he $fp = fopen("emails.txt", "w"); It opens a txt file called emails.txt that is in the same folder where the php is saved but how do I tell $fp = fopen("/folderbefore/emails.txt", "w"); ?? In other words, how do I write the path on the script that the emails.txt is located in a previous folder where the php file is located?? Thanks in advance for your help Cheers! hello, I was wondering what is the point of writing for a dropdown: <?php if ($_POST[inputfieldID] == "value") { echo "selected"; } ?> or for a checkbox/ radio button: <?php if ($_POST['cb/radioID'] == "value") { echo "checked"; } ?> I guess it's for after submit, if there is any error, the values filled will still be echoed in the inputfield, or am i wrong? But then if that is true, i have a php search box where i use AJAX object to to send all the input they filled in after submit. But after pushing submit the inputted values remain. I guess when using AJAX to send the information i don't need <?php if ($_POST[inputfieldID] == "value") { echo "selected"; } ?> in my html forms? Little confused Can maybe somebody bring clearness Hi all, Using a form with check boxes divided into different categories, I collect data selected by the user. I now want to combine each choice in each category with each choice in the other categories and list the combinations to the user. If the user chooses one or more options in each category, it is relatively easy to nest foreach loops, since the number of categories will always be the same. For example, if the form contains three categories of options, the code will be: Code: [Select] foreach ($form['cat_1'] as $k1 => $val1) { foreach ($form['cat_2'] as $k2 => $val2) { foreach ($form['cat_3'] as $k3 => $val3) { echo $val1.' _ '.$val2.' _ '.$val3.'<br/>'; } } } Things get complicated if the user does not select options within a given category. More generally, I want to be able to generate the list regardless of the number of categories in which the user selects options. Thank you in advance for your advice. |