lanredoyes Posted April 2, 2017 Share Posted April 2, 2017 if(setcookie('logged_in', hash('sha512', $userID.$email.$pass_encrypted.'PectGtma'), time()+31556926, '/', get_app_info('cookie_domain'))) { if($used_paid=='Y') { if($tied_to=='') { if($redirect_to=='') header("Location: ".get_app_info('path')); else header("Location: ".get_app_info('path').'/'.$redirect_to); } else { if($redirect_to=='') header("Location: ".get_app_info('path')."/dashboard?i=".$_SESSION['restricted_to_app']); else header("Location: ".get_app_info('path')."/".$redirect_to); } } else { header("Location: ".get_app_info('path')."/complete-registration?i=".$_SESSION['restricted_to_app']); } } } else { //user doesn't exist and exit if($redirect_to=='') header("Location: ".get_app_info('path')."/login?e=2"); else header("Location: ".get_app_info('path')."/login?e=2&redirect=$redirect_to"); exit; } Hello and thanks to everyone on this awesome platform. I am working on a web app that requires payment after registration and not during registration. The code block below is meant to create a login session and then check if the user as paid or not the do the necessary redirect. The code is working in a funny way presently and i can't seem to know what the problem is. The $user_paid is a char(1) database type returning either Y/N and when the response is 'N', it executes the else statement and also when the response is 'Y', it also execute the else statement. kindly help please. Quote Link to comment https://forums.phpfreaks.com/topic/303599-login-redirect-seriously-acting-up/ Share on other sites More sharing options...
Solution denno020 Posted April 2, 2017 Solution Share Posted April 2, 2017 Are you talking about the if statement if($used_paid=='Y')? If so, have you checked that $used_paid isn't a lowercase y? Because y doesn't equal Y. Also, is $used_paid a typo? Is it supposed to be $user_paid? 1 Quote Link to comment https://forums.phpfreaks.com/topic/303599-login-redirect-seriously-acting-up/#findComment-1544936 Share on other sites More sharing options...
Jacques1 Posted April 2, 2017 Share Posted April 2, 2017 (edited) Several things: (Ab)using a CHAR(1) field with values like “Y”/“N” to represent booleans sucks, because this is unreliable and cumbersome. Chances are you'll quickly end up with many different variations due to bugs or human error (“y”/“N”, “Y”/“n”, “y”/“n”, “0”/“1”, “t”/“f”, ...). When you need booleans, use the BOOLEAN type. That's what it's for. After four years of programming, it's time to learn basic debugging steps. PHP scripts aren't magical; they behave logically based on simple rules, so whenever you ask yourself “WTF is happening?”, try to find out. Use var_dump() to inspect the contents of relevant variables (like $used_paid, or whatever you've called that). Actual debuggers like Xdebug can speed up this process enormously, because instead of manipulating the code, you can set breakpoints to halt program execution and analyze the current state of the program. Also make sure that your error reporting is turned all the way up. When programs behave “weirdly”, there are sometimes hard errors behind it, and you definitely want to see those errors. WTF is up with this “logged_in” cookie? Edited April 2, 2017 by Jacques1 Quote Link to comment https://forums.phpfreaks.com/topic/303599-login-redirect-seriously-acting-up/#findComment-1544937 Share on other sites More sharing options...
lanredoyes Posted April 2, 2017 Author Share Posted April 2, 2017 Thanks for the responses. @denno020 I can't believe I was that stupid mistyping that. @Jacques thanks for the insight. Will definitely look into your suggestions. Quote Link to comment https://forums.phpfreaks.com/topic/303599-login-redirect-seriously-acting-up/#findComment-1544944 Share on other sites More sharing options...
Jacques1 Posted April 2, 2017 Share Posted April 2, 2017 And another suggestion: Replace your current editor with a proper IDE that tells you when you're using nonexistent variables. Quote Link to comment https://forums.phpfreaks.com/topic/303599-login-redirect-seriously-acting-up/#findComment-1544945 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.