Jump to content

Recommended Posts

<?php

$host="localhost"; // Host name

$username="root"; // Mysql username

$password=""; // Mysql password

$db_name="test"; // Database name

$tbl_name="members"; // Table name

 

// Connect to server and select databse.

mysql_connect("$host", "$username", "$password")or die("cannot connect");

mysql_select_db("$db_name")or die("cannot select DB");

 

// username and password sent from form

$myusername=$_POST['myusername'];

$mypassword=$_POST['mypassword'];

 

// To protect MySQL injection (more detail about MySQL injection)

$myusername = stripslashes($myusername);

$mypassword = stripslashes($mypassword);

$myusername = mysql_real_escape_string($myusername);

$mypassword = mysql_real_escape_string($mypassword);

 

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";

$result=mysql_query($sql);

 

// Mysql_num_row is counting table row

$count=mysql_num_rows($result);

// If result matched $username and $password, table row must be 1 row

 

if($count==1){

// Register $username, $password and redirect to file "home.html"

session_register("myusername");

session_register("mypassword");

header("location:home.html");

}

else {

echo "Wrong Username or Password";

}

?>

 

 

This is the checklogin.php file. when the login has been aproved the user is redirected to the home.php page

Link to comment
https://forums.phpfreaks.com/topic/259743-help-please/#findComment-1331288
Share on other sites

Thanks,

 

I put this code into checklogin.php

 

if($count==1){

// Register $username, $password and redirect to file "home.html"

session_register("myusername");

session_register("mypassword");

header("location:home.php username=" . $myusername);

}

 

Getting this error message

 

The requested URL /website/home.php username=admin was not found on this server.

 

Sorry its probably easy fixed

 

Thanks again

Link to comment
https://forums.phpfreaks.com/topic/259743-help-please/#findComment-1331295
Share on other sites

<html>

<head>

<link rel="stylesheet" type ="text/css" href="anything2.css"

</head>

 

<body>

 

 

<div id="container">

 

<div id="header"><img src="imagesb.jpg" alt="Cool Image" align="left">

<img src="images.jpg" alt="Cool Image" align="right"><center><b><font size="6.5"><br><br>G.O.A.C.A Home Page</b></center></font>

 

</div>

 

 

<div id="leftnav"><center>

$_GET['username'];

<br><br>

<input type= "button" style="width:120px;" value="Personal Details" onClick="window.location= 'personaldetails.php' ">

<br><br>

<input type= "button" style="width:120px;" value="Club Details" onClick="window.location= 'clubdetails.php' ">

<br><br>

<input type= "button" style="width:120px;" value="Future Events" onClick="window.location= 'futureevents.php' ">

<br><br>

<input type= "button" style="width:120px;" value="News" onClick="window.location= 'news.php' ">

<br><br>

<input type= "button" style="width:120px;" value="FAQ" onClick="window.location= 'faq.php' ">

<br><br>

<input type= "button" style="width:120px;" value="Wall" onClick="window.location= 'wall.php' ">

<br><br>

<input type= "button" style="width:120px;" value="About Us" onClick="window.location= 'about.php' ">

</div>

 

<div id="body">

<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>

<A HREF = index.php>Log out</A>

 

 

 

 

<div id="footer">Welcome to the Glens of Antrim Chess Association Homepage!!!!</div>

 

</body>

</html>

 

Link to comment
https://forums.phpfreaks.com/topic/259743-help-please/#findComment-1331309
Share on other sites

well you are sending $myusername to home.php, which comes from this line in the checklogin page: $myusername=$_POST['myusername'];

So it should contain the username that the user enters.

Check to see if register_globals is turned on, place this code at the top of the page.

<?php echo "Register Globals: " . ini_get('register_globals'); ?>

Link to comment
https://forums.phpfreaks.com/topic/259743-help-please/#findComment-1331318
Share on other sites

It just returns at the top of the page

 

Register Globals:

 

Look at this bug report https://bugs.php.net/bug.php?id=34536

It should be returning a value.

As a quick fix, change the header to header("location:home.php?myusername=" . $myusername); and grab the value in home.php using $_POST['myusername'];

Link to comment
https://forums.phpfreaks.com/topic/259743-help-please/#findComment-1331355
Share on other sites

I might be totally wrong here, but I don't see a point of passing the username through a get request if you are already storing it in a session variable!

 

Instead of session_register, do a $_SESSION['myusername'] = $myusername;

 

and on the second page, just do

 

<?php
echo $_SESSION['myusername'];
?>

 

No need to play with GET requests!

Link to comment
https://forums.phpfreaks.com/topic/259743-help-please/#findComment-1331548
Share on other sites

That worked perfectly thanks. I kept the session register but the echo worked perfectly. now when i try to log out and login with a different user the first username is still displayed.

 

I have a logout function...

 

<?PHP

session_destroy();

?>

 

Is this the correct code to use when the logout link is pressed?

Link to comment
https://forums.phpfreaks.com/topic/259743-help-please/#findComment-1331550
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.