redirect to another page

Posted on 2006-11-28
Medium Priority
Last Modified: 2008-03-06

Please assist how can we redirect to another page when the user has successfully login?

      $result = mysql_query($myQuery);
      $row = mysql_fetch_array($result);
      if ($myID==12345)
                                <-------------------------------------------------------------redirect to ../../main/index.php
                else { echo "Login failed."; }

Question by:FrankPorter
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 143

Accepted Solution

Guy Hengel [angelIII / a3] earned 1400 total points
ID: 18026537
header("Location: "../../main/index.php");

you have however to take care that there is NO output generated (print/echo/html) before the header function is run,.
LVL 11

Assisted Solution

ch2 earned 80 total points
ID: 18026617
If the file is moved permanently you can use like this.

header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.example.com/redirecto.html');
header('Connection: close');
LVL 11

Expert Comment

ID: 18026645
Well as i read better in your case the first comment will do the job.
Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?


Assisted Solution

jeffkee1985 earned 320 total points
ID: 18033180
I usually put in Meta tags - to put headers in it can get messy and complicated, and may interfere with other header things.

echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=index.php\">";
LVL 11

Expert Comment

ID: 18034067
<< to put headers in it can get messy and complicated, and may interfere with other header things.

which are those headers thing? could you explain why get complicated? why messy?
LVL 14

Assisted Solution

ygoutham earned 200 total points
ID: 18035311
setting up a meta tag might not pass on any variables between the pages. it is only a count and i have personally experienced difficulty in handling session cookies (irrespective of placing a meta tag after session_start(), placing values in cookies, etc) and have a meta tag with counter zero has no effect and sends the user back to the login page to relogin => creating a indeterminate loop.


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question