|
-
Apr 6th, 2006, 08:06 PM
#1
Thread Starter
Frenzied Member
Easy Question about loading another page.
Hi guys,
I have this code to verify the login of a certain user. What I want is when the login succedd it will load another page.
PHP Code:
<?php
if(verify($name,$pass)!=1) echo "User Name or password is incorrect!";
else{
echo "Welcome: $name";
//Call here the page. mypage.php
}
?>
How can I do that?
-
Apr 6th, 2006, 08:26 PM
#2
Fanatic Member
Re: Easy Question about loading another page.
use this
PHP Code:
header("Location: mypage.php\n \r");
-
Apr 6th, 2006, 08:53 PM
#3
Thread Starter
Frenzied Member
Re: Easy Question about loading another page.
thanks for the quick reply but I got this error: Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\connectmssql.php:31) in C:\Program Files\Apache Group\Apache2\htdocs\verifylog.php on line 32]
-
Apr 6th, 2006, 08:55 PM
#4
Re: Easy Question about loading another page.
You can't use header() to redirect once you've sent data output (echo "Welcome: $name") - you can either use a meta tag to redirect after a timeout, or you can redirect straight away without sending any output (the quicker way).
-
Apr 6th, 2006, 09:05 PM
#5
Thread Starter
Frenzied Member
Re: Easy Question about loading another page.
pen I tried to remove the echo thingy in the else statement but nothing happens it still throws an error.
PHP Code:
if(verify($name,$pass)!=1) echo "User Name or password is incorrect!";
else{header("Location: mypage.php");}
?>
//and here's the verify function
function verify($name,$pass){
$query="select 1 from table where name='$name' and password='$pass'";
$r=mssql_query($query);
$max=mssql_num_rows($r);
return $max;
}
-
Apr 6th, 2006, 09:28 PM
#6
Re: Easy Question about loading another page.
See the bit in the error where it says
(output started at C:\Program Files\Apache Group\Apache2\htdocs\connectmssql.php:31)
The file and line it points to, look there - that is the bit you need to change. Anything like echo, print, or anything outsite <?php ?> tags needs to go.
-
Apr 6th, 2006, 09:47 PM
#7
Thread Starter
Frenzied Member
Re: Easy Question about loading another page.
Pen here's the code about connectmssql.php. It'a class for the connection through my database. What thing should I remove here? Sorry to ask such a noob question but this is my first time playing w/ php, actually this is my first project in php. So please bear w/ me.
PHP Code:
<?php
class DBConnect{
private $host;
private $user;
private $pw;
private $link;
public function myconnect($host,$user,$pw)
{
$this->host=$host;
$this->user=$user;
$this->pw=$pw;
$this->link=mssql_connect($this->host,$this->user,$this->pw);
if(!$this->link)
{
die('could not connect'.mssql_error());
}
}
public function myclose()
{
mssql_close($this->link);
}
}
?>
-
Apr 6th, 2006, 09:52 PM
#8
Re: Easy Question about loading another page.
Seems fine. Make sure there are no trailing characters after the closing ?> tag. < must be the first character and > the last, as anything outside them will be outputted.
-
Apr 6th, 2006, 10:02 PM
#9
Thread Starter
Frenzied Member
Re: Easy Question about loading another page.
Pen here's my full code. Any wrong w/ it?
PHP Code:
<?php
require 'connectmssql.php';
$db=new DBConnect;
$name=$_POST['name'];
$pass=$_POST['pass'];
$db->myconnect('xx','xx','xxxx');
mssql_select_db('xx');
function verify($name,$pass){
$query="select 1 from dtrlog where name='$name' and password='$pass'";
$r=mssql_query($query);
$max=mssql_num_rows($r);
return $max;
}
$db->myclose();
?>
<html>
<head><title>DTR</title>
<link rel='stylesheet' type='text/css' href='mystyle.css'>
</head>
<body>
<table>
<tr><td><img src='images/xxx.jpg'></td></tr>
</table>
<table cellpadding='3' cellspacing='3'>
<tr><td class='small'>
<?php
if(verify($name,$pass)==1){ header("Location: dtrshow.php");}
else{echo"<p class='bold'>User Name or password is incorrect!</p>";}
?></td></tr>
</table>
<hr>
</body>
</html>
-
Apr 10th, 2006, 06:02 AM
#10
Fanatic Member
Re: Easy Question about loading another page.
you see me... i don't like the problems i encounter when i try using the
PHP Code:
header("Location: page.html");
so my own way of always doing the redirection is
Code:
<script>
window.location = 'somepage.php';
</script>
and since i always use this JS function, i make it in to a php function so i can use it anytime(even when it subject to changes)
this is how i do it.
PHP Code:
function jsredir($url){
<script>
window.location = '$url';
</script>
}
so anytime i want to use it i do this
PHP Code:
jsredir("mypage.html");
and viola...
i like it when i do things like this(so simple)...
-
Apr 10th, 2006, 06:07 AM
#11
Re: Easy Question about loading another page.
 Originally Posted by mar_zim
Pen here's my full code. Any wrong w/ it?
Sorry, missed that post
It looks OK, but check that it is connecting to the DB properly. It might be that an error is being outputted and stopping the header from working.
modpluz - Never rely on Javascript.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|