By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,664 Members | 1,643 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,664 IT Pros & Developers. It's quick & easy.

redirect page to other page when user logged in..

P: 1
when i used
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  @header("Location:google.co.in");
  3. ?>
  4.  
.. the page is not redirecting to that page,,

if i remove @ sign then it is showing worning session already started(...)in...

i m posting my error page also..
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. @session_start();
  3. require_once("connection.php");
  4. $pg=$_SERVER['HTTP_REFERER'];
  5. $ar=explode("/",$pg);
  6. $len=count($ar)-1;
  7. $page=$ar[$len];
  8. $err="";
  9. if($_POST['login']==2)
  10. {
  11. $password=$_POST['name3'];
  12. $email=$_POST['name2'];
  13. $sql="select * from tbl_user_reg where username='".$email."' and password='".$password."' and username!='' and password!=''";
  14. $res=mysql_query($sql) or die(mysql_error());
  15.     if(mysql_num_rows($res)>0)
  16.     {
  17.     if(isset($_GET['page']))
  18.         {
  19.         $page=$_GET['page'];        
  20.         }
  21.         $_SESSION['email_id']=$email;
  22.         @header("location: $page");
  23.         echo "download pdf........";
  24. exit;
  25.     }
  26.     else
  27.     {
  28.     $err="Invalid login";
  29.     echo $err;
  30.     }
  31.     }?>
  32.  
Sep 11 '08 #1
Share this Question
Share on Google+
3 Replies


Atli
Expert 5K+
P: 5,058
Hi.

First of all. It's a very bad idea to use the @ sign much in your code.
It is only meant to be used when you know that the error it is silencing won't affect the rest of your code. (Which, clearly, is not the case in your code)

I don't get why the header function would show you a "Session already started" error. Are you sure that is what is causing the error?

Also, make sure that nothing has been printed (or otherwise added) to the response before the header function is called.
Sep 11 '08 #2

P: 2
Modify your header function as follows:[PHP]@header("Location:http://google.co.in");[/PHP]
Sep 12 '08 #3

Atli
Expert 5K+
P: 5,058
Modify your header function as follows:[PHP]@header("Location:http://google.co.in");[/PHP]
Good point.

If you omit the "http://" prefix, the URL will be treated as a relative URL.

So if you set the following header in http://example.com/index.php :
Expand|Select|Wrap|Line Numbers
  1. header("Location: google.com");
  2.  
You would be redirected to http://example.com/google.com .
Sep 12 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.