views:

46

answers:

3

hello,

i have created a login system with sessions in php,when used header to redirect to a particular page after checking username and password, it shows the following in firebug response "Failed to load source for: http://localhost/emp_tracker/main/edit_new.php" ,but it redirects in local system instead in server when i host it does not redirect.Is there any way to redirect other than header('Location:'.$filename);

Code: <?php session_start(); include("db_connect.php"); $filename="edit-grid.php"; $myusername = mysql_real_escape_string($_REQUEST['myusername']); $encrypted_mypassword = mysql_real_escape_string(crypt($_REQUEST['mypassword'], 'ctk')); $check_query=mysql_query ("select * from login where u_name='$myusername' and password='$encrypted_mypassword'"); $session_value=mysql_fetch_array($check_query); $count=mysql_num_rows($check_query); $session_name=$session_value['u_name']; if($count==1){$_SESSION['session_name']=$session_name; header('Location:'.$filename); } ?>

A: 

Hi Mayuri

what is the value of $filename in

header('Location:'.$filename)

Your redirects should work if the $filename is a relative path from the current page

eg: This would work all the time

$filename = './index.php' //relative path
header('Location:'.$filename) 

While this would only work on your local server

$filename = 'http://localhost/emp_tracker/main/edit_new.php'
header('Location:'.$filename)

EDIT: I see in your code you added to your post $filename is 'edit-grid.php' have you tried using './edit-grid.php' as the filename?

Hope it helps

Donnavan de Groot
@Donnavan de Groot...no its still showing the same thing in firebug
mayuri
Where does the file "edit_new.php" come into play with regards to the code in your post? perhaps the problem is in a different section of your code - Its just a guess as I cant see a reason for that coding to fail
Donnavan de Groot
if the user name and password matches it redirects to edit_new.php its in the same folder in which login page exists
mayuri
I've taken a closer look at your code and found one line that isn't making sense to me:-->What is this line? Theres also a extra quotation mark here : password='$encrypted_mypassword'";
Donnavan de Groot
check the edited code..its the select query...select * from login where u_name='$myusername' and password='$encrypted_mypassword'
mayuri
I was looking at the line before your select query :)
Donnavan de Groot
That code looks good to me :( Not sure why you're having problems with it - will keep an eye on this post its gonna bug me until its been resolved. Good luck
Donnavan de Groot
ya i am sorry i edited the code just check... thanks very much for the help
mayuri
Have you checked your code where it does the redirect on a successful login? I dont see it changing $filename to "edit_new.php" in that code
Donnavan de Groot
in my local wamp server although it shows failed to load it redirects to edit_new but when its hosted it does not redirect.
mayuri
i tried this echo '<META HTTP-EQUIV="Refresh" Content="0; URL=edit-grid.php">'; instead of header.. its showing moved temporarily in status in server but in local its working perfectly with no issus
mayuri
+1  A: 

You should use an absolute URL in your header() call.

Steve Claridge
A: 

Can you clarify this bit please?

"but it redirects in local system instead in server when i host it does not redirect"

kskjon
@kskjon....in my local wamp server although it shows failed to load source, it redirects to edit_new but when its hosted it does not redirect
mayuri
Thanks :) I'm not sure if the "failed to load source" is actually a problem with your code or if it's a problem with firebug. I assume "edit_new.php" sends some form of output to the browser?You could also try this:$host = $_SERVER['HTTP_HOST'];$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');header("Location: http://$host$uri/$filename");
kskjon
i tried this echo '<META HTTP-EQUIV="Refresh" Content="0; URL=edit-grid.php">'; instead of header.. its showing moved temporarily in status in server but in local its working perfectly with no issus
mayuri
I assume "edit_new.php" sends some form of output to the browser? ..answer: ya edit_new.php contains html in that i have some java script files which contain extjs framework
mayuri