Results 1 to 7 of 7

Thread: php web redirect

  1. #1
    Join Date
    Nov 2007
    Beans
    665

    php web redirect

    Ok, so I have a simple redirect already. I would really like it to ask for a username and password before it will redirect you though and if you get it wrong then i won't redirect you. Please if you know of one already made online or if you would be willing to make me one then that would be amazing!

    -thank you!

  2. #2
    Join Date
    Jun 2006
    Location
    Gwangju, Korea
    Beans
    3,479
    Quote Originally Posted by RadiationHazard View Post
    Ok, so I have a simple redirect already. I would really like it to ask for a username and password before it will redirect you though and if you get it wrong then i won't redirect you. Please if you know of one already made online or if you would be willing to make me one then that would be amazing!

    -thank you!
    It shouldn't be too hard to write one yourself. Otherwise, you can use some pre-made CMS.

    By the way, if all you have is a login followed by a redirect, how will you do anything with that on the destination page? In other words, how will you prevent somebody from going to that page directly without logging in?
    Last edited by mssever; May 1st, 2008 at 11:10 PM.

  3. #3
    Join Date
    Nov 2007
    Beans
    665

    Re: php web redirect

    Quote Originally Posted by mssever View Post
    It shouldn't be too hard to write one yourself. Otherwise, you can use some pre-made CMS.

    By the way, if all you have is a login followed by a redirect, how will you do anything with that on the destination page? In other words, how will you prevent somebody from going to that page directly without logging in?
    i only want to keep then out of that one page
    and it only needs one username and pass

  4. #4
    Join Date
    Jun 2006
    Location
    Gwangju, Korea
    Beans
    3,479

    Re: php web redirect

    Quote Originally Posted by RadiationHazard View Post
    i only want to keep then out of that one page
    and it only needs one username and pass
    The easiest thing, then, would to use HTTP authentication. Apache has a several modules for that (mod_auth*).

  5. #5
    Join Date
    Jan 2007
    Beans
    71

    Re: php web redirect

    Hi,

    as i understand, you just need a _post to a specified page.
    Something like this:
    Code:
    <form method="post" action="secretPage.php">
    Name:<input name="name" type="text"></input><br>
    Password:<input name="password" type="password"></input><br>
    <input type="submit" value="Submit">
    </form>
    And your secret page (named secretPage.php) looks like this:

    Code:
    <?php
    	$name = addslashes($_POST["name"]);
    	$password = addslashes($_POST["password"]);
    
    	$user = "somename";
    	$passw = "somepassw";
    	if($name == $user && $password = $passw)
    	{
    		$body = "<b>you are a member</b>";
    	}
    	else
    	{
    		$body = "incorrect username and/or password";
    	}
    ?>
    
    <html>
    <body>
    <? echo $body; ?>
    </body>
    </html>
    This is a very simple example! You should use a database containing the username and passwords.

    I hope this is what you wanted to know.
    Intel(R) Core(TM)2 Duo CPU T5870 @ 2.00GHz
    Linux #-laptop 2.6.28-13-generic #45-Ubuntu SMP Tue Jun 30 19:49:51 UTC 2009 i686 GNU/Linux

  6. #6
    Join Date
    Apr 2008
    Beans
    3

    Re: php web redirect

    If you are want to protect only one page its will be great to use Sportingfan's code.
    If you want to redirect rather then posing the whole page you can choose between JS redirection (like this forum after you log in) or php redirection:

    just send to the browser (before anything sent!):
    PHP Code:
    header('Location: http://www.example.com/'); 
    or full code (stolen from Sportingfan):

    Code:
    <?php
    	$name = addslashes($_POST["name"]);
    	$password = addslashes($_POST["password"]);
    
    	$user = "somename";
    	$passw = "somepassw";
    	if($name == $user && $password = $passw)
    	{
    		$body = "<b>you are a member</b>";
    	}
    	else
    	{
                    header('Location: http://www.mySite.com/Login.php');
    	}
    ?>
    
    <html>
    <body>
    <? echo $body; ?>
    </body>
    </html>
    * I hope its working well

    for more information please read this:
    http://il2.php.net/header

    EDIT: u can write the whole page below because the user will leave ur page at the "header" line so he wont see the html code.
    Last edited by xtal; May 2nd, 2008 at 04:46 PM.

  7. #7
    Join Date
    Dec 2005
    Location
    Finland
    Beans
    339
    Distro
    Ubuntu Development Release

    Re: php web redirect

    Quote Originally Posted by xtal View Post
    If you are want to protect only one page its will be great to use Sportingfan's code.
    If you want to redirect rather then posing the whole page you can choose between JS redirection (like this forum after you log in) or php redirection:

    just send to the browser (before anything sent!):
    PHP Code:
    header('Location: http://www.example.com/'); 
    or full code (stolen from Sportingfan):

    Code:
    <?php
    	$name = addslashes($_POST["name"]);
    	$password = addslashes($_POST["password"]);
    
    	$user = "somename";
    	$passw = "somepassw";
    	if($name == $user && $password = $passw)
    	{
    		$body = "<b>you are a member</b>";
    	}
    	else
    	{
                    header('Location: http://www.mySite.com/Login.php');
    	}
    ?>
    
    <html>
    <body>
    <? echo $body; ?>
    </body>
    </html>
    * I hope its working well

    for more information please read this:
    http://il2.php.net/header

    EDIT: u can write the whole page below because the user will leave ur page at the "header" line so he wont see the html code.
    That's not entirely true. If the user agent has disabled redirects then the HTML would show. It's been a while since I did any PHP but I think you should do an exit() to end the execution of the current script.

Bookmarks

Posting Permissions

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