Jump to content

Where would i add this part of php to this part of php?


Recommended Posts

Hi guys im having trouble with my login page as people go to my webiste index.php is restricted only for member so it redirects to login.php but when it redirects to the login page, the login page dosent have a register buttong link so this is the code i want on the login page and i cant add this myself

 

 

I want this code added to the login page:

<?php

{

echo "<form action="?op=reg" method="POST">";

echo "<input type="submit\" value="Register">";

echo "</form>";

}

?>

 

 

 

Login.php

<?php

session_start();

// dBase file

include "dbConfig.php";

 

if ($_GET["op"] == "login")

{

if (!$_POST["username"] || !$_POST["password"])

  {

  die("You need to provide a username and password.");

  }

 

// Create query

$q = "SELECT * FROM `dbUsers` "

  ."WHERE `username`='".$_POST["username"]."' "

  ."AND `password`=PASSWORD('".$_POST["password"]."') "

  ."LIMIT 1";

// Run query

$r = mysql_query($q);

 

if ( $obj = @mysql_fetch_object($r) )

  {

  // Login good, create session variables

  $_SESSION["valid_id"] = $obj->id;

  $_SESSION["valid_user"] = $_POST["username"];

  $_SESSION["valid_time"] = time();

 

  // Redirect to member page

  Header("Location: index.php");

  }

else

  {

  // Login not successful

  die("Sorry, You have enterd a wrong Username or Paswword please try again and be more carefull with your spelling!");

  }

}

else

{

//If all went right the Web form appears and users can log in

echo "<form action=\"?op=login\" method=\"POST\">";

echo "Username: <input name=\"username\" size=\"15\"><br />";

echo "Password: <input type=\"password\" name=\"password\" size=\"8\"><br />";

echo "<input type=\"submit\" value=\"Login\">";

echo "</form>";

}

?>

 

I hope you guys no what i am trying to say! please try and add the code to the login page! thanks to all of you who try and support me!

Link to comment
Share on other sites

One more Question just to make this easy to understand from this end... Are you putting your code into HTML  ?

 

E.g your web page looks like  :

 

www.example.com/index.html

 

or

 

www.example.com/login.php

 

 

Link to comment
Share on other sites

I see the problem here, you should consider having your login.php on included in a index.html page (looks better too with some design work)

Then have a link for registration on this page  :

 

<a href=\"register.html

 

Which will include your PHP 

 

 

Am I making sence for you ?

Link to comment
Share on other sites

Well it makes more sence to have your PHP script embedded in html

(sense)

 

Why?

 

Besides, you can't embed PHP in HTML unless you configure the server to parse HTML as PHP. If you embed in PHP, you'll have to modify Apache configuration to parse HTML as PHP.

Link to comment
Share on other sites

I Totaly understand ill try the

 

<?php

include ('login.php')

?>

 

Thansk for your suggestion.

 

unless your server is configured to parse .html as PHP, that will only display the following:

 

<?php

include('login.php');

?>

 

 

A PHP file doesn't even have to have any PHP in it. This is a valid PHP file:

 

<HTML>
<BODY>
something here.
</BODY>
</HTML>

 

you can use HTML in a PHP file wherever you want without re-configuring your server.

Link to comment
Share on other sites

Appologies for confusion guys I mean have your normal web page (your html part) then include your php with  : This way you can include the two parts of your PHP without any hassle .

 

 

<!--#include file="example.php" --> 

Link to comment
Share on other sites

Appologies for confusion guys I mean have your normal web page (your html part) then include your php with  : This way you can include the two parts of your PHP without any hassle .

 

 

<!--#include file="example.php" -->   

 

that also won't work. first, you have to turn on the ability to use includes, your file name will have to end in .shtml (unless you change another configuration) and then the include will include the PHP code without parsing it.

 

the only way to 'include' PHP in HTML is to configure Apache to parse HTML as PHP.

 

No offense, but have you ever written any PHP?

 

Link to comment
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.