7 Replies - 435 Views - Last Post: 02 September 2013 - 06:41 PM

#1 dannybarh  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 19-February 11

Apart from Head("") is there an other way to redirect in php?

Posted 02 September 2013 - 06:27 AM

Am currently using this code, but it abit slow for my liken
echo '<meta http-equiv="REFRESH" content="0; url=veh_type.php?nav=default" />';


Am getting this error when i use head();
Warning: Cannot modify header information - headers already sent by (output started at D:\xampp\htdocs\auto-habari\admin\userindex\inc\main_nav_head2.php:215) in D:\xampp\htdocs\auto-habari\admin\userindex\vehicles\insert.php on line 754


Is This A Good Question/Topic? 0
  • +

Replies To: Apart from Head("") is there an other way to redirect in php?

#2 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3746
  • View blog
  • Posts: 13,116
  • Joined: 12-December 12

Re: Apart from Head("") is there an other way to redirect in php?

Posted 02 September 2013 - 06:39 AM

Do you mean header()?

the docs

Quote

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

Even a space being output before the header() call can cause the error message you posted.
Was This Post Helpful? 0
  • +
  • -

#3 dannybarh  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 19-February 11

Re: Apart from Head("") is there an other way to redirect in php?

Posted 02 September 2013 - 06:47 AM

so apart from
header();
is there another way?
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3746
  • View blog
  • Posts: 13,116
  • Joined: 12-December 12

Re: Apart from Head("") is there an other way to redirect in php?

Posted 02 September 2013 - 06:54 AM

What's wrong with header()? Just make sure that you don't output anything before calling it.

There are server re-directs (in your server settings) but if you are re-directing from one page, within another page, then you need to use header() (or echo an html meta-tag like you did originally).

This post has been edited by andrewsw: 02 September 2013 - 06:58 AM

Was This Post Helpful? 1
  • +
  • -

#5 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3572
  • View blog
  • Posts: 10,414
  • Joined: 08-June 10

Re: Apart from Head("") is there an other way to redirect in php?

Posted 02 September 2013 - 06:56 AM

Java­Script, but that’s essentially the same as in HTML.
Was This Post Helpful? 0
  • +
  • -

#6 dannybarh  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 19-February 11

Re: Apart from Head("") is there an other way to redirect in php?

Posted 02 September 2013 - 07:33 AM

Thank all of you for your help, this is my code

<?php session_start(); include "inc/config.php";
if ($_SESSION["login1"]== "Superadmin" or $_SESSION["login1"]== "User" or $_SESSION["login1"]=="Administrator")
{
	$snames = $_SESSION["name1"];
	$id = $_SESSION["id1"];
	$stype = $_SESSION["login1"];
	$navtype = $_GET['nav'];
	include("inc/ps_pagination.php"); 
	}else{header ("location: ../../../index.php");}?>
  
<?php
									//time ago function
									function time_ago($date)
									{
									if(empty($date)) {
									return "No date provided";
									}
									$periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
									$lengths = array("60","60","24","7","4.35","12","10");
									$now = time();
									$unix_date = strtotime($date);
									// check validity of date
									if(empty($unix_date)) {
									return "Bad date";
									}
									// is it future date or past date
									if($now > $unix_date) {
									$difference = $now - $unix_date;
									$tense = "ago";
									} else {
									$difference = $unix_date - $now;
									$tense = "from now";} 
									for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
									$difference /= $lengths[$j];
									}
									$difference = round($difference);
									if($difference != 1) {
									$periods[$j].= "s";
									}
									return "$difference $periods[$j] {$tense}";
									}

?>


can you tell me what i may be missing...

This post has been edited by dannybarh: 02 September 2013 - 07:35 AM

Was This Post Helpful? 0
  • +
  • -

#7 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3746
  • View blog
  • Posts: 13,116
  • Joined: 12-December 12

Re: Apart from Head("") is there an other way to redirect in php?

Posted 02 September 2013 - 07:45 AM

The error message says that the output started in the page-header file (which makes sense):

Quote

(output started at D:\xampp\htdocs\auto-habari\admin\userindex\inc\main_nav_head2.php:215

which is not shown in your code fragment.

This post has been edited by andrewsw: 02 September 2013 - 07:45 AM

Was This Post Helpful? 0
  • +
  • -

#8 dannybarh  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 19-February 11

Re: Apart from Head("") is there an other way to redirect in php?

Posted 02 September 2013 - 06:41 PM

thanks andrewsw for pointing me in the right direction, i have included the header(); twice on the same page,thanks again.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1