+ Reply to Thread
Results 1 to 7 of 7

Thread: need help in PHP coding - double header not working if used twice??

  1. #1
    online41 is offline x10Hosting Member online41 is an unknown quantity at this point
    Join Date
    Dec 2011
    Posts
    2

    Unhappy need help in PHP coding - double header not working if used twice??

    hello.. im just a newbie here, and also in PHP coding..

    I'm having a problem with header syntax like this..
    Code:
    header("location:mysite.php");
    everytime i used this in a single PHP page twice,it doesn't redirect the page..

    can someone help me about header syntax?maybe i just didn't used the code right..
    i really appreciate the help..

    thanks!

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: need help in PHP coding - double header not working if used twice??

    That's not enough information to reproduce the problem. Create a minimal test case, post the code here and include a link to a live version of the minimal test case.

    For more on the syntax of the "Location" header, check the current HTTP standard. Note that though the standard calls for an absolute URI, many browsers support redirects to relative URIs.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  3. #3
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: need help in PHP coding - double header not working if used twice??

    Does it work if you only use it once?

    Why are you doing it twice? You should exit as soon as you use it the first time.
    Nothing is always absolutely so.

  4. #4
    online41 is offline x10Hosting Member online41 is an unknown quantity at this point
    Join Date
    Dec 2011
    Posts
    2

    Re: need help in PHP coding - double header not working if used twice??

    Quote Originally Posted by misson View Post
    That's not enough information to reproduce the problem. Create a minimal test case, post the code here and include a link to a live version of the minimal test case.

    For more on the syntax of the "Location" header, check the current HTTP standard. Note that though the standard calls for an absolute URI, many browsers support redirects to relative URIs.

    i've already changed my codes and used the header once.. but it still not redirecting to the location i put in the header... it still stays on the same page.. BTW i'm creating an online examination.. here's my code..

    PHP Code:
    <?php
    session_start
    ();
    include(
    "config.php");
    include(
    "overall_assess.php");
    include(
    "course_specialty_function.php");
    include(
    "exam_assess_function.php");
    $examid $_SESSION['examid'];
    $exam_score $_SESSION['exam_score'];
    $item_count $_SESSION['item_count'];
    $arith_score $_SESSION['arith_score'];
    $cler_score $_SESSION['cler_score'];
    $log_score$_SESSION['log_score'];
    $com_score $_SESSION['com_score'];

    $score_array = array($arith_score,$cler_score,$com_score,$log_score,);

    $result mysql_query("SELECT * FROM exam_result_tb WHERE username = '$_SESSION[username]'");
    $count=mysql_num_rows($result);

    $exam_no $count;
    if (
    $exam_score>$texam_good){
    echo 
    "Excellent";
    $remark "Excellent";
    }
    elseif (
    $exam_score>$texam_average&&$exam_score<=$texam_good){
    echo 
    "Good";
    $remark "Good";
    }
    elseif (
    $exam_score>$texam_fair&&$exam_score<=$texam_average){
    echo 
    "Average";
    $remark "Average";
    }
    elseif (
    $exam_score>$texam_poor&&$exam_score<=$texam_fair){
    echo 
    "Fair";
    $remark "Fair";
    }
    elseif (
    $exam_score>=0&&$exam_score<=$texam_poor){
    echo 
    "Poor";
    $remark "Poor";
    }

    include(
    "config.php");
    foreach(
    $score_array as $each_remark){
    if (
    $each_remark>=$logpass){
    $score_remark[]="Good";}
    elseif(
    $each_remark<$logpass && $each_remark>=$logave){
    $score_remark[]="Average";}
    elseif(
    $logave>$each_mark && $each_remark>="0"){
    $score_remark[] = "Failed";}
    }


    $s_time mysql_query("SELECT curtime FROM exam_result_tb WHERE examid = '$examid'");
    $row mysql_fetch_array($s_time);
    $curtime $row['curtime'];
    $time_end  time();
    $time_taken $time_end $curtime;
    $time_took_min "";
    $time_took_sec "";

    $time_took_min floor($time_taken/60);
    $time_took_sec = ($time_taken`);


    $tot_time_take = $time_took_min." minute(s),".$time_took_sec." second(s)";


        mysql_query("UPDATE exam_result_tb SET  time_taken='
    $tot_time_take',finish_time='$time_end',cler_score='$_SESSION[cler_score]',arith_score='$_SESSION[arith_score]',log_score='$_SESSION[log_score]',com_score='$_SESSION[com_score]',exam_score  = '$_SESSION[exam_score]', t_exam = '$texam' , remark =  '$remark',exam_no = '$exam_no' WHERE examid = '$examid'");
    $username=$_SESSION['username'];

    session_destroy();
    session_start();
    $_SESSION['time_end'] = $time_taken;
    $_SESSION['qualification'] = $ave_cat_remarks;
    $_SESSION['tot_time_take'] = $tot_time_take;
    $_SESSION['score_array'] = $score_array;
    $_SESSION['score_remark'] = $score_remark;
    $_SESSION['texam'] = $texam;
    $_SESSION['username'] = $username;
    $_SESSION['exam_remark'] = $remark;
    $_SESSION['exam_score'] = $exam_score;   
    $filename = "demo3.png";
    unlink(
    $filename);
    header("Location:onlineitexam.x10.mx/online_ex_php/exam_result.php");
    ?>

    any help and advice would be great.. thanks

  5. #5
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: need help in PHP coding - double header not working if used twice??

    Do you get an error with your code?

    You should not output anything other than the header.
    Nothing is always absolutely so.

  6. #6
    revcent is offline x10Hosting Member revcent is an unknown quantity at this point
    Join Date
    Dec 2011
    Posts
    5

    Re: need help in PHP coding - double header not working if used twice??

    Removing the apostrophe in the code below might solve your problem.

    PHP Code:
    $time_took_sec = ($time_taken`); 

  7. #7
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: need help in PHP coding - double header not working if used twice??

    That's hardly a minimal test case. Read the link in my previous post (it's there for a reason).

    Quote Originally Posted by online41 View Post
    PHP Code:
    header("Location:onlineitexam.x10.mx/online_ex_php/exam_result.php"); 
    That's likely not URL for a resource on your server. URLs are absolute, in which case they begin with a scheme (e.g. "http:"), or are relative, which is a path relative to the current URL (if there's no leading slash) or to the site root (if there is a leading slash). A few browsers may be able to understand URLs of the form "//www.example.com/path/to/resource", but you shouldn't depend on it. The URL you're setting is relative; the "onlineitexam.x10.mx" will be interpreted as a path component rather than the server name, and is relative to the location of the current page. The pages I previously linked to already cover this.

    Code should be indented for readability.

    Don't use SELECT * unless you're writing a DB administration program; select only the columns you need.

    Database access and application logic should be separated into distinct modules. Look up architectural patterns such as MVC and multi-tiered architectures (3-tier is common).

    The sample code may be vulnerable to SQL injection, which is a very serious security risk. To fix this hole, switch from the outdated (and soon-to-be deprecated) mysql extension to PDO and use prepared statements. Data shouldn't be interpolated directly into statements. If you need a PDO tutorial, try "Writing MySQL Scripts with PHP and PDO". The site you save may just be your own.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to Thread

Similar Threads

  1. Re: PHP header location not working on X10hosting
    By m_keeper53 in forum Programming Help
    Replies: 1
    Last Post: 12-10-2011, 03:50 PM
  2. PHP header location not working on X10hosting
    By sikuneh in forum Programming Help
    Replies: 9
    Last Post: 12-08-2011, 10:25 PM
  3. Header not working *MOVED*
    By scorch94 in forum Programming Help
    Replies: 11
    Last Post: 10-08-2011, 02:16 PM
  4. My coding isn't working
    By 0piper0halliwell0 in forum Programming Help
    Replies: 12
    Last Post: 11-07-2009, 12:04 PM
  5. PHP coding for banner header
    By bookwise in forum Programming Help
    Replies: 1
    Last Post: 12-02-2008, 08:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers