Register/login

Post here is you are having problems with any of the tutorials.
Post Reply
drama22
Posts: 22
Joined: Wed May 30, 2012 9:40 am

Register/login

Post by drama22 »

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.
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: Register/login

Post by Temor »

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.
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 :)
drama22
Posts: 22
Joined: Wed May 30, 2012 9:40 am

Re: Register/login

Post by drama22 »

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.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Register/login

Post by jacek »

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
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.
Image
drama22
Posts: 22
Joined: Wed May 30, 2012 9:40 am

Re: Register/login

Post by drama22 »

guys iam lost :( i cant make a secure guest login i would if we have tut about it
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Register/login

Post by jacek »

Secret guest login o.O Explain the problem ?
Image
drama22
Posts: 22
Joined: Wed May 30, 2012 9:40 am

Re: Register/login

Post by drama22 »

jacek wrote:Secret guest login o.O Explain the problem ?
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 :mrgreen: ,, 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 function
function logged_in(){
return (isset($_SESSION['user_id'])) ? true : false;
}
keystone
Posts: 10
Joined: Mon Aug 20, 2012 10:00 pm

Re: Register/login

Post by keystone »

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?
drama22
Posts: 22
Joined: Wed May 30, 2012 9:40 am

Re: Register/login

Post by drama22 »

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.
drama22
Posts: 22
Joined: Wed May 30, 2012 9:40 am

Re: Register/login

Post by drama22 »

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
<?php echo $user_data['username']; ?>
Last edited by drama22 on Sun Aug 26, 2012 9:05 am, edited 2 times in total.
drama22
Posts: 22
Joined: Wed May 30, 2012 9:40 am

Re: Register/login

Post by drama22 »

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
Last edited by drama22 on Fri Aug 31, 2012 7:58 am, edited 1 time in total.
drama22
Posts: 22
Joined: Wed May 30, 2012 9:40 am

Re: Register/login

Post by drama22 »

if no one have any idea about this please Delet my thread admin :D
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Register/login

Post by jacek »

drama22 wrote:if no one have any idea about this please Delet my thread admin :D
Not how it works :P

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.
Image
drama22
Posts: 22
Joined: Wed May 30, 2012 9:40 am

Re: Register/login

Post by drama22 »

Solved down !
Last edited by drama22 on Sat Sep 01, 2012 7:58 pm, edited 1 time in total.
drama22
Posts: 22
Joined: Wed May 30, 2012 9:40 am

Re: Register/login

Post by drama22 »

Solved
Post Reply