Jump to content

Login redirect seriously acting up


lanredoyes
Go to solution Solved by denno020,

Recommended Posts

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.

Link to comment
Share on other sites

  • Solution

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?

  • Like 1
Link to comment
Share on other sites

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 by Jacques1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.