Register/login
Register/login
Hi guy's ,, i follow jacek tut and i finish the register and login and thank you very much jacek for every thing you do to teach us god bless you .
i just now need help in somthing maybe easy for you guy's but its still hard to me
i want add Guest login function and store it in database any idea about this.
i just now need help in somthing maybe easy for you guy's but its still hard to me
i want add Guest login function and store it in database any idea about this.
Re: Register/login
The description of what you want done is pretty vague, but should be easy to implement.
What do you mean by guest login exactly?
You could do a check at the top of the page to see if the user is logged in, if not, set as guest.
Not sure what exactly you want to store in the database. Feel free to elaborate a bit on what you mean
What do you mean by guest login exactly?
You could do a check at the top of the page to see if the user is logged in, if not, set as guest.
if(isset($_SESSION['user_name'])){ user is logged in }else{ $_SESSION['user_name'] = 'Guest'; }This would make the username of any guest on your site " Guest ".
Not sure what exactly you want to store in the database. Feel free to elaborate a bit on what you mean
Re: Register/login
Thanks Bro for replay , let me explain more lets say i have visitor and he dont have registered account i want make him able to login as guest without registration and store his name session in database.
Re: Register/login
So you want to have the login form register a new user if one is not found in the table ?
Well you could create a function to check to see if the username exists (might already exists actually) and then do
Well you could create a function to check to see if the username exists (might already exists actually) and then do
if (user_name_taken($_POST['username'])){ // do normal login }else{ // do registration. }It's probably not the best idea to do this though since you would generally want a bit more information form the user than just their name. Also if a user makes a typo while logging in it will create a whole new account for their misspelled username.
Re: Register/login
guys iam lost i cant make a secure guest login i would if we have tut about it
Re: Register/login
i just creat form for guest login and form for userlogin basicly user login needs name in data base to login what iam trying to do is allow the guest login form to also login but i have problem with welcome session like if i echo the session of registered user like this $user_name['username']; i get Undefined variable for the guest and work normal for the registered user , its complicated ,, what iam trying to do is echo 2 sessions in the same time like echo $userdata else echo $_Post['form element name'] but i donno how also i want add the $_post['element'] in check login data this is my check login data functionjacek wrote:Secret guest login o.O Explain the problem ?
function logged_in(){ return (isset($_SESSION['user_id'])) ? true : false; }
Re: Register/login
Ok what are you wanting "guest" to have and be able to do and how long will the session last (till they close their browser, a week?
For me I would want guest to have a user_id and user_name. (So lets do a simple flow chart ; )
login page
login link and guest login link
(you already have login link)
guest login link I would have it as its own table "guests", with cols guest_id (auto increment). User_name would be just the letters(string) "guest" + the guest_id. Which you assign to $_SESSION, or if you want it to stick around longer than them closing their browser (i.e. keep their shopping cart for a week) then set cookie to username = guest_id and how long in seconds.
So guest login link onclick adds a row to the guest table and sets SESSION username to "guest" + 'guest_id' and sets cookie if wanted.
Is this a bit what you are wanting?
For me I would want guest to have a user_id and user_name. (So lets do a simple flow chart ; )
login page
login link and guest login link
(you already have login link)
guest login link I would have it as its own table "guests", with cols guest_id (auto increment). User_name would be just the letters(string) "guest" + the guest_id. Which you assign to $_SESSION, or if you want it to stick around longer than them closing their browser (i.e. keep their shopping cart for a week) then set cookie to username = guest_id and how long in seconds.
So guest login link onclick adds a row to the guest table and sets SESSION username to "guest" + 'guest_id' and sets cookie if wanted.
Is this a bit what you are wanting?
Re: Register/login
thanks for replay that not what i need i just need login form for guest and in the same time allow them to login .
Last edited by jacek on Mon Aug 27, 2012 11:21 pm, edited 1 time in total.
Reason: Removed massive quote.
Reason: Removed massive quote.
Re: Register/login
i make function to allow login for guest from login form but i have an error now the welcome session for guest i get Undefined variable any idea about how to defined it in welcome session this is the welcome session that i use it
welcome
welcome
<?php echo $user_data['username']; ?>
Last edited by drama22 on Sun Aug 26, 2012 9:05 am, edited 2 times in total.
Re: Register/login
i successfully create the login for guest but i had one problem now the welcome session i get Undefined variable: user_data
how can i define the variable in function any idea ? or can i echo username data and if its not found i do else echo statement ?
i do somthing lik this but i stell get undefiend user_data
how can i define the variable in function any idea ? or can i echo username data and if its not found i do else echo statement ?
i do somthing lik this but i stell get undefiend user_data
Last edited by drama22 on Fri Aug 31, 2012 7:58 am, edited 1 time in total.
Re: Register/login
if no one have any idea about this please Delet my thread admin
Re: Register/login
Not how it worksdrama22 wrote:if no one have any idea about this please Delet my thread admin
The best thing to do would be to define a default $user_info variable. If I remember correctly you should have something that looks a bit like this
if (isset($_SESSION['username'])){ $user_info = fetch_user_info($_SESSION['username']); }so you could define the default which would be used for guests like this
if (isset($_SESSION['username'])){ $user_info = fetch_user_info($_SESSION['username']); }else{ $user_info = array( 'id' => 0, 'name' => 'Guest', ); }obviously filling in any other keys that you need.
Re: Register/login
Solved down !
Last edited by drama22 on Sat Sep 01, 2012 7:58 pm, edited 1 time in total.