Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    Regular Coder
    Join Date
    Jan 2012
    Location
    Slovakia
    Posts
    111
    Thanks
    9
    Thanked 0 Times in 0 Posts

    header and php version

    Hi ... i have this: header('Location: "'.$redirect.'" '); when i echo my $redirect it show good url ... but when i try it .. nothing happend. Any ideas ?

    http://sk.php.net/manual/en/function.header.php

    The syntax is good .. but it worked when i had lower php version.... today i updated to 5.3 ... and from now it doesnt work why?

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Do you have an exit(); after it?
    Try this
    PHP Code:
    header("Location: $redirect");
    exit(); 
    Also it needs to come before you have any output to the browser.
    Last edited by _Aerospace_Eng_; 01-21-2012 at 03:49 PM.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    Trki (01-21-2012)

  • #3
    Regular Coder
    Join Date
    Jan 2012
    Location
    Slovakia
    Posts
    111
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    Do you have an exit(); after it?
    Try this
    PHP Code:
    header("Location: $redirect");
    exit(); 
    Also it needs to come before you have any output to the browser.
    hm... i have this in my file:

    PHP Code:

    <?php

    session_start
    ();

    require_once 
    './includes/functions.php';

    connect();

    $id_comment=clean_get_include($_GET['id_comment']);
    $id_clanku=clean_get_include($_GET['id_clanku']);

    $mysql_delete='DELETE FROM blog_comments WHERE id='.$id_comment.'';
    $mysql_query=mysql_query($mysql_delete);



    echo 
    $redirect="http://www.example.com/clanok/blog_obsah/id/".$id_clanku."";

    header('Location: "'.$redirect.'" ');
    exit();
                                       




    ?>

    and if i echo $redirect the url is good
    doesnt work i have no idea where could be a problem
    Last edited by Trki; 01-21-2012 at 05:17 PM.

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Quote Originally Posted by Trki View Post
    PHP Code:
    //You cannot do this.
    echo $redirect="http://www.example.com/clanok/blog_obsah/id/".$id_clanku."";

    header('Location: "'.$redirect.'" '); 
    (
    You can't echo the url first. You can only use header() BEFORE any output not after it.

    See the link in my signature about headers for more information.

    Also remove those double quotes from inside the header() call.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #5
    Regular Coder
    Join Date
    Jan 2012
    Location
    Slovakia
    Posts
    111
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    You can't echo the url first. You can only use header() BEFORE any output not after it.

    See the link in my signature about headers for more information.

    Also remove those double quotes from inside the header() call.
    i am still reading your topics .but ...

    this: still not working

    PHP Code:
    <?php

    session_start
    ();  

    require_once 
    './includes/functions.php';

    connect();

    $id_comment=clean_get_include($_GET['id_comment']);
    $id_clanku=clean_get_include($_GET['id_clanku']);

    $mysql_delete='DELETE FROM blog_comments WHERE id='.$id_comment.'';
    $mysql_query=mysql_query($mysql_delete);



    $redirect="http://www.trki.sk/clanok/blog_obsah/id/".$id_clanku."";

    header('Location: '.$redirect.' ');
    exit();
                                       




    ?>
    or... the header should be in the TOP? but it of course not working
    Last edited by Trki; 01-21-2012 at 07:26 PM.

  • #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Try this
    PHP Code:
    <?php 

    session_start
    ();   

    require_once 
    './includes/functions.php'

    connect(); 

    $id_comment=clean_get_include($_GET['id_comment']); 
    $id_clanku=clean_get_include($_GET['id_clanku']); 

    $mysql_delete="DELETE FROM blog_comments WHERE id=$id_comment"
    $mysql_query=mysql_query($mysql_delete); 



    $redirect "http://www.trki.sk/clanok/blog_obsah/id/".$id_clanku

    header("Location: $redirect"); 
    exit(); 
    ?>
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #7
    Regular Coder
    Join Date
    Jan 2012
    Location
    Slovakia
    Posts
    111
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    Try this
    PHP Code:
    <?php 

    session_start
    ();   

    require_once 
    './includes/functions.php'

    connect(); 

    $id_comment=clean_get_include($_GET['id_comment']); 
    $id_clanku=clean_get_include($_GET['id_clanku']); 

    $mysql_delete="DELETE FROM blog_comments WHERE id=$id_comment"
    $mysql_query=mysql_query($mysql_delete); 



    $redirect "http://www.trki.sk/clanok/blog_obsah/id/".$id_clanku

    header("Location: $redirect"); 
    exit(); 
    ?>
    no nothing aaaaaaaa ... but it was working in past... just when i updated version to 5.3 ... its supported?

  • #8
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Yes it is supported. Can you post your updated code?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #9
    Regular Coder
    Join Date
    Jan 2012
    Location
    Slovakia
    Posts
    111
    Thanks
    9
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php  

    session_start
    ();    

    require_once 
    './includes/functions.php';  

    connect();  

    $id_comment=clean_get_include($_GET['id_comment']);  
    $id_clanku=clean_get_include($_GET['id_clanku']);  

    $mysql_delete="DELETE FROM blog_comments WHERE id=$id_comment";  
    $mysql_query=mysql_query($mysql_delete);  



    $redirect "http://www.trki.sk/clanok/blog_obsah/id/".$id_clanku;  

    header("Location: $redirect");  
    exit();  
    ?>

  • #10
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Check for new entries in your error log, and maybe turn display_errors on.
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • #11
    Regular Coder
    Join Date
    Aug 2011
    Posts
    134
    Thanks
    20
    Thanked 0 Times in 0 Posts
    Try the following at the start and end of the script ans see...
    ob_start();
    ob_flush();

  • #12
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    To respond to your PM, you'll find your error log either in your public_html (www, web root) folder OR in another defined directory/place (or in the log directory in the php install itself, but this is unlikely if you're on shared hosting).

    Display_errors can be turned on in the php.ini
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • #13
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Add
    PHP Code:
    ini_set('display_errors','On');
    error_reporting(E_ALL); 
    Above session_start();
    That should start displaying errors if any.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #14
    Regular Coder
    Join Date
    Jan 2012
    Location
    Slovakia
    Posts
    111
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    Add
    PHP Code:
    ini_set('display_errors','On');
    error_reporting(E_ALL); 
    Above session_start();
    That should start displaying errors if any.
    i put just this into my file:

    PHP Code:
    <?php  
      
    ini_set
    ('display_errors','On');
    error_reporting(E_ALL);  

    header('Location: http://www.wtf.com');  
    exit();  
    ?>
    and


    Warning: Cannot modify header information - headers already sent by (output started at ...........functions.php:258) in blog_obsah_delete_comment.php on line 6

    the blog obsah delete cooment.php file is where we are trying use header command and on line 258 in functions.php is just " ?> " of the php file

  • #15
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    So somewhere you have whitespace - As I've mentioned in my topic.

    Anything that is in the file that is not inside <?php and ?> is output - including spaces, returns, tabs etc. This is called whitespace because its spaces that you can't see but they are still valid characters. A bit like the number zero, you can't see it but its a valid number.

    Check for whitespace, I reckon you've got it somewhere. Also when PHP suggests its the last line number what its really saying is that it's elsewhere.

    IF you really can't nail this then as I've suggested in my topic and as coding_begins has also said, use output buffering as a dirty hack.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •