Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Php header + javascript warning boxes

Options
  • 25-10-2007 4:28pm
    #1
    Registered Users Posts: 3,401 ✭✭✭


    Hi Lads,
    I'm getting an error about headers already sent and I know it's from using the javascript pop up combined with the php header function.
    Just wondering if it is possible to do the following in anyway?

    ... Note this is at the end of a php form
    <?php 
     print "<script>";
     print " alert(\"Your pictures will be approved within the next 24 hours.\");";
     print "</script>";
     header ("Location: http://www.ratemypub.ie/dublin/pubname/");
     exit();
    ?>
    

    I tried using the method below but because of mod_rewrite and the form it's directing to the
    http://www.ratemypub.ie/pub.php?pubid=....... page
    <?php 
     print "<script>";
     print " alert(\"Your pictures will be approved within the next 24 hours.\");";
     print " self.location='http://www.ratemypub.ie/$county/$pubnamelink/;";
     print "</script>";
    ?>
    


Comments

  • Registered Users Posts: 6,511 ✭✭✭daymobrew


    Can you elaborate on the process you want and maybe show a page where you'll be implementing it.
    If the person is submitting a photo, surely there is a page refresh when they click the 'Submit' button (unless it is ajax stuff).

    You could redirect to the appropriate page (or the target of the form would be the page) and put a note on the page about the approval time.


  • Registered Users Posts: 3,401 ✭✭✭randombar


    Sorry getting very bad at explaining myself these days!

    Basically I have a php page that uploads photos

    http://www.ratemypub.ie/dublin/peter's-pub/addpics/

    for example!

    and the form is embedded so the parameters are passed back to the page and after the pictures are uploaded I would like a pop up to appear saying please wait 24 hours and then the user clicks ok and is then directed back to

    http://www.ratemypub.ie/dublin/peter's-pub/

    something like that?

    I could put the note on the following page but I for one don't like too many pages on a site, so if I have one saying your photos will be uploaded then the user will have to make another click to go to the next page?


  • Registered Users Posts: 6,511 ✭✭✭daymobrew


    First some errors:
    - small typo: "result in the photo's being" - photo's -> photos.
    - error: http://www.ratemypub.ie/dublin/peter's-pub/ Should handle this gracefully.
    - On 'Top 5' list: http://www.ratemypub.ie/county.php?countyid=10 redirects to http://www.ratemypub/pub.php?pubid=272 (note loss of '.ie').
    - "If your pub isn't here, Add it by Clicking Here." - 'Clicking Here' is not good for SEO or accessibility.
    - Mapped location of Anglers Rest wrong: http://www.ratemypub.ie/pub.php?pubid=5635

    Ok, back to the issue.
    I wasn't thinking about adding new files.
    Just add code to pub.php to display a message about approval time.
    When the photos are submitted, redirect back to the pub page with an additional GET parameter e.g. http://www.ratemypub.ie/pub.php?pubid=5635&photossubmitted=1

    In pub.php
    if ( $GET['photossubmitted'] )
    echo '<p class="highlight">Your pictures will be approved within the next 24 hours.</p>';
    

    If you can redirect and add POST variables then you won't need a 'photossubmitted=1' parameter.
    A comment in header() suggests
    header("HTTP/1.0 307 Temporary redirect");
    header("Location: https://myserver.redcetus.com/otherlocation");
    


  • Registered Users Posts: 3,401 ✭✭✭randombar


    Jesus nice one for the help dymo!
    daymobrew wrote: »
    - small typo: "result in the photo's being" - photo's -> photos.

    Fixed, thanks!
    daymobrew wrote: »
    - error: http://www.ratemypub.ie/dublin/peter's-pub/ Should handle this gracefully.

    Ya I've to fix this and ampersands!
    daymobrew wrote: »

    Ya saw that this morning, I shouldnt be working on the live page much without checking it fully!
    daymobrew wrote: »
    - "If your pub isn't here, Add it by Clicking Here." - 'Clicking Here' is not good for SEO or accessibility.

    What is better for SEO?
    daymobrew wrote: »
    - Mapped location of Anglers Rest wrong: http://www.ratemypub.ie/pub.php?pubid=5635

    I've reset the mapping so the location is editable again!
    http://www.ratemypub.ie/pub.php?pubid=5635

    As for the problem I'm having I guess I'd like to try and avoid adding the get variables as this won't fit in with my new type of addressing.

    http://www.ratemypub.ie/county/pubname/

    so I would probably try the other method? I've tried running this code but a pop up is saying the page is redirecting and asking if I want to send the form information to the new page?
    header("Location: http://www.ratemypub.ie/message.php?id=1",TRUE,307);
    header("Location: http://www.ratemypub.ie/$countynamelink/$pubnamelink/");
    exit();
    


  • Registered Users Posts: 6,511 ✭✭✭daymobrew


    GaryCocs wrote: »
    What is better for SEO?
    Maybe something like "If your pub isn't here, help us by adding the pub to our site."
    GaryCocs wrote: »
    I've reset the mapping so the location is editable again!
    http://www.ratemypub.ie/pub.php?pubid=5635
    Fixed.
    GaryCocs wrote: »
    As for the problem I'm having I guess I'd like to try and avoid adding the get variables as this won't fit in with my new type of addressing.
    It shouldn't affect your SEO because spiders won't be submitting photos and seeing these 'GET' variables.
    GaryCocs wrote: »
    so I would probably try the other method? I've tried running this code but a pop up is saying the page is redirecting and asking if I want to send the form information to the new page?
    header("Location: http://www.ratemypub.ie/message.php?id=1",TRUE,307);
    header("Location: http://www.ratemypub.ie/$countynamelink/$pubnamelink/");
    exit();
    
    I can't picture this working. Do your tests with static pages to make it simpler.


  • Advertisement
Advertisement