Page 1 of 1
How do link-buttons in PHP?
Posted: Sun Jul 01, 2007 6:46 am
by my_food
I have two textboxes for login and pass... and in books there is else a button. After clicking button i get $login and $pass by GET or POST. So ze problem is:
I want to make a link, which would play submit-button function.
Coz, i code:
<a href="index.php?login=<?=$_GET['login']."&pass=."$_GET['pass'] ?>">check</a>
and i get in browser empty login and pass
index.php?login=&pass=
Am I in right way to making link-submit-button?
Please, could you help me? I found no books what help me

-----------------------------
P.S. Sorry for my English, if there is something wrong or un-understandable

php login page
Posted: Sun Jul 01, 2007 7:32 am
by yacahuma
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
If you are trying to make a login page that is not the correct way. Take a look.
Code: Select all
<?php
$msg='';
if (isset($_POST['submitBtn'])){
$user = $_POST['user'];
$pwd = $_POST['pwd'];
//database call to check user
//list($itworked,$userinfo) = $mgr->checkUser($user,$pwd); --this you have to do yourself
if ($itworked)
{
$_SESSION['userinfo'] = $userinfo;
header('Location: http://www.example.com/anypage.php');
exit;
}
else
{
$msg ='Invalid User';
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Page title</title>
</head>
<body>
<?
echo $msg;
?>
<form name="login" action="<?=$_SERVER['PHP_SELF']?>" method="post">
<input type="text" name="user" value="" />
<input type="password" name="pwd" value="" />
<input type="submit" name="submitBtn" id="submitBtn" />
</form>
</body>
</html>
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Sun Jul 01, 2007 8:10 am
by superdezign
yacahuma, we have multiple posts here about not using PHP_SELF as the action. Look a few up.
my_food, you are attempting to access variables that don't exist. $_GET variables only exist if they are already defined in the URL. A link to submit would be like this:
Code: Select all
<a href="#" onclick="document.form.submit">Submit</a>
Or something of that nature.
If you want to send variables through the GET method (not recommended for logins), use this:
Why not use PHP_SELF?
Posted: Sun Jul 01, 2007 9:55 am
by yacahuma
superdezign,
Could you be so kind and mention why not?
Every now and then a read php security stuff and never heard anything bad about it.
I did a search on the forum but was not successful finding the information you mention.
Thank you
Posted: Sun Jul 01, 2007 10:02 am
by superdezign
Posted: Tue Jul 03, 2007 12:04 pm
by my_food
2yacahuma:
Thanx for recommending "Posting Code in the Forums"! I read it. At next time I'll try to write right

Also thanx for helping
2superdezign:
Your:
Code: Select all
<a href="#" onclick="document.form.submit">Submit</a>
is that what i need!!! thanx...

[/quote]