...

View Full Version : PHP - Direct to another page



bahy
04-11-2003, 07:26 PM
In my PHP file , i have a button login , when i enter username and password ( right ones) i want the next page to display is the admin or userpage but i don't know how to code this in PHP , all i can do now is just give out a link to the file admin.php or member.php , that's not so good i think , so i am trying another way but got stuck .
Anyone around here can help me plz .

missing-score
04-11-2003, 07:48 PM
You could simply do this client side, with javascript.

If not, put a header at the top of the page...



<?php header('location:admin.php'); ?>

;)

Spookster
04-11-2003, 10:51 PM
For a login page what I would do is:

login.php

in this page you have nothing but your login form that submits to a page that actually processes the login for example

<form action="access.php">

in the access.php you could connect to your databse(assuming you are using a database) run your query to verify the login is valid so something like this:

if(login is valid)
header('location:admin.php');
else
header('location:login.php?error=true');

You could pass a variable back to the login page indicating a bad username or password and display an appropriate message to the user based off of the variable you pass.

bahy
04-14-2003, 07:00 PM
Redirect :
I tried to user the function header() but there is an error warning like this :"Warning: Cannot add header information - headers already sent by (output started at d:\fox\www\detai\page.inc:20) in d:\fox\www\detai\login.php on line 81 . So it did not redirect to another page as i wanted , how this can be solved ?
all i want is that it send us to another page after we have logged on successfully .

Spookster
04-14-2003, 07:24 PM
You cannot output anything to the browser before you send a header. That means no echo or print statements. Also make sure that that you have no spaces before <?php and after ?>. Any spaces there will make the parser go into HTML mode and output those spaces to the browser.

bored
04-14-2003, 09:01 PM
I dont really suggest using header redirection. I found it much easier to use a simple meta tag.



<meta http-equiv="refresh" content="0; url=file.html">


You could easily interpret that into a conditional statement:



if($condition) die("<meta http-equiv=\"refresh\" content=\"0; url=file.html\">");


The header redirect works just as well, but sometimes causes conflicts with browsers. The meta way is never mistaken.

missing-score
04-14-2003, 09:03 PM
Not all browsers support meta refresh do they?

Spookster
04-14-2003, 09:09 PM
Originally posted by bored
I dont really suggest using header redirection. I found it much easier to use a simple meta tag.



<meta http-equiv="refresh" content="0; url=file.html">


You could easily interpret that into a conditional statement:



if($condition) die("<meta http-equiv=\"refresh\" content=\"0; url=file.html\">");


The header redirect works just as well, but sometimes causes conflicts with browsers. The meta way is never mistaken.

What kind of coflicts? I've always found just the opposite that it is much safer and more reliable to send the headers from the server.

Nightfire
04-15-2003, 12:15 AM
Never had conflicts either :confused: No idea how it can cause conflicts....Unless it's something stupid like IE0.01

missing-score
04-15-2003, 12:30 AM
I have never had any probs with PHP headers, and i think they are much safer than meta refreshes.

bored
04-15-2003, 05:56 PM
Its based off a pretty small error ratio. But one error is enough for me. To each his own i guess.

And as far as compatibility, I've used a lot of different browser structures on multiple platforms and all have performed the meta refresh correctly.

missing-score
04-15-2003, 06:03 PM
The chances are, the one error was a temporary server error, nothing to do with the header.

nw0123
09-25-2013, 03:03 PM
can i take this one step further.

would it be easy enough to redirect to a url that is specific to the user that is held in the db with the username and password ie having db fields of user; pass; redirect;

so when the username and password are verified, the redirect command calls the db field redirect to get the page required?

many thanks

nick

firepages
09-26-2013, 02:01 PM
10 year old thread resurrection :) good job :)

answer is yes .. so when you authenticate the user, you would then pull out the relevant data from the db for that user and add that info to the header..



$user=your_get_user_function($auth_id);
header("location:{$user['default_page']}");

nw0123
09-26-2013, 10:59 PM
10 year old thread resurrection :) good job :)

answer is yes .. so when you authenticate the user, you would then pull out the relevant data from the db for that user and add that info to the header..



$user=your_get_user_function($auth_id);
header("location:{$user['default_page']}");


Completely new to php, and I was on the right lines, but I couldn't quite get it to work properly.

Thank you for your help even if I did resurrect a dinosaur of a thread.

Nick

jaspreetsingh90
09-27-2013, 08:22 AM
In my PHP file , i have a button login , when i enter username and password ( right ones) i want the next page to display is the admin or userpage but i don't know how to code this in PHP , all i can do now is just give out a link to the file admin.php or member.php , that's not so good i think , so i am trying another way but got stuck .
Anyone around here can help me plz .

<form acrtion="admin.php" name="form">

type ur code here


</form>

jaspreetsingh90
09-27-2013, 08:24 AM
[QUOTE=jaspreetsingh90;1359720]<form action="admin.php" name="form">

type ur code here


</form>




fix the action



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum