Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 01-18-2003, 08:38 PM   #1 (permalink)
trevor
Code Monkey
 
Join Date: Jan 2003
Location: Canada
Posts: 91
trevor is on a distinguished road
gotta be an easier way

than doing 'main.php?username=$username&password=$password'

Do I have to enter that into all of my navigation links?
trevor is offline   Reply With Quote
Old 01-18-2003, 09:14 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
that is what sessions are for .. it's really hard to read what i'm trying to tell you with all of illya's and vlads comments on your post, .. but look at the session stuff that i put in there.

sessions are what carry over variables automatically between pages. if you register "username" and "password" on every page from when the user logs in, .. you won't have to pass anything through the url.
sde is offline   Reply With Quote
Old 01-18-2003, 09:15 PM   #3 (permalink)
anon
Guest
 
Posts: n/a
after around 10 minutes of googling I found it on php.net. Do
blah=$_POST['username'];
And you will get username! Now change the form from method=get to original method=post


EDIT: This is the URL if you want it http://www.php.net/manual/en/reserved.variables.php
  Reply With Quote
Old 01-18-2003, 09:53 PM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
i thought it worked when he submited the form .. and the problem was with passing the user/pass for everything inside the protected area.

if the original submission works, then he does not need the $_POST[] .. he needs to use sessions so the username and password variable stay valid for the entire time the user is on the site.
sde is offline   Reply With Quote
Old 01-19-2003, 07:06 AM   #5 (permalink)
anon
Guest
 
Posts: n/a
Quote:
Originally posted by sde
i thought it worked when he submited the form .. and the problem was with passing the user/pass for everything inside the protected area.

if the original submission works, then he does not need the $_POST[] .. he needs to use sessions so the username and password variable stay valid for the entire time the user is on the site.
Oh, sorry, I thought he was talking about when he submitted the form and using the get method in the form, but still, atleast now he knows about $_POST But it worked when he submitted the form but he was using Get and as you said it's not secure... so now he can use this and not have to worry about that one....
  Reply With Quote
Old 01-19-2003, 07:27 AM   #6 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
from how i understood it, .. the problem was when he was trying to use the $Array[username] . i tried thie myself and could not get it to work.

in most php installations, you don' tneed to use $_POST[] ,although it could be good practice and it is more secure if you dont want people to be able to enter variables in the url.

user/pass like i said isn't that critical to be in the url for the site, as it is more of a security risk on the clients end when someone is looking over their shoulders.
sde is offline   Reply With Quote
Old 01-19-2003, 07:29 AM   #7 (permalink)
trevor
Code Monkey
 
Join Date: Jan 2003
Location: Canada
Posts: 91
trevor is on a distinguished road
I still cant qite figure it out:

here is my code for main.php
PHP Code:
<?
include("connect.php");
session_start();
session_register("username");
session_register("password");

$password=$_GET['password'];
$username=$_GET['username'];

$result=mysql_query("select * from users where username='$username' and password='$password'");

$num=mysql_num_rows($result);

if(
$num 1){
  
header("location: failed2.php");
}

?>
Now that part works fine. Just when I load the page profile.php which right now just simply lists username, email etc, i get the failed2.php.

my code for that part is:
PHP Code:
<?
include("connect.php");
session_start();

$result=mysql_query("select * from users where username='$username' and password='$password'");

$num=mysql_num_rows($result);

if(
$num 1){
  
header("location: failed2.php");
}
?>
so the username and password should be registered so I can open them from any page right? what am I forgeting?

thanks,

Trevor
trevor is offline   Reply With Quote
Old 01-19-2003, 07:30 AM   #8 (permalink)
anon
Guest
 
Posts: n/a
Quote:
Originally posted by sde
from how i understood it, .. the problem was when he was trying to use the $Array[username] . i tried thie myself and could not get it to work.
Yes that was the problem.

in most php installations, you don' tneed to use $_POST[] ,although it could be good practice and it is more secure if you dont want people to be able to enter variables in the url.

Actually that guide I gave you on installing Apache with PHP in the Linux forum, when I did it I have to use Post and it is the latest one out... (although it is Apache 1.3.27). But true it is more secure too.

user/pass like i said isn't that critical to be in the url for the site, as it is more of a security risk on the clients end when someone is looking over their shoulders.
And when you look back in the history as well, you can see lets say his sites name is lll.asd

well if you type in lll.asd you could see the old history, things like lll.asd/blah.php?asd=asd&lll=ddd
  Reply With Quote
Old 01-19-2003, 10:01 AM   #9 (permalink)
trevor
Code Monkey
 
Join Date: Jan 2003
Location: Canada
Posts: 91
trevor is on a distinguished road
is anyone here?
trevor is offline   Reply With Quote
Old 01-19-2003, 10:07 AM   #10 (permalink)
technobard
Centurion Nova Prime
 
technobard's Avatar
 
Join Date: May 2002
Location: Oak Park, IL (USA)
Posts: 285
technobard is on a distinguished road
Trevor,

Try executing session_start() first on both pages (before the include). I remember reading somewhere that it has to be first on subsequent pages to work properly. I've never tried it, personally, but it's easy enough to try.
technobard is offline   Reply With Quote
Old 01-19-2003, 10:15 AM   #11 (permalink)
trevor
Code Monkey
 
Join Date: Jan 2003
Location: Canada
Posts: 91
trevor is on a distinguished road
nope, still not working,

thanks though

do I have to do:
PHP Code:
session_register("username");
session_register("password"); 
on every page?
trevor is offline   Reply With Quote
Old 01-19-2003, 02:24 PM   #12 (permalink)
technobard
Centurion Nova Prime
 
technobard's Avatar
 
Join Date: May 2002
Location: Oak Park, IL (USA)
Posts: 285
technobard is on a distinguished road
Quote:
Originally posted by trevor
nope, still not working,

thanks though

do I have to do:
PHP Code:
session_register("username");
session_register("password"); 
on every page?
No. Just for giggles, try registering after setting the variables for the first time.

$password=$_GET['password'];
$username=$_GET['username'];
session_register("username");
session_register("password");

Also, session_register is supposed to return a boolean. I'd check that in an if to make sure it is working. If register_globals is off, session_register won't work according to info at php.net. The way your first example is written, it will still work even if session_register fails.
technobard is offline   Reply With Quote
Old 01-19-2003, 02:47 PM   #13 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
why are we using $_GET[] ???

also, i think you should have "session_start(); " at the top of each page before you register anything in the session.
sde is offline   Reply With Quote
Old 01-19-2003, 03:25 PM   #14 (permalink)
trevor
Code Monkey
 
Join Date: Jan 2003
Location: Canada
Posts: 91
trevor is on a distinguished road
well I know it is registering the variable fine because I went to /tmp/sess_o4f1fc707...... and there was my username and password

now why aren't my other sites getting these variables.

sde, can you explain the idea of not having the $_GET please?

thanks all,

Trevor
trevor is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Easier answer? Kernel_Killer HTML, XML, Javascript, AJAX 4 02-26-2003 12:13 PM


All times are GMT -8. The time now is 11:41 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting