Jump to content
Larry Ullman's Book Forums

Redirect Header Function Works On Localhost But Not Under Yahoo Hosting


Recommended Posts

Hello,

Please help!  Thank you.

 

I have a webpage (a member log in page called logcheck.php) which allows members to enter their member name and password, then once the member name (member_name) and password (pass) are validated, i.e. the combination is found in a unique record in the members table in a mysql database called test  , then members will be redirected to another page (called byimain.php) on my website using. 

header('Location: byimain.php');

 

This works perfectly when I run it on localhost where the mysqli connect function is as follows:

$dbc = @mysqli_connect('localhost', 'root', 'password', test') OR die ('Could not connect to MySQL: ' . mysqli_connect_error());

 

Now I sign up with yahoo as my web hosting. I have to set up access to mySQL and to create a new username and password for mySQL database (phpMyadmin).    I also created a database called test to store my members table, and on my members table, I have one row with member_name = janekoo and pass = passjk .  Yahoo told me the host now is mysql instead of localhost.  So my new mysqli connect function will be:

 

$dbc = @mysqli_connect('mysql', 'xxx', 'yyy', test') OR die ('Could not connect to MySQL: ' . mysqli_connect_error()); 

 

where xxx =username and yyy = password

 
I know the mysql part and the validation of the member_name and pass against the members table in the test database are working because for testing,  I program to have the sentence "I am in" to display on the member log in page if someone enters janekoo as member_name and passjk as password.  And I did get "I am in".  But I cannot get the redirection to the byiman.php page with yahoo hosting which I can under localhost.
 
Before Yahoo allows me to set up mySQL access, I have to upgrade my php from version 5.2  to a newer version 5.3.  Before my script is under version 5.2, now it is under version 5.3.
Will that upgrade cause 
header('Location: byimain.php'); not to work under yahoo hosting?
 
Once again, the following script works fine under localhost, but not under Yahoo hosting.  Under Yahoo hosting, I cannot get the redirect to byimain.php when users enter the correct member name and password.   
 
Below is my script in the members log in page:
 
<?php
 error_reporting (E_ALL ^ E_NOTICE);
 
?>
 
<!DOCTYPEhtml><html>
<head>
<title> Login Form </title>
 
 
 
<style type="text/css" media="screen">
    form div{
         margin-bottom: 1em;
}
 
    
    
 
</style>
</head> 
 
<body bgcolor=#FFFFFF>
<h1> Log In </h1>
 
<?php
$form = "<form action='logcheck.php' method='POST'>
  <table>
   <tr>
     <td> Username: </td>
    
     <td> <input type='text' name='member_name' /> </td>
    </tr>
 
    <tr>
     <td> Password: </td>
     <td> <input type='password' name ='pass'/> </td>
    </tr>
 
   <tr>
     <td></td>
   </tr>
 
    <tr>
     <td></td>
     <td> <input type='submit' name='submit' value='submit'/> </td>
    </tr>
 
   </table>
   
  
   
</form>";
         echo $form;
 
?>
 
 
 
<?php
//Check for form submission
 
if ($_SERVER['REQUEST_METHOD'] =='POST'){
    
     $m=($_POST['member_name']);
   
 
     $p=($_POST['pass']); 
 
 
// Register the user in the database host = mysql, username = xxx, password = yyy, database = test.
 
$dbc = @mysqli_connect('mysql', 'xxx', 'yyy', 'test') OR die ('Could not connect to MySQL: ' . mysqli_connect_error());
 
 
//Retrieve the first_name, and last_name for that email/password combination:
 
  $q= "SELECT member_id FROM members WHERE member_name = '$m' AND pass = '$p' ";
 
 
//Run the query:
 
$r= @mysqli_query($dbc, $q);
 
//Check the results
 
if (mysqli_num_rows($r) == 1) { //if a record is found
 
//Success message
 
header('Location: byimain.php');
 
 
 
}else{//if no record is found
 
//Problem message
print '<p style="color: red;"> Incorrect username and password combination.  Or username and/or password fields are blank. Please try again! </p>';
}
 
 
//Close the database connection
 
mysqli_close($dbc);
 
exit();
 
}
 
?>
 
 
 
</body>
 
</html>
 
 
Link to comment
Share on other sites

Okay, so first of all, the MySQL stuff won't affect the redirection and vice versa. Best not to confuse the roles that these elements play. 

 

Second, I'd use exit(); after calling header() as a matter of practice. 

 

Third, you say you can't get the redirect to work. What does happen? What URL is the browser left on?

Link to comment
Share on other sites

 Share

×
×
  • Create New...