php header() function help needed - automatic re-direct

free web hosting
Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

php header() function help needed - automatic re-direct

ashish_m_k
hey ppl, u seem to have real gud knowledge about php, i just wanted a little help...i designed this website, but i want that if i click on certain page, it should open for some few seconds and then browser should automatically redirect me to some other page....i tried this with header() function but i couldnt do the wait n redirect part, ...

so somebody plz help....
-thanx in advance!

Reply

electriic ink
I don't think that this is possible with php but you can do it with javascript. This code goes in the <head> tag:

HTML
<script type="text/javascript">

function goOnwards() {

window.location = "http://bla.com";

}

setTimeout("goOnwards()", 3000);

</script>

<!-- Provide an alternative for those without javascript -->

<noscript>

<meta http-equiv="refresh" content="3; url=http://bla.com">

</noscript>

Reply

DeveloperX
My answer in other topic:
http://www.trap17.com/forums/problem-page-...ect-t32062.html
I think that Header function better... <meta refresh>!

Code like
CODE

<meta http-equiv="refresh" content="5;url=http://www.mysite.com/nextpage.html">

can be stopped by Escape button pressing!!!

I think that this code will help U.
CODE

<?php

header("Location: http://www.example.com/"); /* Redirect browser */

/* Make sure that code below does not get executed when we redirect. */
exit;
?>  



View full description about Header function at http://php.rinet.ru/manual/ru/function.header.php with some examples.

 

 

 


Reply

kvkv

I don't think header function makes any sense as you cannot send headers once you have started your content. It is helpful for redirection if you want to do something without sending any output to browser and then redirect (like one file for doing operations and redirect to other to display UI). But once you have displayed some UI, it would have already committed the headers to browser. So, when you try to redirect, it gives error "headers already sent".

Reply

Spectre
Hmm, this topic is pretty old. But anyway, in response to kvkv...

Of course the headers need to be sent prior to any output. The headers inform the client of information required to ensure the client knows what to do with the data, and they must come before the data to which they are related. This is not specific to PHP (or Apache or any other web server), but rather to the hypertext transfer protocol, the protocol you are almost definately using to access webpages (see the specification for version 1.1 - the current standard - for details).

For example, let's say there are two files the client requests - 'page.html', a webpage, and 'image.jpg', an image. We can associate both files with their types due to their extensions (and, in this case, their full file names), but a web browser is not going to be able to differentiate one from the other unless the server tells it which is which via the 'Content-Type' header, which would be something like 'text/html' for the webpage and 'image/jpeg' for the image. Although some clients do identify files based on their file extension, that's not the way the HTTP works, and is just one of the reasons header information must accompany every packet of data sent from a HTTP server to the client. Without the header information, the client is not going to know what the data is or what to do with it, as well as other critical information (in which case most clients treat the data as 'text/plain', which is why you will sometimes find the contents images or other binary files are being printed to the screen as text).

Anyway, my overdrawn, pointless lecture slash rant is done smile.gif

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. php automatic direct - 54.21 hr back. (1)
Similar Topics

