Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP - Direct to another page

    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 .

  • #2
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could simply do this client side, with javascript.

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

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

  • #3
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    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.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #4
    Registered User
    Join Date
    Apr 2003
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 .

  • #5
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    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.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #6
    New Coder
    Join Date
    Jan 2003
    Location
    Tulsa, OK
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I dont really suggest using header redirection. I found it much easier to use a simple meta tag.

    Code:
    <meta http-equiv="refresh" content="0; url=file.html">
    You could easily interpret that into a conditional statement:

    PHP Code:
    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.

  • #7
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Not all browsers support meta refresh do they?

  • #8
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Originally posted by bored
    I dont really suggest using header redirection. I found it much easier to use a simple meta tag.

    Code:
    <meta http-equiv="refresh" content="0; url=file.html">
    You could easily interpret that into a conditional statement:

    PHP Code:
    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.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #9
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Never had conflicts either No idea how it can cause conflicts....Unless it's something stupid like IE0.01

  • #10
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have never had any probs with PHP headers, and i think they are much safer than meta refreshes.

  • #11
    New Coder
    Join Date
    Jan 2003
    Location
    Tulsa, OK
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #12
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The chances are, the one error was a temporary server error, nothing to do with the header.

  • #13
    New to the CF scene
    Join Date
    Sep 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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

  • #14
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,077
    Thanks
    11
    Thanked 98 Times in 96 Posts
    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..

    PHP Code:
    $user=your_get_user_function($auth_id);
    header("location:{$user['default_page']}"); 
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • Users who have thanked firepages for this post:

    nw0123 (09-26-2013)

  • #15
    New to the CF scene
    Join Date
    Sep 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by firepages View Post
    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..

    PHP Code:
    $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


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •