Jump to content

Search the Community

Showing results for tags 'unset'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 5 results

  1. Hello, I am trying to unset from array using array_search, it's working, except the first array value "a+" is not working $bloodType_list = ['a+','a-','b+','b-','o+','o-','ab+','ab-']; if($key = array_search('a+',$bloodType_list)){ unset($bloodType_list[$key]); } foreach($bloodType_list as $bloodType_lists){ echo $bloodType_lists."<br>"; }
  2. I am having a very strange issue on one server. I have the same code in a development server running fine, but in my prod server it is failing. Here is the main issue: I have a user authentication routine that accepts UserID and Password from a form and validates it against a MySQL database. So to start, UserId and Password are entered via POST variables as is standard: $UserId=@$_POST['UserId']; $Password=@$_POST['Password']; The Password is encrypted using a standard crypt method such as: $encrypt = crypt($Password,'6!68$7435!'); And this is stored in a MySQL database. This part is working fine, that is, the password is encrypted in value and stored in the MySQL database as 'epasswd'. On login, I am using session, so a standard session_start() and eventual session_destroy() on logout are used. The reason I mention this is because I suspect my issue is session related. So normally this works well. User logs in and I check credentials as follows in one part of my auth routine: elseif(UserAuth($UserId,$Password)){ $UserLogin=$UserId; session_start(); $_SESSION['UserLogin'] = $UserLogin; sql_insertActivity(); header("Location: home.php"); And the auth routine is as follows: <? function UserAuth($UserId,$Password){ global $conn; $Stmt="select epasswd from Users where UserId='$UserId' and Approved='1' or Approved='-1' or Approved='-2'"; $Result = mysql_query($Stmt, $conn) or die(mysql_error()); $Result=mysql_fetch_row($Result); $epasswd=$Result[0]; $retval=($epasswd==crypt($Password,$epasswd)); return($retval); } ?> So I am checking for a valid UserID and Password on form input, and I have a few other variables set for approved status. The retval checks the password they enter versus the encrypted value for a match. This usually works well. Then login occurs and session started, etc. Here is the issue. I added a quick admin routine a little while ago which helps reset a user's password to a temporary value. Once this value is set, along with a setting of approved=-1 in my database, then the user is re-directed to a Change Password screen to update his or her password. *Note: I changed the value to 'Charlie' for this discussion purpose. Here is that quick admin routine I run when I need to change a User to a temp setting: // ----- Establish database connection ----- require "../inc_php/inc_mysql_prod.php"; // $UserId=@$_GET['UserId']; $Password='Charlie'; $encrypt = crypt($Password,'6!68$7435!'); $sql = "UPDATE Users set epasswd='$encrypt', approved='-1' where UserId='$UserId'"; mysql_query($sql, $conn) or die(mysql_error()); So this does work as I validate the UserID is updated in the MySQL database along with an encrypted value for 'Charlie'. However, this is where things breakdown going forward. When the user logs in with the temp credentials, and enters in the Change password routine, their new password is saved in the table. However, when logging back in with the new credentials, the new password is not valid. And what's odd is that 'Charlie', the temp password, works for them on login and nothing else, no matter how many times they change the password in the form. So seems a case of session management out of control? What is the issue? I am defining session on all Php pages used, and have a logout to destroy session, etc. The temp password routine is something I run as an admin in the system and it doesn't have a session start statement. And I am not defining any global vars for Password. I lloked into session management and tried some UNSET paths and such, but may not be doing this correctly. Also I did a complete stop apache, remove all php sess_ files, restart and to no avail. I tried the clear my client side cookies deal in the browser, and still the same problem. What is odd is that this same set of code works fine on my other server, but breaks down on the mirrored server. They are essentially twins in all setup. Some minor differences between the two servers regarding PHP setup that might(?) make a difference. DEV server: SERVER_SOFTWARE Apache/2.2.3 (Red Hat) PROD server: (server showing the issues): SERVER_SOFTWARE Apache/2.2.3 (CentOS) HTTP_COOKIE PHPSESSID=3gocr0hhelvsjjlt63pp4qlnp3 _REQUEST["PHPSESSID"] 3gocr0hhelvsjjlt63pp4qlnp3 _COOKIE["PHPSESSID"] 3gocr0hhelvsjjlt63pp4qlnp3 _SERVER["HTTP_COOKIE"] PHPSESSID=3gocr0hhelvsjjlt63pp4qlnp3 Thanks appreciate the help! -Eddie
  3. Just a thought... Is it possible to unset a global variable/array from within a function? So basically I want to pass an array to a function to convert to a string then destroy the original array. I'd like to keep it all contained within the function to reduce any additional clear-up scripting required. Here's my example code below: $GLOBALARRAY = array("keyname1" => "value1", "keyname2" => "value2"); $newstring = convertArrayToString($GLOBALARRAY, true); function convertArrayToString($array, $unset = false) { $string = ''; //Loop for each array value foreach ($array as $key => $value) { $string = $string . $key . '=' . $value ';'; } if ($unset === true) { unset($GLOBALARRAY_WHICH_WAS_PASSED); } return $string; } My guess is that I need to either get the name of the passed array or pass by reference? Thanks for your thoughts. Matt
  4. Hi, I'm trying to make a form that validates any errors on a page then submits the data via a $_SESSION to the next page for further review. I'm at the point where I'm trying to make it so that if there are any errors on the first page that form information isn't lost when the page reloads. So far this is fine for my text fields, drop down boxes etc, however I'm having issues with my check boxes. If they have been checked and submitted and the admin wants to uncheck it, when the page reloads it still comes back as being checked which means my code for unsetting the variable isnt working for whatever reason. Heres my code. <?php require_once("includes/session.php"); ?> <?php if(isset($_POST['submit'])) { $errors = array(); $required_fields = array( 'brand_id', 'dev_model', 'freq_2g_gsm850', ); //If any of the required fields are not set or empty, put them into an errors array and clear the $_SESSION variable foreach($required_fields as $fieldname) { if (!isset($_POST[$fieldname]) || empty($_POST[$fieldname])) { $errors[] = $fieldname; unset($_SESSION['$fieldname']); } } //If there are no errors go ahead and process the data if (empty($errors)) { //Process each variable and add it to the Session for the next page to process *** Might be able to remove if(isset) foreach($required_fields as $fieldname) { if (isset($_POST[$fieldname])) { $_SESSION[$fieldname] = mysql_prep($_POST[$fieldname]); } } //Redirect to posttest.php to complete the device registration form redirect_to('posttest.php'); } else { foreach($required_fields as $fieldname) { if (isset($_POST[$fieldname])) { $_SESSION[$fieldname] = mysql_prep($_POST[$fieldname]); } } //unset($_SESSION['$freq_2g_gsm850']); //Errors occured $message = "There were " . count($errors) . " errors in the form"; } } ?> <h3>2G GSM</h3> <?php if(!isset($_SESSION['freq_2g_gsm850']) || empty($_SESSION['freq_2g_gsm850'])) { echo "<label><input type=\"checkbox\" name=\"freq_2g_gsm850\" value=\"850\" id=\"freq_2g_gsm850\">850</label>"; } else { echo "<label><input type=\"checkbox\" name=\"freq_2g_gsm850\" value=\"850\" id=\"freq_2g_gsm850\" checked>850</label>"; } ?> Thanks in advance for your help
  5. Inside a foreach/as loop, in a nested if loop I have this little nugget: else { $currentRec = current($r); echo "Rec to Kill: $currentRec"; //Testing purposes only - Killing the right thing? unset($r[$currentRec]); } It's not working as I'd expect it to (which would be to kill the current record of my 2d array). Of course, I'm a PHP novice, (more used to working with dbase/foxpro) so there's something in transitioning to PHP's logic that I'm most definitely missing. A nudge in the right direction would be lovely. Thanks!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.