Keywords : php header function needed automatic

  1. PHP Function To Add Previous and Next Page Feature - useful php function (2)
  2. Tools Needed! - PHP & MySQL (9)
    Hello, everyone! I need some tools for those two things to test PHP scripts coming together with
    database on my laptop, instead checking them on a web-server which takes time....
  3. Tutorial Needed?! - PHP+Ajax (11)
    I need many tutorials based on PHP programming language and AJAX technology. Those tutorials might
    be of any kind. Please post only the links to the trusted and working tutorials!...
  4. Getting List Of Directories And Files Using Php - PHP Function for Directory and File List (6)
    is there a php function that lists the content of some folder.... example: /New folder new.txt
    left.gif download.zip dc.exe ....so is there..? /rolleyes.gif' border='0'
    style='vertical-align:middle' alt='rolleyes.gif' /> ...
  5. How To Use A Link To Call Function In Php? - (8)
    The title says it all, really. How do you call a function using in PHP? I'm doing a project
    and I stumbled upon this problem. I don't want to use query string in the href part like
    since that would mess up the other part of my code. Can anyone pleae help me? I've pasted the
    code below. /smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /> Thanksh.
    CODE <?php   function display($x){ //coding goes here.   } ?>
    <html> <body> <p align="center"> <a href="what g...
  6. Include File.php?id=something - using the include() function (13)
    Well, I am making a full CMS system for my site, and want to make the index.php file to include the
    view.php?id=1 file. I tried with this code, but it didn't work: CODE <?php include
    'view.php?id=1' ?> This is the error I get: CODE Warning:
    main(view.php?id=1) [function.main]: failed to open stream: Invalid argument
    in C:\server\xampp\htdocs\test\index.php on line 1 Warning:
    main() [function.include]: Failed opening 'view.php?id=1' for inclusion
    (i...
  7. How Good Is This Data Cleaning Function? - (2)
    Hi all, this is my first function and as part of a script and i just want to know a couple of
    things. here is the code for the function: CODE <? function
    clean($dirty_string) { $muddy_string = stripslashes($dirty_string);
    $murky_string = strip_tags($muddy_string); $clean_string =
    htmlentities($murky_string);      }; ?> So the first thing is how secure is
    it? the script this will be used in connects to a database and sends an email so it needs to stop
    SQL injections and any email ab...
  8. Creatting A Playlist Through Php - script help needed (5)
    Hi I am trying to make a script so that i can insert songs into a playlist, but i need a script in
    which it opens the playlist file and removes the closing tag at the end, so before i can add more
    entrys. e.g CODE <atx> <entry>Location 5</entry> <entry>Location
    4</entry> <entry>Location 3</entry> <entry>Location
    2</entry> <entry>Location 1</entry> <atx> But to add more entrys
    i would have to get rid of the atx, then use the fputs to place the new entry into the file. ...
  9. Admin Page - Tutorial Needed? (4)
    I need to look at a nice tutorial how do you create an admin access page with many functions as many
    as possible....
  10. Endif function? - (6)
    As you get noticed before, I am studying PHP in examples like using the tutorials as well as books
    itself. Through my readings, I get this function CODE <?php endif; ?> a lot of times.
    So, what do you mean by this function, and what does it do exactly?...
  11. Php Code Needed Iii - (10)
    Hello, everyone. I need your help again! Who might create the PHP code, the picture is
    above this text. Basically, I want when the user fill in all the information in this form, it
    automatically was sent to my email. And, then, the dialog box appears or on the same window, it was
    said that your request has been sent. Moreover, if the user did not fill the entire information,
    the dialog box appears stating that you did not fill some field. Thanks, for help. You always do
    that....
  12. Php Code Needed - Working Together? (5)
    Hello, everyone. I need your help again. This forum is quite good for it. Well, I need create a
    registration form for my web-site using PHP and SQL. The information it should contain: 1) User
    Name 2) First Name 3) Last Name 4) Password 5) e-mail Address 6) Security Image: that images helps
    to protect a random registration, for instance, 56+2=where user have to type an answer in order to
    finish registration. That's all for today. Anymore things, I will post another post over here.
    ...
  13. How To Check If Fsockopen Function Is Enabled? - (2)
    Hi, I have VPS (virtual private server) and I have access to php.ini file. Is there any script that
    will show that fsockopen function is enabled or where do I have to enable it? Searched google and
    here and couldn't find anything. Thanks! ...
  14. Php Code - Needed?! (15)
    Well, I am a novice in PHP programming, so there is a script which I wanna get: 1. You go the
    web-site 2. On the main screen, there is a some kind of field windows, the one you get used to type
    in, when you go to google, for instance. 3. He or she types her email address and it's going to
    be saved in my SQL database. 4. That's it. Help me if you can....
  15. Looking For Command Line Based Sql Modification - Program Needed For SQL? (1)
    How I use Windows command prompt client and do modifications to my SQL database. If yes, please
    write the commads I should know for that. If no, please get me the software with which I can do it.
    Topic title modified. Proper English is always required when posting in our forum. ...
  16. Slaed Cms - Book Needed!!! (2)
    Hello, everyone! I need some tutorial for Slaed Engine for any version you might find. I wanna
    learn how you can make modules or blocks for this CMS. Especially, library functions and other
    things that will make the web-site works like virtual library....
  17. Automatic Login Using Curl - (1)
    If you'are lazy people like me. This script may help u. This script is to automated our login to
    some site. You must have cURL installed to use this script. CODE <?php // INIT CURL
    $ch = curl_init(); // SET URL FOR THE POST FORM LOGIN curl_setopt($ch,
    CURLOPT_URL, 'http://www.external-site.com/Members/Login.php'); // ENABLE HTTP POST
    curl_setopt ($ch, CURLOPT_POST, 1); // SET POST PARAMETERS : FORM VALUES FOR EACH
    FIELD curl_setopt ($ch, CURLOPT_POSTFIELDS, 'fieldname1=fieldvalue1&fieldna...
  18. Mail() Clone - A PHP mail() function clone (5)
    A lot of free web hosts have disabled the mail() function so you cannot send emails using PHP. Does
    anybody know of a script that makes a function "like" mail but is able to be installed in a web
    accessible directory and called included into another script and called like that? Or maybe you know
    how to make such a function? I just really need to find a way around the free hosts turning of the
    mail() function. I need to figure out a way to send emails....
  19. Arrays Outside A Function - Need to have arrays available to all functions. (3)
    I've got a bunch of arrays that i want to use for more then 1 function. when i declear the
    arrays outside a function i cant use it in a function. This code was originally written in
    javascript by another person but since I plan to use it and extend it with php I had to change it
    from javascript to php code. In the javascript code the arrays were decleared outside the functions
    with 'var arrayname' I read somewhere that declearing javascript variables with
    'var' gives it global access. Any ideas on how I can go about declearing 1 set of these
    arrays t...
  20. The Best Zip Function - (1)
    hi my 6th code is very useful, you can zip your file by this: CODE <? class dZip{     var
    $filename;     var $overwrite;          var $zipSignature =
    "\x50\x4b\x03\x04"; // local file header signature     var
    $dirSignature = "\x50\x4b\x01\x02"; // central dir header signature
        var $dirSignatureE= "\x50\x4b\x05\x06"; // end of central dir
    signature     var $files_count  = 0;     var $fh;          Function
    dZip($filename, $overwri...
  21. Wamp Packages Needed To Test Scripts - Set up Apache, PHP, etc on your machine (1)
    In order to test php scripts on your localhost machine, you require a system that includes php
    parsing. A WAMP set-up 'usually' includes a database server, and a database manager, too.
    For Windows machines, theses are usually referred to as WAMP because they include Apache, Mysql, and
    PHP for Windows, hence the acronym WAMP. Wikipedia has a listing of the available packages with
    details about the included versions and often a link to the wikipedia article describing them. The
    list can be found at http://en.wikipedia.org/wiki/Comparison_of_WAMPs Personally, I...
  22. Php Explode Function Help - (4)
    I am having trouble creating a script, all i want to achieve is to: 1. Select the variable from my
    mysql database, which is in a format of : id|id|id|id| and so on... 2. Split them into separate
    variables by using : $songexploded = explode("|",$ttyo ); 3. Then this is the bit I'm
    stuck on trying to create a while loop from the $songexploded variables. So(this might not be
    correct but you should get the idea).. CODE $x=1; while ($songexploded
    ==$result) echo $songexploded[$x].'<br>'; }...
  23. Ipetsite Related Programming Help Needed - iPetSite screwed me over (0)
    Ok so i you are anyone here who would like to hlp me with these files, please pm me your email. Here
    is what i need help with: Replacement of lost files Repair of corrupt files Configuring said files
    Help with setting up the site If you can help me, please let me know. If you would like to be an
    admin on my site, also let me know. Just I request that you don't post here unless you plan or
    intend to help some how....
  24. [php](simple) Using Functions To Combine Values In A Form - Really simple example on how to combine values with function (2)
    I just learned this simple method on how to use functions to combine two values from a form. First
    we create ourselves a simple POST form CODE <form method="POST"> Name:
    <input type="text" name="nickname"> Location: <input
    type="text" name="location"> <input type="submit"
    value="Input"> </form> Now we add this php to that same file CODE
    <?php $nick = $_POST['nickname']; $location =
    $_POST['location' ...
  25. [php] Header Function - (2)
    Header function Greetings we are going to use the header() funtion to redirect start making a
    file called page.php at the top of the file add CODE <?php ?> Example 1 After
    CODE header('Location: http://www.trap17.com'); the LOCATION means
    where you want it to go. Example 2 you also can define a file that you want to redirect to After
    CODE header('Location: index.php'); Example 3 you also can add a timer to
    it /laugh.gif" style="vertical-align:middle" emoid=":lol:" border="0" alt=...
  26. The Extract() Function - Something I just found out (6)
    The extract() function is used in PHP to take an array and split it up into variables. MySQL
    queries can be parsed this way. Below is an example. CODE $query =
    mysql_query("select username, password from users where uid=1"); $result =
    mysql_fetch_array($query, mysql_assoc); extract($result); print "Your
    username is : $username"; The extract() function works for ANY array, including
    $_POST, and $_GET. Makes processing form data a LOT easier /biggrin.gif"
    style="vertical-align:midd...
  27. Error With Joomla Template - cant find function (1)
    Hello! I am working on my template in Dreamweaver and i am using joomla extensions for
    dreamweaver! When i start my page with joomla stand alone server(jsas) i get this errors on the
    bottom of the page! QUOTE Warning:
    mosloadcomponent(w:/www/Joomla/components/com_banner/banner.php) : failed to open stream: No such
    file or directory in w:\www\Joomla\includes\frontend.php on line 66 Warning:
    mosloadcomponent(w:/www/Joomla/components/com_banner/banner.php) : failed to open stream: No such
    file or directory in w:\www\Joomla�...
  28. Header Redirect Errors - (5)
    Hi, I am using the header function to redirect after the processing of the form. I have to specify
    a internal link using '#link'. This works in Firefox and opera. But in Internet Explorer
    internal linking when done from a redirect is not working for somewhat reasons. e.g.
    header("Location: http://www.example.com/index.php#link"); this works in Firefox and Opera but
    not in Internet Explorer . IE just accepts 'http://www.example.com/index.php' instead of
    http://www.example.com/index.php#link Please help me if you know anything about this. Well ther...
  29. Php Help Needed Including File In A Page. - (2)
    i'm a noob in php programming, i can understand and modify php programs, but i dont know to
    write on my own. So please somebody who is well versed in php help me. My need is, I'm
    currently builiding a knowledge base website , i've my own design for the website, check here,
    http://laschatz.info/kzone/ Each page in the left hand site has a tree navigation of all the
    topics available. Since this information must be same in all the pages, presently I need to change
    all the pages after adding a new category. Could you please help me in such a way that I can ad...
  30. Php - Fsockopen, Get, Etc - Help Needed - (1)
    Hi I am writing a PHP script that gets the search results from here . I can get the results from
    the first page fine, but when I try to get the next page, it doesn't return the correct results.
    Try comparing the results from here , and searching for "Vampire" (In the "Name" text box) here .
    The first page of results is the same, but when you go on the the second page of results, they are
    totally different. This I think is because the "persist_search" (see the URI on the Planet Elder
    Scrolls Search) always seems invalid. Is there any reason why the PHP would get...



Looking for php, header, function, needed, automatic, direct

Searching Video's for php, header, function, needed, automatic, direct
advertisement



php header() function help needed - automatic re-direct



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE