Page 1 of 1

Session Uid in A href

Posted: Sat Jun 15, 2013 2:07 pm
by TehCrayz
Hello, i havn'nt used php for a while because i gave up. But now im back to give it another try...So i fail straight away and need a solution to this.

I have been following the profile tutorial and have a profile on uid 1. But i don't know to be able to make that when i click on profile, it will take me to Profiles/profile.php?uid=""
$SESSION['uid'']???
	<li><a href=""><i class="icon-user"></i>Profile</a></li>
							<li><a href="#"><i class="icon-cog"></i>Settings</a></li>
							<li><a href="Login/logout.php"><i class="icon-remove"></i>Log out</a></li>

Re: Session Uid in A href

Posted: Sat Jun 15, 2013 4:54 pm
by Temor
$_SESSION['uid'] will always be the ID of the currently logged in user, so using that in your url will be the equivalent of a "My Profile" link. I.E it will always take you to your own profile.

There are a multitude of ways to get an id into the url, but I'm gonna need more info on what you're trying to do exactly to be able to help with that :)

Re: Session Uid in A href

Posted: Sat Jun 15, 2013 5:41 pm
by TehCrayz
Basically, on the main page, it says the users name, they click it. It's a drop down, and it says "Profile", and so when they click it, it takes them to their profile. Simple.

<a href="*insert thingy here*"><i class="icon-user"></i>Profile</a></li>

I just don't know how to add it in. :mrgreen:

Re: Session Uid in A href

Posted: Sat Jun 15, 2013 7:01 pm
by Temor
Oh, that would be really simple :P
<a href="Profiles/profile.php?uid=<?php echo $_SESSION['uid'];?>"><i class="icon-user"></i>Profile</a></li>
If you have the users ID stored in $_SESSION['ui'd], and your profile.php page is located in Profiles/, then this will work.

Re: Session Uid in A href

Posted: Sat Jun 15, 2013 7:53 pm
by TehCrayz
[EDIT] Or, if it doesn't do what's below, it just takes me to uid=1


When i change it to that, i get this in the URL:

http://localhost/Quodec/Profiles/profil ... Cbr%20/%3E

...I don't get it :/

Re: Session Uid in A href

Posted: Sat Jun 15, 2013 9:20 pm
by Temor
That's because you don't have a value in $_SESSION['uid'].

Where are you storing the logged in user ID?

Re: Session Uid in A href

Posted: Sat Jun 15, 2013 9:33 pm
by TehCrayz
What do you mean by that?
<?php

function user_exists($user){
	$user = mysql_real_escape_string($user);
	
	$total = mysql_query("SELECT COUNT(`ID`) FROM `users` WHERE `Username` = '{$user}'");
	
	return (mysql_result($total, 0) == '1') ? true : false;
}

    function valid_credentials($user, $pass){
            $user = mysql_real_escape_string(htmlentities($user));
            $pass = sha1($pass);
           
            $total = mysql_query("SELECT COUNT(`ID`) FROM `users` WHERE `Username` = '{$user}' AND `Password` = '{$pass}'") or die(mysql_error());
           
            return (mysql_result($total, 0) == '1') ? true : false;
    }


function add_user($user, $pass){
	$user = mysql_real_escape_string(htmlentities($user));
	$pass = sha1($pass);
	
	mysql_query("INSERT INTO `users` (`Username`, `Password`) VALUES ('{$user}', '{$pass}')");
}

?>
??

Re: Session Uid in A href

Posted: Sat Jun 15, 2013 9:36 pm
by Temor
Well, when you log a user in, you set some values in $_SESSION, do you not?
You need to grab the users ID from your Database and insert it into $_SESSION['uid'], otherwise you have no value in $_SESSION['uid'], and trying to grab a value from a variable with no value isn't the easiest thing to do.

Re: Session Uid in A href

Posted: Sat Jun 15, 2013 9:47 pm
by TehCrayz
Ah, so you're trying to say that right now $_SESSION['uid'] isn't getting the IDs from the database??

...


I'm confused... :?

Re: Session Uid in A href

Posted: Sat Jun 15, 2013 10:23 pm
by Temor
Yeah, you're never assigning a value to $_SESSION['uid'].

Re: Session Uid in A href

Posted: Sat Jun 15, 2013 10:26 pm
by TehCrayz
So uh, How can i fix this issue? :)

Sorry, i'm kinda a noob at PHP.

Re: Session Uid in A href

Posted: Tue Jun 18, 2013 5:00 pm
by Temor
Follow the tutorial again :P It's in there, you just missed it I guess.

It's the login part. You need to set the $_SESSION variable to "log in" the user.

Re: Session Uid in A href

Posted: Sun Jun 23, 2013 12:22 am
by TehCrayz
Ok, i'll look back on the tutorial. Thanks. :D