Jump to content

Php: A Function Inside A Class Repeating Values Twice


Recommended Posts

Hi, again got a problem.

 

As the title describing, everything in a function inside a class repeating every value twice. For example, when using 'echo', transferring a value to another function/class. I'm attaching a screenshot of the page. On that page you will see, "HELLO4HELLO4", The two four had transferred from the class-1(where the problem occurs) and printed on the class-2. Class-1 transferring 4 two times to class-2. And also I'm posting the function:

function setSession($uid){
		session_start();
		if(!empty($uid)){
			$this->uid_md5 = $uid;
			if($q=db_query("SELECT uid,uid_md5,username,login_cookie,uid_md5,status,suspended,suspension_reason FROM users WHERE uid_md5='".$this->uid_md5."'",$this->db)){
				if(db_num_rows($q)==1){
					$r=db_fetch_array($q);
					$this->uid_md5 = sha1($r['uid_md5']);
					$this->sessid = sha1($r['uid']).'-'.sha1($this->ip);
					$this->login_cookie = sha1($r['username']).'-'.sha1($this->ip).'-'.sha1($this->device);
					if($this->login_cookie == $r['login_cookie']){
						if($update=db_query("UPDATE users SET uid_md5='".$this->uid_md5."', autologin='0', login_ip='".$this->ip."',login_device='".$this->device."',login_platform='".$this->platform."',login_browser='".$this->browser."',login_ua='".$this->ua."',login_country='".$this->country."',login_state='".$this->state."',login_location='".$this->city."',login_date='".$this->date."',login_time='".$this->time."',login_timestamp='".$this->timestamp."',login_cookie='".$this->login_cookie."' WHERE uid_md5='".$this->uid_md5."'", $this->db)){
							setcookie('uid','',0);
							$_SESSION['expires'] = time();
							$_SESSION['uid'] = $uid;
							$_SESSION['sessid'] = $this->sessid;
							if($r['status']==0){
								$this->nmi->redirectByRefId(3,'do=confirm');
							} elseif($r['status']==1){
								$this->nmi->redirectByRefId(2,2);
							} elseif($r['status']==2){
								echo "HELLO";
								$this->nmi->redirectByRefId(4);
							} elseif($r['status']==3){
								$this->nmi->redirectByRefId(3,'do=renew');
							} elseif($r['status']==4){
								$this->nmi->redirectByRefId(3,'do=status');
							} elseif($r['status']==5){
								$this->nmi->redirectByRefId(3,'do=status');
							}
						} else {
							echo '<div class="error">Unable to update database</div>';
						}
					} else {
						setcookie('uid','');
						unset($_SESSION['expires']);
						unset($_SESSION['uid']);
						unset($_SESSION['sessid']);
						echo '<div class="error">Your login device was changed. Please login again.</div>';
					}
				} else {
					echo '<div class="error">Your login details were changed. Please login again: '.$this->uid_md5.'/'.$r['uid_md5'].'</div>';
				}
			} else {
				echo '<div class="error">Unable to query database</div>';
			}
		} else {
			echo '<div class="error">UID cannot be left empty</div>';
		}
	}
Take a look at the screenshot:

Link to comment
Share on other sites

  • 2 weeks later...

My guess is that somewhere in the function $this->nmi->redirectByRefId(4); (line 167) is an echo statement that outputs the parameter given (4). What I can't quite figure out is what would cause the statements given in elseif($r['status']==2) (lines 165-168) to execute twice. Maybe the entire function setSession() is called twice somewhere else in your code? Possibly if called from within a loop?

Link to comment
Share on other sites

Yeah, you are right.. The problem was caused by a second call to the setSession(). Now it solved. I've removed the second call. And thanks for your help.

Link to comment
Share on other sites

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.   Paste as plain text instead

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