PHP - Problem With $_session Values
I am trying to create a history of requested URI's (upto 3) for two purposes Login page and Error Logging. My problem is the Session is written and the values are set yet i can not retrieve the values in it upon a refresh. The use of an Array is to manage the quantity of max values (not written in yet).
<?phpSession contains REQUEST_URI|a:1:{i:0;s:19:"1422925783,/~Debug/";}After a refresh i expect REQUEST_URI|a:2:{i:0;s:19:"1422925783,/~Debug/";i:1;s:28:"1422925784,/~Debug/index.php";}Yet it only contains REQUEST_URI|a:1:{i:0;s:28:"1422925784,/~Debug/index.php";} Similar Tutorials
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. Is there a way to make it
How can I go about removing a $_SESSION entity if certain array values of it equal a specific value? I am thinking something along the lines of this: if (isset($_SESSION['cart']['content'][$_POST['id']])) = array ('sizes' => 0, 'sizem' => 0, 'sizel' => 0, 'sizexl' => 0) { // remove $_SESSION['cart']['content'][$_POST['id']] } Hi all, I'm in trouble with a strange problem. At the system login a script sets a $_SESSION['status'], this keeps user status for admin (a), user (u), and so on... In another part of the system I need to post a value also called 'status': Code: [Select] <input value="N" type="hidden" name="status"/> and this 'status' value has nothing to do with 'status' session. The problem is that when I post the value 'N' it overwrite the session value, crashing the system then. The most strange is that on the localhost the problem does not happen, it only occurs on the server. Any clue? Thankx Danilo Jr. Hiya, I'm quite new to php. My script was working fine till I transferred to a new host. The login system doesn't seem to register the $_SESSION 'userid' variable, so the proper page won't load because it thinks I'm not logged in. login.php - processes the login information Code: [Select] <?php session_start(); include('functions.php'); connect(); // note: session_start needs to be on every document apart // from index.php, login.php and register.php $username = protect($_POST['username']); $password = protect($_POST['password']); // the password and username from the inputs are stored in variables if ($username&&$password) { // if both the username and password variables are true $query = mysql_query("SELECT * FROM users WHERE username='$username'"); $numrow = mysql_num_rows($query); if ($numrow!=0) { // if $numrow does not equal nothing while ($row = mysql_fetch_assoc($query)) { $userid = $row['userid']; $dbusername = $row['username']; $dbpassword = $row['password']; } if ($username==$dbusername&&md5($password)==$dbpassword) { // $password gets encrypted so it can be checked on the database password $_SESSION['username'] = $username; $_SESSION['userid'] = $userid; // used for sessions knowing who is logged in header("Location:main.php"); // redirects to main.php page after successful login } else { echo "Incorrect password"; } } else { ?> <html> <head> <title>University Crusade</title> <link rel="stylesheet" href="css/style.css" type="text/css" media="screen"> <meta name="viewport" content="width=device-width, minimum-scale=1,maximum-scale=1, user-scalable=no"> </head> <body> <div id="wrapper"> <?php die (" That account doesn't exist...<br /><a href=\"index.php\">try again,</a> <a href=\"register.php\">or register an account.</a> "); } } else { die("Please enter a username and password"); } ?> </div> <div id="footer"> </div> </body> </html> and the main.php - after login.php it takes the user here Code: [Select] <?php session_start(); include('functions.php'); connect(); ?> <html> <head> <title>University Crusade</title> <link rel="stylesheet" href="css/new.css" type="text/css" media="screen"> <meta name="viewport" content="width=device-width, minimum-scale=1,maximum-scale=1, user-scalable=no"> </head> <body> <?php if (isset($_SESSION['userid'])) { include('safe.php'); ?> <ul id="tab-nav"> <li><a href="stats.php" id="tab-character">CHARACTER</a></li> <li><a href="games.php" id="tab-games">GAMES</a></li> <li><a href="account.php" id="tab-account">ACCOUNT</a></li> </ul> <div id="wrapper"> <h2 id="name">Hello, <?php echo $_SESSION['username'] ?>!</h2> <p> Welcome to UNIVERSITY CRUSADE the fantasy-themed pervasive web game! </p> <p> To start playing, begin with clicking the "games" button at the top of the screen, from there choose a challenge and follow the instructions </p> <p> What are the other buttons for? Well, the "account" button (top-right) is where you can change settings for your account - things like changing your password, deleting your account etc. The "character" button (top-left) when clicked takes you to your character, you can change your display picture, view your statistics and battle other players. </p> <p> More help with the game is available in the "account" section, this includes a detailed game manual describing in-detail game concepts and information. </p> </div> <div id="footer"> <a href="logout.php" class="button">log me out</a> </div> <?php } else { die (" <div id=\"wrapper\"> <p>Opps! You don't seem to be logged in...</p> <a class=\"button\" href=\"index.php\">login now</a><br /> <p>Don't have an account? No worries, just <a href=\"register.php\">register for one.</a></p> </div> "); } ?> </body> </html> I appreciate any help, as I'm left scratching my head. Hi, I'm kinda new to php, so I followed a video tutorial on making a login/registration system and nearly everything works, except for when a registered user follows a link to the members.php page, the $_SESSION variable is supposed to check if they are logged-in and say "Welcome, [name of user]!. But it keeps saying I need to be logged in, even though I am. The php code from the members.php page. Code: [Select] if ($_SESSION['username']) { echo "Welcome," .$_SESSION['username']. "!"; } else { die ("You must be logged in."); } This is the php code form the login page. Code: [Select] session_start(); $username = $_POST['username']; $password = $_POST['password']; if ($username&&$password) { $connect = mysql_connect("localhost","root","password") or die ("Unable to connect"); mysql_select_db("database") or die ("Unable to find database"); $query = mysql_query("SELECT * FROM users WHERE username='$username'"); $numrow = mysql_num_rows($query); if ($numrow!=0) { // while ($row = mysql_fetch_assoc($query)) { $dbusername = $row['username']; $dbpassword = $row['password']; } if ($username==$dbusername&&md5($password)==$dbpassword) echo "You're in! - <a href=\"members.php\">Go to members page</a>"; $_SESSION['username'] == $dbusername; } else { echo "Incorrect password"; } } else { die ("That user doesn't exist"); } } else { die("Please enter a username and password"); } Any help would be much appreciated. So like When somones enter my site it shows them as a guest, but then if they havn't clicked anywere for about 5minutes and then refresh or if somone else refresh it will delete from the active users list because it's been over 5 minutes, but then if that same person refreshes again my script wont catch them as a GUEST AGAIN!! It just shows no one online, none of my if's catch him and put him in the ibf_session table! Code: [Select] //check for cookies //If no username, Is a Guest, Has COOKIE_ID and cookie USER_NAME and COOKIe PASSWORD if(!isset($_SESSION['user_name']) && !isset($_SESSION['is_guest']) && isset($_COOKIE['user_id']) && isset($_COOKIE['user_name']) && isset($_COOKIE['password'])){ $user_cond = "user_name='{$_COOKIE['user_name']}'"; $sql = "SELECT `id`,`user_name`,`approved` FROM users WHERE $user_cond AND `pwd` = '{$_COOKIE['password']}' AND `banned` = '0' "; $result = mysql_query($sql) or die (mysql_error()); $num = mysql_num_rows($result); // Match row found with more than 1 results - the user is authenticated. if ( $num > 0 ) { list($id,$full_name,$approved) = mysql_fetch_row($result); if(!$approved) { echo "YOU FREAKING HACKER"; exit(); } $_SESSION['user_id']= $id; $_SESSION['user_name'] = $full_name; $lol = session_id(); //$minute5 = 30 ? (time() - 30) : (time() - 3600); // mysql_query("DELETE FROM ibf_sessions WHERE running_time < {$minute5}"); mysql_query("INSERT INTO ibf_sessions (id, member_name, member_id, ip_address, running_time, location, member_group) ". "VALUES ('".$lol."', '{$_SESSION['user_name']}', '{$_SESSION['user_id']}', '{$_SERVER['REMOTE_ADDR']}', '".time()."', ". "'Index', '1')") or die(mysql_error()); unset($_SESSION['is_guest']); } } $lol = session_id(); //Thanks if (!$id) { //Create Guest Session ~ if (!isset($_SESSION['user_id']) && @(!$_SESSION['is_guest']) && !isset($_COOKIE['password'])) { //$minute5 = 39 ? (time() - 30) : (time() - 3600); //echo $minute5; // mysql_query("DELETE FROM ibf_sessions WHERE running_time < {$minute5}"); mysql_query("INSERT INTO ibf_sessions (id, member_name, member_id, ip_address, running_time, location, member_group) ". "VALUES ('".$lol."', 'Guest', '0', '{$_SERVER['REMOTE_ADDR']}', '".time()."', ". "'Index', '0')") or die(mysql_error()); $_SESSION['is_guest'] = 'yes'; } } if (isset($_SESSION['user_id']) && !isset($_SESSION['is_guest'])) { mysql_query("UPDATE ibf_sessions SET member_name='{$_SESSION['user_name']}',member_id='{$_SESSION['user_id']}',member_group='1', running_time='".time()."', in_forum='".$f."', in_topic='".$topicid."', location='".$act."' WHERE id='".$lol."'") or die(mysql_error()); } else { mysql_query("UPDATE ibf_sessions SET member_name='Guest',member_id='0',member_group='0', running_time='".time()."', in_forum='".$f."', in_topic='".$topicid."', location='".$act."' WHERE id='".$lol."'") or die(mysql_error()); } Thanks, it might be confusing but re read Hi folks, I have an initial redirect page which directs to my main page, sending two reference variables as $_GET parameters: Code: [Select] header("Location: /ob/index.php?id=".$id."&ref=".$ref); The first thing this main page does is include a file which checks for those two values: Code: [Select] if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); session_start(); error_reporting(E_ALL); if (isset($_GET['id']) && isset($_GET['ref'])){ $_SESSION['id'] = $_GET['id']; $_SESSION['ref'] = $_GET['ref']; } if(!isset($_SESSION['id']) || $_SESSION['id']=="" || !isset($_SESSION['ref']) || $_SESSION['ref']==""){ echo ("This service requires a valid ID to run - your session may have expired, please refresh your browser to try again."); exit; } The main page loads fine - meaning that the $_SESSION variables have been set correctly. However, when the next page loads (including the same file), the $_GET values obviously aren't there but the $_SESSION variables should be intact. I am getting fails every time though in Opera and Safari (have checked in IE, FF and Chrome and all seems well). However, if I then refresh the browser - in both Opera and Safari - the next page loads fine and the $_SESSION variables are correctly set. Any ideas on this at all? Many thanks in advance, Rich Hi, I am using a $_SESSION for my shopping cart but cannot figure out how to total my quantity. The format I am using is: $_SESSION['cart']['itemid']['qty'] I realise that i could write a for loop to start at item id 0 and end at 1000 each time totalling the qty field but there must be a better, more efficient way, Does anybody have any advice? Mark Hi there I have been working on a login PHP script and had it working until I made so change late at night and forgot to back it up. The script uses PHP and Javascript as well as a Mysql database. The problem I am having is with the session closing unexpectedly when I go to enter the profile (or any other button placed after the login). It is rather hard to explain so here is the code [syntax=php]<?php //login php script include_once 'rnfunctions.php'; $theaction='index14.php'; function destroySession() { $_SESSION=array(); if ((session_id() != '') || isset($_COOKIE[session_name()])){ setcookie(session_name(),'', time()-2592000,'/'); session_destroy(); } } function startsessions($user,$pass,$theaction) { session_start(); session_name($user); $_SESSION['user'] = $user; $_SESSION['pass'] = $pass; $theuser =($_SESSION['user']); echo "You are now logged in as $theuser"; } function loggedin($theaction) { echo <<<_END <table> <tr> <td> <form name="myform" method='post' action='$theaction'> <input type='hidden' name='logout'value='logout' /> <a href="#" onMouseDown="submitform(0);">logout</a> | </form> </td> <td> <form name="myform2" method='post' action='$theaction'> <input type='hidden' name='profile'value='profile' /> <a href="#" onMouseDown="submitform(2);">profile</a> | </form> </td> <td> <form name="myform3" method='post' action='$theaction'> <input type='hidden' name='unregister'value='unregister' /> <a href="#" onMouseDown="submitform(3);">unregister</a> </form> </td> </tr> </table> _END; } function loginform($theaction) { echo <<<_END <table border="0"> <tr> <form name="myform" method='post' action='$theaction'> <td>Username-> </td><td> <input type='text' STYLE="color: #FFFFFF; font-family: Verdana; font-size: 12px; background-color: #1BCE11;" id ='password' id='username' size='12' maxlength='16' name='user' value='user' /></td> </tr> <tr> <td>Password-> </td><td> <input type='text' STYLE="color: #FFFFFF; font-family: Verdana; font-size: 12px; background-color: #1BCE11;" id ='password' size='12' maxlength='16' name='pass' value='pass' /></td> </tr> <tr> <td colspan="2"><a href="#" onMouseDown="submitform(0);">login</a></td> </form> </tr><tr><td colspan="2"> <form name="myform2" method='post' action='$theaction'> <input type='hidden' name='register'value='register' /> <a href="#" onMouseDown="submitform(2);">register</a> </form></td></tr> <tr><td colspan="2"> <form name="myform3" method='post' action='$theaction'> <input type='hidden' name='reset'value='reset' /> <a href="#" onMouseDown="submitform(3);">reset password</a></td> </tr> </table> _END; } function regform($theaction) { echo <<<_END <table border="0"> <tr> <form name="myform" method='post' action='$theaction'> <td>Username-> </td><td> <input type='text'STYLE="color: #FFFFFF; font-family: Verdana; font-size: 12px; background-color: #1BCE11;" size='12' maxlength='16' name='username' value='username' onBlur='checkUser(this)'/></td> </tr> <tr> <td>Password-> </td><td> <input type='password' STYLE="color: #FFFFFF; font-family: Verdana; font-size: 12px; background-color: #1BCE11;" size='12' maxlength='16' name='password' value='password' onBlur='checkpass(this)'/></td> </tr> <tr> <td>Email-> </td><td> <input type='text' STYLE="color: #FFFFFF; font-family: Verdana; font-size: 12px; background-color: #1BCE11;"size='12' maxlength='30' name='email' value='email' onBlur='checkEmail(this)'/></td> </tr> <tr> <td colspan="2"><a href="#" onMouseDown="submitform(0);">register</a> </form></td></tr><tr> <td colspan="2"> <form name="myform2" method='post' action='$theaction'> <input type='hidden' name='login'value='login' /> <a href="#" onMouseDown="submitform(2);">login</a> </form> </td> </tr> </table> <span id='logtext'></span> _END; } function retlogin($theaction) { echo <<<_END <form name="myform" method='post' action='$theaction'> <input type='hidden' name='login'value='login' /> <a href="#" onMouseDown="submitform(0);">back to login</a> </form> _END; } function resetform($theaction) { echo <<<_END <table border="0"> <tr> <form name="myform" method='post' action='$theaction'> <td>Enter New Password-> </td><td> <input type='password' STYLE="color: #FFFFFF; font-family: Verdana; font-size: 12px; background-color: #1BCE11;"size='12' maxlength='16' name='password1' value='password1' onBlur='checkpass(this)'/></td> </tr> <tr> <td>Email-> </td><td> <input type='text' STYLE="color: #FFFFFF; font-family: Verdana; font-size: 12px; background-color: #1BCE11;" id ='password' size='12' maxlength='30' name='email' value='email'onBlur='checkreset(this)'/></td> </tr> <tr> <td colspan="2"><a href="#" onMouseDown="submitform(0);">reset password</a> </form></td></tr><tr> <td colspan="2"> <form name="myform2" method='post' action='$theaction'> <input type='hidden' name='login'value='login' /> <a href="#" onMouseDown="submitform(2);">back to login</a> </form> </td> </tr> </table> <span id='logtext'></span> _END; } if (isset($_POST['login'])) { loginform($theaction); } elseif (isset($_POST['logout'])) { echo "you have logged out"; destroySession(); loginform($theaction); } //recieve reset password call elseif (isset($_POST['reset'])) { resetform($theaction); } //recieve reset password info elseif (isset($_POST['password1'])) { $theemail = $_POST['email']; $newpass = $_POST['password1']; //salt hash password for replacement $newpass = encriptpass($newpass); $query = "SELECT * FROM users WHERE email='$theemail'"; if (mysql_num_rows(queryMysql($query)) == 0) { echo "Email invalid please register<br />"; regform($theaction); } else { $message = validate_password($newpass); if ($message =="") { $regaddress = "http://www.imandanband.com.resetpass.php?newpass=".$newpass."&email=".$theemail; $to = $theemail; $subject = "Reset password at Imandan"; $body = "Hi there,\n\nYou have requested to reset your password to $newpass.\n\nPlease click the following link to validate your new password\n\n$regaddress or ignore this message if it has been sent in error"; if (mail($to, $subject, $body)) { echo("Message successfully sent! Go to your email to validate your new password"); retlogin($theaction); } else { echo("Message delivery failed...You must enter a valid email address"); } } } } elseif (isset($_POST['user'])) { $user = sanitizeString($_POST['user']); $pass = sanitizeString($_POST['pass']); $pass = encriptpass($pass); if ($user == "" || $pass == "") { $error = "Not all fields were entered<br />"; } else { $query = "SELECT user, pass FROM users WHERE user='$user' AND pass ='$pass'"; if (mysql_num_rows(queryMysql($query)) == 0) { echo "Username/Password invalid<br />"; loginform($theaction); } else { startsessions($user,$pass,$theaction); showprofile(); } } Hi there I have been working on a login PHP script and had it working until I made so change late at night and forgot to back it up. The script uses PHP and Javascript as well as a Mysql database. The problem I am having is with the session closing unexpectedly when I go to enter the profile (or any other button placed after the login). It is rather hard to explain so here is the PHP code <?php //login php script include_once 'rnfunctions.php'; $theaction='index14.php'; function destroySession() { $_SESSION=array(); if ((session_id() != '') || isset($_COOKIE[session_name()])){ setcookie(session_name(),'', time()-2592000,'/'); [color=#FFBF40]session_destroy();[/color] } } function startsessions($user,$pass,$theaction) { session_start(); session_name($user); $_SESSION['user'] = $user; $_SESSION['pass'] = $pass; $theuser =($_SESSION['user']); echo "You are now logged in as $theuser"; } function loggedin($theaction) { echo <<<_END <table> <tr> <td> <form name="myform" method='post' action='$theaction'> <input type='hidden' name='logout'value='logout' /> <a href="#" onMouseDown="submitform(0);">logout</a> | </form> </td> <td> ////////////////////here is the problem point//////////////////////////////////// <form name="myform2" method='post' action='$theaction'> <input type='hidden' name='profile'value='profile' /> <a href="#" onMouseDown="submitform(2);">profile</a> | </form> /////////////////////////////////////////////////////////////////////////////////// </td> <td> <form name="myform3" method='post' action='$theaction'> <input type='hidden' name='unregister'value='unregister' /> <a href="#" onMouseDown="submitform(3);">unregister</a> </form> </td> </tr> </table> _END; } function loginform($theaction) { echo <<<_END <table border="0"> <tr> <form name="myform" method='post' action='$theaction'> <td>Username-> </td><td> <input type='text' STYLE="color: #FFFFFF; font-family: Verdana; font-size: 12px; background-color: #1BCE11;" id ='password' id='username' size='12' maxlength='16' name='user' value='user' /></td> </tr> <tr> <td>Password-> </td><td> <input type='text' STYLE="color: #FFFFFF; font-family: Verdana; font-size: 12px; background-color: #1BCE11;" id ='password' size='12' maxlength='16' name='pass' value='pass' /></td> </tr> <tr> <td colspan="2"><a href="#" onMouseDown="submitform(0);">login</a></td> </form> </tr><tr><td colspan="2"> <form name="myform2" method='post' action='$theaction'> <input type='hidden' name='register'value='register' /> <a href="#" onMouseDown="submitform(2);">register</a> </form></td></tr> <tr><td colspan="2"> <form name="myform3" method='post' action='$theaction'> <input type='hidden' name='reset'value='reset' /> <a href="#" onMouseDown="submitform(3);">reset password</a></td> </tr> </table> _END; } function regform($theaction) { echo <<<_END <table border="0"> <tr> <form name="myform" method='post' action='$theaction'> <td>Username-> </td><td> <input type='text'STYLE="color: #FFFFFF; font-family: Verdana; font-size: 12px; background-color: #1BCE11;" size='12' maxlength='16' name='username' value='username' onBlur='checkUser(this)'/></td> </tr> <tr> <td>Password-> </td><td> <input type='password' STYLE="color: #FFFFFF; font-family: Verdana; font-size: 12px; background-color: #1BCE11;" size='12' maxlength='16' name='password' value='password' onBlur='checkpass(this)'/></td> </tr> <tr> <td>Email-> </td><td> <input type='text' STYLE="color: #FFFFFF; font-family: Verdana; font-size: 12px; background-color: #1BCE11;"size='12' maxlength='30' name='email' value='email' onBlur='checkEmail(this)'/></td> </tr> <tr> <td colspan="2"><a href="#" onMouseDown="submitform(0);">register</a> </form></td></tr><tr> <td colspan="2"> <form name="myform2" method='post' action='$theaction'> <input type='hidden' name='login'value='login' /> <a href="#" onMouseDown="submitform(2);">login</a> </form> </td> </tr> </table> <span id='logtext'></span> _END; } function retlogin($theaction) { echo <<<_END <form name="myform" method='post' action='$theaction'> <input type='hidden' name='login'value='login' /> <a href="#" onMouseDown="submitform(0);">back to login</a> </form> _END; } function resetform($theaction) { echo <<<_END <table border="0"> <tr> <form name="myform" method='post' action='$theaction'> <td>Enter New Password-> </td><td> <input type='password' STYLE="color: #FFFFFF; font-family: Verdana; font-size: 12px; background-color: #1BCE11;"size='12' maxlength='16' name='password1' value='password1' onBlur='checkpass(this)'/></td> </tr> <tr> <td>Email-> </td><td> <input type='text' STYLE="color: #FFFFFF; font-family: Verdana; font-size: 12px; background-color: #1BCE11;" id ='password' size='12' maxlength='30' name='email' value='email'onBlur='checkreset(this)'/></td> </tr> <tr> <td colspan="2"><a href="#" onMouseDown="submitform(0);">reset password</a> </form></td></tr><tr> <td colspan="2"> <form name="myform2" method='post' action='$theaction'> <input type='hidden' name='login'value='login' /> <a href="#" onMouseDown="submitform(2);">back to login</a> </form> </td> </tr> </table> <span id='logtext'></span> _END; } if (isset($_POST['login'])) { loginform($theaction); } elseif (isset($_POST['logout'])) { echo "you have logged out"; [color=#FFBF40]destroySession();[/color] loginform($theaction); } //recieve reset password call elseif (isset($_POST['reset'])) { resetform($theaction); } //recieve reset password info elseif (isset($_POST['password1'])) { $theemail = $_POST['email']; $newpass = $_POST['password1']; //salt hash password for replacement $newpass = encriptpass($newpass); $query = "SELECT * FROM users WHERE email='$theemail'"; if (mysql_num_rows(queryMysql($query)) == 0) { echo "Email invalid please register<br />"; regform($theaction); } else { $message = validate_password($newpass); if ($message =="") { $regaddress = "http://www.imandanband.com.resetpass.php?newpass=".$newpass."&email=".$theemail; $to = $theemail; $subject = "Reset password at Imandan"; $body = "Hi there,\n\nYou have requested to reset your password to $newpass.\n\nPlease click the following link to validate your new password\n\n$regaddress or ignore this message if it has been sent in error"; if (mail($to, $subject, $body)) { echo("Message successfully sent! Go to your email to validate your new password"); retlogin($theaction); } else { echo("Message delivery failed...You must enter a valid email address"); } } } } elseif (isset($_POST['user'])) { $user = sanitizeString($_POST['user']); $pass = sanitizeString($_POST['pass']); $pass = encriptpass($pass); if ($user == "" || $pass == "") { $error = "Not all fields were entered<br />"; } else { $query = "SELECT user, pass FROM users WHERE user='$user' AND pass ='$pass'"; if (mysql_num_rows(queryMysql($query)) == 0) { echo "Username/Password invalid<br />"; loginform($theaction); } else { startsessions($user,$pass,$theaction); showprofile(); } } } else{ loginform($theaction); } The code that is marked is where I have the problem. It calls a javascript function to submit the form. The javascript function is as follows Code: [Select] function submitform(num) { if (num == 2) { document.myform2.submit(); return 1; } if (num == 3) { document.myform3.submit(); return 1; } if (num == 4) { document.myform4.submit(); return 1; } if (num == 5) { document.myform5.submit(); return 1; } if (num == 6) { document.myform6.submit(); return 1; } else { document.myform.submit(); return 1; } }I can log in though when I go to enter the profile the $_SESSION['user'] is gone and I am logged out. I just can't seem to track down the problem and it is frustrating the heck out of me. If anyone has any ideas PLEASE help! 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> Quote Hi guys, I have a question, I have a fairly large site wich we have resellers for, but in certain circumstances for admin purposes, we need to be able to login under the same credentials EG: I might be doing something on one machine and i need to log in on another machine to do something else but with my user name and pass At the moment when i try to to this It will log out the session already logged in when i try to log in from the other machine Is there away around this,, i suspect that when i log in from the other machine its ending the first session Any Idears Guys and Gals..... really stuck I have developed a script for dynamic display of coupons, for a client. Explanation: There is an index.php page that contains a text link. when we click on the link at the first time, a coupon name (say coupon1) should be shown in a pop up window and at the same time another page (page3.php) should be called in place of the parent window. There is a coupon list (coupon_list.txt) which contains 10 coupons. After displaying coupon1, it should be removed from the coupon_list.txt file, so that when the user clicks on the link in the second time, coupon2 should be displayed. I have developed a php function(pop.php) for this purpose. My problem is that it is working perfectly in Mozilla FireFox and Google Chrome, and also in local machine. But it is not working properly in Internet Explorer (but in local machine it is working properly in IE). That means if we click back from page3.php to index.php and again clicking in the link, it shows the same coupon (coupon1) instead of coupon2. I am not able to solve this problem. Please help me. I am attaching here with the index.php file, pop.php file, page3.php file and coupon_list.txt file. Good day guyz... I dont know why this code does not work... the connection is fine, the database is also fine it works with the localhost, when i upload it on free hosting site like 000webhost and infinityfree this is not working.. the database on free hosting site are also working also the connection is code, just only this code i cant figure it out.. else{ $sql = "INSERT INTO .$name (TrxID, ProductName, Price, ProductImage, PurchasedDate, PurchasedStatus) VALUES (?, ?, ?, ?, ?, ?)"; $stmt = mysqli_stmt_init($conn2); if(!mysqli_stmt_prepare($stmt, $sql)){ echo 'connection error'; } mysqli_stmt_bind_param($stmt, "isssss", $val, $PName, $Price, $PImage, $PDate, $PStatus); mysqli_stmt_execute($stmt); mysqli_stmt_close($stmt); header("location: ../customer/cart.html"); exit(); } }
I am very grateful for any input. I have a field in a database that contains references (pattern: authorYYYY), such as the following string:
"authorA1989; authorB1978a; authorB1984; authorC1999; authorC2000a; authorC2000b; authorC2002; authorD2009"
What I want is an output as the following in order to create a proper bibliography (therefore accessing another table and picking out the respective reference details):
authorA
1989
authorB
1978a
1984
authorC
1999
2000a
2000b
2002
authorD
2009
I somewhat fail to group the values (years) per author. I know that keys are unique, but is there a way to work around this?
Many thanks for any help!
I'm trying firstly to output hidden fields based on the values of the $_POST variable. Then after that I want to output the values again in a unordered list. I'm using the following code: while (list($key, $val) = each($_POST)) { if ($key != 'Submit') { echo '<input type="hidden" name="' . $key . '" value="' . $val . '" />'; } } echo '<ul>'; while (list($key, $val) = each($_POST)) { if ($key != 'Submit') { echo '<li><strong>' . $key . '</strong>: <span class="highlight-219ddb">' . $val . '</span></li>'; } } echo '</ul>'; However the <ul> appears to be blank? Can I only use the list() function once on a particular variable? I am having trouble with passing values with a POST to another php file. I am getting the error : undefined index : productID and undefined index: filename. I have also tried : <form method = \"POST?pdib=$processID&filename=$filename\" action = \"upload2.php\" > When I look at the array of superglobals, they are both defined. Thank you! Here is the code : drawfirsttwoforms: $sql = "SELECT ProductFilename, ProductName, ProductID, ProductDescription,ProductCost,ProductQuantity, ProductCatTitle FROM products INNER JOIN customers ON customers.CustomerID = products.CustomerID WHERE ((products.ProductKeyWord1 = ?) OR (products.ProductKeyWord2 = ?) OR (products.ProductKeyWord3 = ? )) AND (products.ProductCatTitle = ?) "; $stmt = $dbo->prepare($sql); $stmt->bindParam(1, $keyword1); $stmt->bindParam(2, $keyword1); $stmt->bindParam(3, $keyword1); $stmt->bindParam(4, $titleOfSelectedDropDown); $stmt->execute(); while ($row = $stmt->fetch()) { //these variables do have values here $productID = $row['ProductID']; $filename = $row['ProductFilename']; $string1 .= " <div class = \"A\" id = \"$mainDiv\"> <p id = \"link1\">product id :$productID</p> <p>category id :$category</p> <div class = \"A\" id = \"endz\"></div> <div class = \"A\" id = \"startz\"></div> <div class=\"container\"> <div id = \"testing\" >testing <div> <div id = \"$displayID\" > </div> <div class=\"row\" > <div class=\"col\"> <form method = \"POST\" action = \"upload2.php\" > <input type=hidden id='$productID' name= '$productID' value=\"A\"> <input type=hidden id=\"$filename\" name=$filename value=\"B\"> <button value = \"Submit\" type = \"submit\" >submit it</button> </form> <iframe id=\"upload_target\" name=\"upload_target\" style=\"width:0;height:0;border:0px solid #fff;\"></iframe> <img width=\"120\" height =\"120\" id = \"$imageID\" src=\"../php proj/uploads/$filename?<?php echo filemtime($filename)?>\"> <button onclick = \"imageRefresh( '{$filename}', '{$imageID}', '{$_SESSION["msg"]}' )\" >Display</button> </div> AFTER: if (!isset($myObj) && isset($string1)) { $myObj = new stdClass(); $myObj->htmlstuff = $string1; //Encode the data as a JSON string $jsonStr = json_encode($myObj); echo $jsonStr; }
function printHTML1(keyword){ const element = document.getElementById("dropDown1"); //const checkValue = element.options[element.selectedIndex].value; const checkText = element.options[element.selectedIndex].text; var val1 = checkText; var xmlhttp = new XMLHttpRequest(); var keyword1 = keyword; var url = "drawfirsttwoforms.php?keyword=" + keyword.value + "&" + "val1=" + val1; xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { var jsonData = JSON.parse(this.responseText); var answerHtml = jsonData.htmlstuff; document.getElementById("codehere").innerHTML = answerHtml; createAndModifyDivs(); } }; xmlhttp.open("GET", url , true); xmlhttp.send(); }
upload2.php <?php session_start(); $productID = $_POST['productID']; $filename = $_POST['filename'];
hey guys, i have my code set up to run substrings through a db to check for matches...even when there is a match it wont insert correctly Code: [Select] $result = mysql_query("select * from friends where userid=$userid"); while($row = mysql_fetch_assoc($result)) { $first_name = $row['first_name']; $last_name = $row['last_name']; $strpos_1 = strpos($friend_1, ' '); $substr_1 = substr($friend_1, 0, $strpos_1); $substr_2 = substr($friend_1, $strpos_1); if($substr_1 == $first_name && $substr_2 == $last_name) { $sql = "insert into fav_friends values('', '$userid', '$friend_1', '$friend_2', '$friend_3', '$friend_4', '$friend_5', '$friend_6')"; $query = mysql_query($sql); } } and i don't receive any errors, any thoughts? hi guys I have two functions and they work well, but now i have a problem in the last if the email is sent like www.yoursite.com/reset_password.php?userid=0&code= and not http://your.url/set_new_password.php?userid=564979&code=54c4a2767c2f485185ab72cdcf03ab59 so, the problem is that i can get the value of hash and the userid. If i do an echo "$hash" in the function code(); it shows the value like 564979&code=54c4a2767c2f485185ab72cdcf03ab59 my question is, how i can do the same in the last if? above two functions. Same occur in the last select select userid from password_reset where code=? none userid is showed, it is always zero. Code: [Select] <? function check($sql, $db, $email) { if(!empty($_POST['email'])) { $email = $_POST["email"]; if ($sql = $db->prepare("select email from users where email=?")) { $sql->bind_param('s', $email); $sql->execute(); $sql->bind_result($email); if ($sql->fetch()) { return true; } else { return false; } } } } function code($sql, $db, $hash, $pwdHasher, $userExists, $sendPass) { if (check($sql, $db, $email)) { $pwdHasher = new PasswordHash(8, FALSE); $hash = $pwdHasher->HashPassword($userExists["email"]); $sendPass=$hash; ($sql = $db->prepare('insert into password_reset (code) values (?)')); $sql->bind_param('s', $hash); $sql->execute(); $sql->fetch(); return true; } } if (code($sql, $db, $hash, $pwdHasher, $userExists, $sendPass)) { ($sql = $db->prepare("select userid from password_reset where code=?")); $sql->bind_param('s', $hash); $sql->execute(); $sql->bind_result($hash); $sql->fetch(); echo $hash; $pwrurl = "www.yoursite.com/reset_password.php?userid=" .$hash . "&code=" . $sendPass; $mailbody = "Dear user,<br><br>If this e-mail does not apply to you please ignore it. It appears that you have requested a password reset at our website www.yoursitehere.com<br> To reset your password, please click the link below. If you cannot click it, please paste it into your web browser's address bar.<br> <a href='$pwrurl'>$pwrurl</a> <br> <br> Thanks,\nThe Administration"; $mail->MsgHTML($mailbody); $mail->AddAddress($email,"Membro"); $mail->IsHTML(true); if(!$mail->Send()) { echo "Deu erro: " . $mail->ErrorInfo; } else { echo "Enviado com sucesso"; } $sql->close(); $db->close(); } ?> any help? thanks PHP 5.3.3 I am trying to redirect a user (currently logged in) to a page where they are able to edit a posted comment. To keep things secure I am using a forms hidden input value to pass the {postID} to a redirect page Code: [Select] <form name="post_edit" method="post" action="post-edit-redirect.php" > <input type="hidden" name="local" id="local" value="<?php echo $row_rsPosts['postID']; ?>" /> <input type="image" src="../imgs/managepost.png" name="submit" /> </form> On the redirect page (simplified below) I am setting the {postID} in a SESSION before redirecting to the user to the page to edit their post with the new $_SESSION val for {postID} set. Code: [Select] session_start(); $id = $_REQUEST['local']; $_SESSION['postID']=$id; header("Location: edit-post.php"); This is working fine in every browser except IE (some one please just put an end to it), where when the edit-post.php page is reached the $_SESSION['postID'] is empty. If I regenerate the session ID from the redirect page as below IE then sets the SESSION ok. Code: [Select] session_start(); session_regenerate_id(); $id = $_REQUEST['local']; $_SESSION['postID']=$id; header("Location: edit-post.php"); However there should be no need to do this and would rather not if there is no need. Any help on why IE is not setting the SESSION is appreciated, and I hope I am not covering old ground here however I am unable to find a solution anywhere. - Cheers The $_Session has a url variable. Using a Dom how do I properly do: Code: [Select] html->load($_SESSION['variable']) I was thinking about breaking down the session to retrieve the value inside but I don't know how. |