Redirect in PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Are you sure the redirection code is being run? I often recommend not looking for a submit button to be apart of the submission data, this is because some browsers don't send the submit button if it wasn't actually used.
User avatar
chrys
Forum Contributor
Posts: 118
Joined: Tue Oct 04, 2005 9:41 am
Location: West Roxbury, MA (Boston)

Post by chrys »

nickman013 wrote:You need to specify the full URL for $url.

For example

videos.php would be somthing like http://www.mysite.com/videos.php.

Not necessarily true
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If you want to conform to the HTTP standards, it's absolutely true.
User avatar
chrys
Forum Contributor
Posts: 118
Joined: Tue Oct 04, 2005 9:41 am
Location: West Roxbury, MA (Boston)

Post by chrys »

It will work if you don't, is what I mean
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Some browsers and agents out there will only conform to the standards. If you want the site to be accessible to all, conform to the standards. It's not like it's hard to write a full url for the redirection.. :roll:
User avatar
chrys
Forum Contributor
Posts: 118
Joined: Tue Oct 04, 2005 9:41 am
Location: West Roxbury, MA (Boston)

Post by chrys »

feyd wrote:Some browsers and agents out there will only conform to the standards. If you want the site to be accessible to all, conform to the standards. It's not like it's hard to write a full url for the redirection.. :roll:
lol, true, for me it's just {$http_dir}/page.php, gotta love smart ;o
Dark_AngeL
Forum Commoner
Posts: 39
Joined: Tue Feb 21, 2006 5:16 am

Post by Dark_AngeL »

So there is no hope in solving it?
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

Dark_AngeL wrote:So there is no hope in solving it?
Show the latest version of your code so we can clear this up. Each time you've mentioned an error, we've discussed the fix for it.

Show the code, and post the error, and we'll help you understand it. :)
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

Put this at the very top of your page, in between PHP tags.

Code: Select all

error_reporting('E_ALL');
Dark_AngeL
Forum Commoner
Posts: 39
Joined: Tue Feb 21, 2006 5:16 am

latest code

Post by Dark_AngeL »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Code: Select all

<?php 
error_reporting('E_ALL');  

if(isset($_POST['submit']) && $_POST['submit'] == 'Submit') //if form has been submitted
{
   $url = "http://localhost/Warehouse_Services_Operations_System/main.php";
   $denied = "";
   $name = $_POST['name'];
   $pass = $_POST['pass'];
   if ($name == "Heba" &&  $pass == "123")
   {
       header('Location: '.$url.''); /* Redirect browser */
       exit;                
   }
   else {
       $denied = "Sorry. You are not authorized to access this page<br>Go <a href='index.php' onclick='history.go(-1);return false'> Back </a>";
   }
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>SYS</title>
.
.
.
.
...
.
.
.
.
.
.
<body>
<?php
if(!empty($denied))
{
echo $denied;
}
?>
.
.


...



.
.
.
.
.
.
.
</body>
</html>
This is the check_login.php Code!


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Re: latest code

Post by Roja »

Dark_AngeL wrote:This is the check_login.php Code!
What you've posted doesn't have a form to submit (so we cant test), and doesn't have an error.
Dark_AngeL
Forum Commoner
Posts: 39
Joined: Tue Feb 21, 2006 5:16 am

Post by Dark_AngeL »

This is the index.php the page which has the form in

Code: Select all

<form name="login" method="post" action="check_login.php"?>
	  <div align="center">
        <div align="center">
    <table width="232" border="2" cellspacing="3" bordercolor="#000000" bgcolor="#FFFFFF">
        <tr>
          <td width="64"><div align="center" class="style19 style21">
            <div align="left"><span class="style22">Username:</span></div>
          </div></td>
          <td width="120" colspan="2"><div align="center" class="style24">
            <div align="left">
              <input type="text" name="name" size="20">
            </div>
          </div></td>
          </tr>
        <tr>
          <td><div align="center" class="style24">
            <div align="left"><span class="style22">Password:</span></div>
          </div></td>
          <td colspan="2"><div align="center" class="style24">
            <div align="left">
              <input type="password" name="pass" size="20">
</div>
          </div></td>
          </tr>
    </table>
    <table width="200" border="0" cellspacing="6">
            <tr>
              <td><div align="center">
                <input name="btnletmein" type="submit" value="Let me in!" id="send" onclick="return checkForm()">
              </div></td>
              </tr>
          </table>
    </div>
        </div>
      </form>
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

Your if statement is never triggered:

Code: Select all

if(isset($_POST['submit']) && $_POST['submit'] == 'Submit') //if form has been submitted
Remove that, and everything seems to work fine in my test.
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

Yeah, There is no need for that. Unless there is more code?
Dark_AngeL
Forum Commoner
Posts: 39
Joined: Tue Feb 21, 2006 5:16 am

Post by Dark_AngeL »

Yes :D

when a wrong info is intered this message occurs Sorry. You are not authorized to access this page But when correct info is entered it takes me to a page with HTTP 500 - Internal server error
Internet Explorer
Post Reply