Session Uid in A href
Session Uid in A href
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'']???
[syntax=php] <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>[/syntax]
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'']???
[syntax=php] <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>[/syntax]
Re: Session Uid in A href
$_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![Smile :)](./images/smilies/icon_e_smile.gif)
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
![Smile :)](./images/smilies/icon_e_smile.gif)
Re: Session Uid in A href
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.![Mr. Green :mrgreen:](./images/smilies/icon_mrgreen.gif)
<a href="*insert thingy here*"><i class="icon-user"></i>Profile</a></li>
I just don't know how to add it in.
![Mr. Green :mrgreen:](./images/smilies/icon_mrgreen.gif)
Re: Session Uid in A href
Oh, that would be really simple ![Razz :P](./images/smilies/icon_razz.gif)
[syntax=php]
<a href="Profiles/profile.php?uid=<?php echo $_SESSION['uid'];?>"><i class="icon-user"></i>Profile</a></li>
[/syntax]
If you have the users ID stored in $_SESSION['ui'd], and your profile.php page is located in Profiles/, then this will work.
![Razz :P](./images/smilies/icon_razz.gif)
[syntax=php]
<a href="Profiles/profile.php?uid=<?php echo $_SESSION['uid'];?>"><i class="icon-user"></i>Profile</a></li>
[/syntax]
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
[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 ... 20%3Cb%3EC:\xampp\htdocs\Quodec\pictures.php%3C/b%3E%20on%20line%20%3Cb%3E417%3C/b%3E%3Cbr%20/%3E
...I don't get it :/
When i change it to that, i get this in the URL:
http://localhost/Quodec/Profiles/profil ... 20%3Cb%3EC:\xampp\htdocs\Quodec\pictures.php%3C/b%3E%20on%20line%20%3Cb%3E417%3C/b%3E%3Cbr%20/%3E
...I don't get it :/
Re: Session Uid in A href
That's because you don't have a value in $_SESSION['uid'].
Where are you storing the logged in user ID?
Where are you storing the logged in user ID?
Re: Session Uid in A href
What do you mean by that?
[syntax=php]<?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}')");
}
?>[/syntax]
??
[syntax=php]<?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}')");
}
?>[/syntax]
??
Re: Session Uid in A href
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.
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
Ah, so you're trying to say that right now $_SESSION['uid'] isn't getting the IDs from the database??
...
I'm confused...![Confused :?](./images/smilies/icon_e_confused.gif)
...
I'm confused...
![Confused :?](./images/smilies/icon_e_confused.gif)
Re: Session Uid in A href
Yeah, you're never assigning a value to $_SESSION['uid'].
Re: Session Uid in A href
So uh, How can i fix this issue?
Sorry, i'm kinda a noob at PHP.
![Smile :)](./images/smilies/icon_e_smile.gif)
Sorry, i'm kinda a noob at PHP.
Re: Session Uid in A href
Follow the tutorial again
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.
![Razz :P](./images/smilies/icon_razz.gif)
It's the login part. You need to set the $_SESSION variable to "log in" the user.
Re: Session Uid in A href
Ok, i'll look back on the tutorial. Thanks. ![Very Happy :D](./images/smilies/icon_e_biggrin.gif)
![Very Happy :D](./images/smilies/icon_e_biggrin.gif)