How do link-buttons in PHP?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
my_food
Forum Newbie
Posts: 2
Joined: Sun Jul 01, 2007 5:16 am

How do link-buttons in PHP?

Post 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 :D
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

php login page

Post by yacahuma »

feyd | Please use

Code: Select all

,

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

,

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]
Last edited by yacahuma on Sun Jul 01, 2007 9:49 am, edited 1 time in total.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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:

Code: Select all

<form method="get" ...
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Why not use PHP_SELF?

Post 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
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

my_food
Forum Newbie
Posts: 2
Joined: Sun Jul 01, 2007 5:16 am

Post 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]
Post Reply