PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 6th, 2002, 07:15 PM
Attila Attila is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 67 Attila User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
PHP and Forms

OK how do I do the PHP self thing?

I have seen many people do the PHP self thing on a form but can't seem to find one when I need it.


<form action="login.php" method="post" name="Logon" >

Please help.
__________________
Thanks,
Attila
http://www.glorynaspiration.com
http://www.abitofthings.com

Reply With Quote
  #2  
Old December 6th, 2002, 07:41 PM
JXL JXL is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Netherlands
Posts: 13 JXL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
u mean this?

<form action="<?=$PHP_SELF?>" method="post" name="Logon" >

Reply With Quote
  #3  
Old December 6th, 2002, 07:52 PM
Attila Attila is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 67 Attila User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Yes that fixes part now I need the other part.

here is what I got.
PHP Code:
<br>
<
form action="<?=$PHP_SELF?>" method="post" name="Logon" id="Logon" >
<
table width="0%" class="newstable1" border="0" align="right" cellpadding="0" cellspacing="0">
  <
tr>
      <
td><font size="-1">Logon:</font></td>
    <
td><input name="name" type="text" id="name" size="15"></td>
  </
tr>
  <
tr>
      <
td><font size="-1">Password:&nbsp;&nbsp;</font></td>
    <
td><input name="password" type="password" id="password" size="15"></td>
  </
tr>
  <
tr>

I want it to call the function login.  If I attempt to login I still see the form.

      <
td align="center"><font color="#FFFFFF"
        <
input type="submit" name="Submit" value="Submit">
        </
font></td>
      <
td align="center"><font color="#FFFFFF">
<
input type="reset" name="Submit2" value="Reset">
        </
font></td>
  </
tr>
</
table>
</
form>
<
br><br><br><br><br><br>



<?
    
dbconnect ();
    
$result mysql_query("SELECT id, name, link, status FROM right_links ORDER BY id ASC");
    
