Jump to content

[SOLVED] link problem


thewooleymammoth

Recommended Posts

I created a login page a while ago, and i decided to turn it into a two page process, however i cant get the login.php page to link back to whatever page linked to it... i hope that makes sence.

 

page user logs in from: (which i would like to be every page on the site)

<?php
$tp='index.php';
$user2=$_COOKIE['auth'];
if(isset($_COOKIE['auth']))
  {  
  echo "welcome $user2<br>";
  echo "<form method='post' action='login.php'><input type='submit' value='logout' name='logout'>"; 
  }
  
elseif (!isset($_COOKIE['auth']))
  {
  echo "<a>please login:</a><br>
  <table>
  <form method='post'  action='login.php'>
  <tr>
    <td>Username:</td>
    <td><input type='text' name='username'></td>
  </tr>
  <tr>
    <td>Password:</td>
    <td><input type='password' name='password'></td>
  </tr>
  <tr>
    <td><input type='hidden' name='pn' value=$tp>
  <input type='submit' name='loggedin' value='Log In'><br></td>
    <td><a href='resister.php'>Register here</a></td>
  </tr>
</table>";
  }

else
{
echo "error";
}
  ?>

login page:

<?php
$tp=$_post['pn'];
$username="root";
$password="";
$database="userlist";
$table="login";
$connectmysql=mysql_connect('localhost',$username,$password) or die(mysql_error());
$selectdb=mysql_select_db($database) or die(mysql_error());
$user2=$_COOKIE['auth'];


if(isset($_POST['logout']))
{
setcookie("auth", "$user2", time()-3600);
echo "you have logged out<br><a href='$tp'>return to your page</a>";
}

elseif(isset($_COOKIE['auth']))
  {  
  echo "You have already logged in<br>";
  echo "<a href='$tp'>return to your page</a>$tp"; 
  }
  
elseif (isset($_POST['loggedin']))
  {
  $user=$_POST['username'];
  $userpass=$_POST['password'];
  $query=mysql_query("SELECT*FROM $table WHERE username='$user'") or die(mysql_error());
  $result=mysql_fetch_assoc($query);
  $connectmysql;
  $selectdb;
    if($user == $result['username'] && $userpass == $result['password'])
      {
      
      setcookie ('auth', $user, time()+3600);
      echo "You have logged in succesfully.<br> <a href='$tp'>return to your page</a>";
      }
    elseif ($userpass != $result['password'])
      {
      echo "bad user/password combanation please try again.<br> <a href='$tp'>return to your page</a>";      
      }
    
    elseif ($user !== $result['username'])
    {
    echo "bad user/password combanation please try again.<br> <a href='$tp'>return to your page</a>";
    }
  }

else
{
echo "error";
}
  ?>

 

the login.php page just refers back to itself and no matter how i play with the "" '' it never makes a difference

Link to comment
https://forums.phpfreaks.com/topic/69086-solved-link-problem/
Share on other sites

Hi,

 

On your login page, change $_post to uppercase. As $_post['tp'] is undefined, $tp will not be set to the value you expected, so when an empty string is used in your links, they link back to the same page.

 

<?php
$tp=$_POST['pn'];
// ... rest of code here.

 

Cheers,

Darren.

Link to comment
https://forums.phpfreaks.com/topic/69086-solved-link-problem/#findComment-347290
Share on other sites

Hi,

 

On your login page, change $_post to uppercase. As $_post['tp'] is undefined, $tp will not be set to the value you expected, so when an empty string is used in your links, they link back to the same page.

 

<?php
$tp=$_POST['pn'];
// ... rest of code here.

 

Cheers,

Darren.

 

 

 

 

 

 

OOOH MY GOD IM AN IDIOT thanks :) it still doesnt work though :( im still stumped, the way i have the quotes set up it should work right? maybe it has to do with my form in the login page... it looks like it should send the POST through so idk i hate my computer sometimes

Link to comment
https://forums.phpfreaks.com/topic/69086-solved-link-problem/#findComment-347292
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.