PHP coding help!!
Moderator: General Moderators
-
dhruvbhatia
- Forum Newbie
- Posts: 8
- Joined: Mon Oct 31, 2011 3:39 am
PHP coding help!!
Below is the code of index.php file. My motive is to first login by entering username and password. If the login details are correct then this includes/main.php part should run. If i include one at a time between main_login.php and main.php in index.php, then this thing works fine. But when I am including these both together, the login page is displayed for a second and automatically the main.php page is displayed. How can i rectify this thing? What should i do?
<?php
include_once("main_login.php");
require("includes/main.php");
try {
if($_GET['category']){
$c = new CategoryController();
}
else if(empty($_GET)){
$c = new HomeController();
}
else throw new Exception('Wrong page!');
$c->handleRequest();
}
catch(Exception $e) {
// Display the error page using the "render()" helper function:
render('error',array('message'=>$e->getMessage()));
}
?>
<?php
include_once("main_login.php");
require("includes/main.php");
try {
if($_GET['category']){
$c = new CategoryController();
}
else if(empty($_GET)){
$c = new HomeController();
}
else throw new Exception('Wrong page!');
$c->handleRequest();
}
catch(Exception $e) {
// Display the error page using the "render()" helper function:
render('error',array('message'=>$e->getMessage()));
}
?>
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: PHP coding help!!
Code: Select all
include_once("main_login.php");
require("includes/main.php");
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
-
dhruvbhatia
- Forum Newbie
- Posts: 8
- Joined: Mon Oct 31, 2011 3:39 am
Re: PHP coding help!!
main_login.php is a simple login page which takes the username and password. main.php contains statements like require_once(names of controllers, models, views)
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: PHP coding help!!
This explains why it is only displayed briefly, i assume you use this to login the user?dhruvbhatia wrote:main_login.php is a simple login page which takes the username and password.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
-
dhruvbhatia
- Forum Newbie
- Posts: 8
- Joined: Mon Oct 31, 2011 3:39 am
Re: PHP coding help!!
yea it is used to login a user
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: PHP coding help!!
That page is usually called by the submit form, why do you include it again? After successfull login the user is directed to an authenticated-users-only area and those pages include other relevant pages
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
-
dhruvbhatia
- Forum Newbie
- Posts: 8
- Joined: Mon Oct 31, 2011 3:39 am
Re: PHP coding help!!
This is the main.php file. Now can u tell me in detail as what should I do by making the changes wherever required. This 2nd part is done using MVC pattern whose files are included in main.php.
<?php
require_once "includes/config.php";
require_once "includes/connect.php";
require_once "includes/helpers.php";
require_once "includes/models/product.model.php";
require_once "includes/models/category.model.php";
require_once "includes/controllers/home.controller.php";
require_once "includes/controllers/category.controller.php";
// This will allow the browser to cache the pages of the store.
header('Cache-Control: max-age=3600, public');
header('Pragma: cache');
header("Last-Modified: ".gmdate("D, d M Y H:i:s",time())." GMT");
header("Expires: ".gmdate("D, d M Y H:i:s",time()+3600)." GMT");
?>
<?php
require_once "includes/config.php";
require_once "includes/connect.php";
require_once "includes/helpers.php";
require_once "includes/models/product.model.php";
require_once "includes/models/category.model.php";
require_once "includes/controllers/home.controller.php";
require_once "includes/controllers/category.controller.php";
// This will allow the browser to cache the pages of the store.
header('Cache-Control: max-age=3600, public');
header('Pragma: cache');
header("Last-Modified: ".gmdate("D, d M Y H:i:s",time())." GMT");
header("Expires: ".gmdate("D, d M Y H:i:s",time()+3600)." GMT");
?>
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: PHP coding help!!
The problem imo is not with the file or it's contents but with the fact that you are calling the login process page before you call the other page
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
-
dhruvbhatia
- Forum Newbie
- Posts: 8
- Joined: Mon Oct 31, 2011 3:39 am
Re: PHP coding help!!
So what should i do now?? what is the solution?
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: PHP coding help!!
What happens if you comment this line out : include_once("main_login.php");
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
-
dhruvbhatia
- Forum Newbie
- Posts: 8
- Joined: Mon Oct 31, 2011 3:39 am
Re: PHP coding help!!
Then the 2nd part works without the login part.
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: PHP coding help!!
Can the user login without it?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: PHP coding help!!
Ok. I don't understand the logic of the script because main_login should only be called once, from the form that requests user input; after that you have no need for it. Can you paste the code inside main_login.php
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
-
dhruvbhatia
- Forum Newbie
- Posts: 8
- Joined: Mon Oct 31, 2011 3:39 am
Re: PHP coding help!!
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="checklogin.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="text" id="mypassword"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
<tr>
<form name="form1" method="post" action="checklogin.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="text" id="mypassword"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>