$num_rows mysql_num_rows($result);
?>
<table align="right" width="200" border="0" cellspacing="0" cellpadding="1">
  <tr>
        <td align="right"><font color="#003366" size="-1"><strong>Whats Playing</strong></font></td>
    </tr><? while ($row mysql_fetch_object($result))
          {
            
$ID $row->id;
            
$name $row->name;
            
$link $row->link;
            
$status $row->status;
          
            if (
$status == 0
                  {
                echo 
"<tr>";
                echo 
"<td align=right><font size=-1><a href=$link target=_blank>$name</a></font></td>";
                echo 
"</tr>";
                }
        }
        
    
?>
</table>
<?
function login()
{
$name1 mysql_query("SELECT memberid, name, online FROM member WHERE name = '$name' AND password = PASSWORD('$password')");
$num_rows mysql_num_rows($name1);

if (
$num_rows <= 0)
    {
        echo 
"<p align= center>You either entered your user name or password wrong.</p>";
        exit;
    }
if(
mysql_num_rows($name1) != 0
    {
        
$verified_user $memberid;
        
$wired = (time()) + 1000;  //I want to add 10 minutes
        
session_register($wired);
        echo 
$wired;   
        
$showonline = ("UPDATE member SET online = '$wired' WHERE name = '$name'");
        
$result mysql_query($showonline) or die ("Query failed");
        echo (
"inside if");
    }
echo 
"<p align= center>Welcome back <font color=#0000FF>";
echo 
$name;
echo 
"</font></p>";
}
?> 

Reply With Quote
  #4  
Old December 7th, 2002, 03:21 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
You're missing an IF statement to check to see if the form has been completed.

What you should do is insert a hidden value in the page that displays the form, and in your IF statement, check to see if the hidden value has been passed, if it hasn't, you display the html form. If it has, then display the welcome page.
__________________
____________________________________________
Developer Shed Weekly Writer | DevArticles Forum Moderator
Build Your Own KlipFolio Klip With PHP
FrankManno.com - Under Construction
Design Interactive Group - Under Construction

Reply With Quote
  #5  
Old December 7th, 2002, 05:34 PM
Attila Attila is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 67 Attila User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Cookies and headers.

OK I got the form set up correctly I beleive. Now I am having problem with cookies and headers.

Here is the script.
PHP Code:
<?
if ($_COOKIE['$membername']  && $_COOKIE['$password'] && $_COOKIE['$allow'] )
        {
        echo 
$_COOKIE['$membername'];
        echo 
"<br>";
        echo 
$_COOKIE['$password'];
        echo 
"<br>";
        echo 
$_COOKIE['$allow'];
        require 
"conf_global.php";
        
$link mysql_connect($conf['sql_host'], $conf['sql_user'], $conf['sql_pass']);
        
mysql_select_db($conf['sql_database'], $link) or die ("Connection Failed.");

            
$name2 mysql_query("SELECT memberid, membername, password, online, session, allow FROM member WHERE membername = '$membername' AND password = PASSWORD('$password')");
            
$num_rows2 mysql_num_rows($name2);

            if (
$num_rows2 <= 0)
                {
                    die(
'This is crap!');
                }
            if(
mysql_num_rows($name2) != 0
                {
                
$wired = (time()) + 600;  //I want to add 10 minutes
                
$showonline = ("UPDATE member SET online = '$wired', session = '$wired' WHERE membername = '$membername'");
                
$result mysql_query($showonline) or die ("Query failed");
                
$logged_in 1;
                }
        }    

if (
$Submit

    require 
"conf_global.php";
    
$link mysql_connect($conf['sql_host'], $conf['sql_user'], $conf['sql_pass']);
    
mysql_select_db($conf['sql_database'], $link) or die ("Connection Failed.");

    
$name1 mysql_query("SELECT memberid, membername, password, online, session, allow FROM member WHERE membername = '$membername' AND password = PASSWORD('$password')");
    
$num_rows mysql_num_rows($name1);
    if (
$num_rows <= 0)
        {
        die(
"That username doesn\'t exist in our database or you entered the password wrong.");
        }
    if(
mysql_num_rows($name1) != 0
        {
        
            
$wired = (time()) + 600;  //I want to add 10 minutes
            
$showonline = ("UPDATE member SET online = '$wired', session = '$wired' WHERE membername = '$membername'");
            
$result mysql_query($showonline) or die ("Query failed");
            
//$_SESSION['membername'] = $_POST['membername'];
            //$_SESSION['password'] = $_POST['password'];
            
            
$logged_in 1;
//            echo "<meta http-equiv=refresh content=0; url='$conf[board_url]'>";
            
setcookie('membername'$_POST['membername'], (time()+2592000), '/'''); 
            
setcookie('password'$_POST['password'], (time()+2592000), '/'''); 
            
setcookie('allow'$_POST['allow'], (time()+2592000), '/''');
            
//echo "<meta http-equiv=refresh content=20; url='$conf[board_url]'>";
            
echo "Welcome back ".$membername;
            exit;
        }
     

else
{      
?> 

<form method="POST" action="<?php echo $GLOBALS ['../PHP_SELF'];?>"> 
<table class="newstable1" width="0%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
      <td class="newstable1" >Logon:</td>
    <td><input name="membername" size="25" type="text" id="membername"></td>
  </tr>
  <tr>
      <td class="newstable1">Password:</td>
    <td><input name="password" size="25" type="password" id="password"></td>
  </tr>
  <tr class="newstable1">
      <td align="center"><font color="#FFFFFF"> 
        <input type="submit" name="Submit" value="Submit">
        </font></td>
      <td align="center"><font color="#FFFFFF">
<input type="reset" name="reset" value="Reset">
        </font></td>
  </tr>
</table>
</form>
<?

?>


To try this file you can go hereLogin
logon: test
password: test

To view the actual page it will be on you can go here

I know I am having some problems with the cookie being set I have that wrong and am unable to find my booboo....Also this login page I would like to have it as an included file withing my index page. So if I need to login I just login. If I already have been logged in then the cookie part welcomes me back to the page.

Can someone please help.

Last edited by Attila : December 7th, 2002 at 05:37 PM.

Reply With Quote
  #6  
Old December 9th, 2002, 10:21 PM
Attila Attila is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 67 Attila User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
PHP Code:
<?
if (isset($_COOKIE["$cookiemember"]))

        {
        require 
"conf_global.php";
        
$link mysql_connect($conf['sql_host'], $conf['sql_user'], $conf['sql_pass']);
        
mysql_select_db($conf['sql_database'], $link) or die ("Connection Failed.");
            
$name2 mysql_query("SELECT memberid, membername, password, online, session, allow FROM member WHERE membername = '$cookiemember'");
            
$num_rows2 mysql_num_rows($name2);

            if (
$num_rows2 <= 0)
                {
                    die(
'This is crap!');
                }
            if(
mysql_num_rows($name2) != 0
                {
                
$wired = (time()) + 600;  //I want to add 10 minutes
                
$showonline = ("UPDATE member SET online = '$wired', session = '$wired' WHERE membername = '$membername'");
                
$result mysql_query($showonline) or die ("Query failed");
                }
        }

if (
$Submit

    require 
"conf_global.php";
    
$link mysql_connect($conf['sql_host'], $conf['sql_user'], $conf['sql_pass']);
    
mysql_select_db($conf['sql_database'], $link) or die ("Connection Failed.");

    
$name1 mysql_query("SELECT memberid, membername, password, online, session, allow FROM member WHERE membername = '$member' AND password = PASSWORD('$pass')");
    
$num_rows mysql_num_rows($name1);
    
    if (
$num_rows <= 0)
        {
        die(
"That username doesn\'t exist in our database or you entered the password wrong.");
        }
    
    while (
$row mysql_fetch_object($name1))
          {
            
$memberid $row->memberid;
            
$membername $row->membername;
            
$password $row->password;
            
$online $row->online;
            
$session $row->session;
            
$allow $row->allow;
          }
    
    
    if(
mysql_num_rows($name1) != 0
        {
            
$wired = (time()) + 600;  //I want to add 10 minutes
            
$showonline = ("UPDATE member SET online = '$wired', session = '$wired' WHERE membername = '$member'");
            
$result mysql_query($showonline) or die ("Query failed");
            
setcookie('cookiemember'$membername, (time()+2592000), '/'''); 
            
setcookie('cookiepass'$password, (time()+2592000), '/'''); 
            echo 
"Welcome back ".$membername;
            exit;
        }
     

else
{
    
?> 

<form method="POST" action="<?php PHP_SELF ?>"> 
<table class="newstable1" width="0%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
      <td class="newstable1" >Logon:</td>
    <td><input name="member" size="25" type="text" id="membername"></td>
  </tr>
  <tr>
      <td class="newstable1">Password:</td>
    <td><input name="pass" size="25" type="password" id="password"></td>
  </tr>
  <tr class="newstable1">
      <td align="center"><font color="#FFFFFF"> 
        <input type="submit" name="Submit" value="Submit">
        </font></td>
      <td align="center"><font color="#FFFFFF">
<input type="reset" name="reset" value="Reset">
        </font></td>
  </tr>
</table>
</form>
<?

?>


Can someone please help...I can log in now and it finds me but if I close the window and go back in another it dosen;t know how I am.

Once again yo can use test for user name and test for password.

The link is.Link

Please help....
Thanks
Attila

Last edited by Attila : December 10th, 2002 at 01:20 AM.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > PHP and Forms


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump