Can't get http_redirect() to work

also, if user goes to just

photos.php

I want to redirect to

photos.php?pn=1

oh man… I don’t know…;-(

I know basic PHP but am not familiar with PHP server issues, like I am with Tomcat…

I have the basic apache setup that comes with the mac… it’s amazing, I don’t even have to turn on the server after rebooting my computer…:wink: (unlike Tomcat…)

Sorry about the htaccess blurb, I missed seeing your last two posts.

If the photo.php file is processing the requests, then it should be fairly easy to default to “pn=1” whenever the $_GET is non-existant or not a valid numeric.

Is it small enough to post a snippet of that file?

well, right now it’s very messy b/c am just testing and stuff…
but this is what it’ll be in “real” situation:

<html>
<head>
        <?php include('../../inc_header.php'); ?>
        </head>
        <body>
            <?php include('../../inc_main.php'); ?>
        </body>
        </html>
    
most of the processing will be in a file called common.php which will be an include in header.php....  main.php will contain output..   typical stuff:

 <?php 
     if (isset($_REQUEST['ss'])) { 
        if ($iPhNo === $iLastPhoto) { ?>
            <a class="ss" id="runSSAgain" href="photos.jsp?pn=1&ss=yes">run slide show again</a>
        <?php  } else { ?>
            <a class="ss" id="stopSlideShow" href="photos.jsp?pn=<?php echo $iPhNo; ?>">stop slide show</a>
        <?php  } 
 } 

?>

Ah, this now sounds more like a logic problem. Try adding more conditionals

<?php  if (isset($_REQUEST['ss'])) { 
if ( (isset($iPhNo)) && (ctype_digit($iPhNo)) && ($iPhNo === $iLastPhoto)) { ?>
    <a class="ss" id="runSSAgain" href="photos.jsp?pn=1&ss=yes">run slide show again</a>
<?php  } else if ( (isset($iPhNo)) && (ctype_digit($iPhNo)) && ($iPhNo <= $iLastPhoto) ){ ?>
    <a class="ss" id="stopSlideShow" href="photos.jsp?pn=<?php echo $iPhNo; ?>">stop slide show</a>
<?php  } else { // either no $iPhNo or it isn't a valid number ?>
    <a class="ss" id="runSSAgain" href="photos.jsp?pn=1&ss=yes">run slide show</a>
<?php }
  } else { ?>
    <a class="ss" id="runSSAgain" href="photos.jsp?pn=1&ss=yes">run slide show</a>
<?php }  ?>

The issets ensure

if user goes to just
photos.php
I want to redirect to
photos.php?pn=1

The ctype_digits ensure

say a user gets cute and wants to mess with with me and writes this in browser address bar:
…/photos.php?pn=dsjflsdjfds
in which case I want to redirect to
…/photos.php?pn=1

I don’t know if you’re wanting to account for if “ss” isn’t set, but that’s what the last else is for.

the “ss” (slideshow) code has nothing to do with the problem at hand, that was just an example of how I do output…

so, again: how do I redirect to photos.php?pn=1

from photos.php?

thank you…

The code snippet you posted does not involve any redirects, it outputs various links.
Please post the portion of the code dealing with the redirect logic.

if ( strpos($URL, 'photos.php') == true) {

        if ($queryStr != "" && strpos($URL,'tn') == true) {
            if ( $tn != 'pb')  {
            //    here need to redirect to ...../photos.php?tn=pb';
            }
        } else {
        //    if photo-no. param in query string does not check, go to photo 1
        //    if not at thumbnails pg and at photos.php  (thumbnails pg is photos.php?tn=pb)
            if ( strpos($URL,'tn') == false && strpos($URL, 'photos.php') == true) {
                if ($phNo.equals("")) {
                //    here need to redirect to ...../photos.php?pn=1';
                }
            } else {
                if (!checkPhotoNo($phNo, $iLastPhoto)) {
                    // etc...
                
                
            }
        }    
    }
            
}

thank you…

I guess the first thing to test is if raw redirects work.

Create a simple file named test.php (substituting your domain of course)

<?php
$tn_or_pn = $_GET['q'];
// void header ( string $string [, bool $replace = true [, int $http_response_code ]] )
if ($tn_or_pn === "tn") {
	header('Location: http://www.example.com/photos.php?tn=pb');
} else if ($tn_or_pn === "pn") {
	header('Location: http://www.example.com/photos.php?pn=1');
}
?>

and request it both
....test.php?q=tn
and
....test.php?q=pn

Do those redirects both work OK?

in both cases I get

The page isn’t redirecting properly

in FF and

This webpage has a redirect loop

in Chrome

thank you…

actually no… sorry…

in both cases it redirects to

…/test.php

(but get no errors…)

i.e., it stays on page, but query string is removed…

it does not redirect to photos.php…

thank you…

Ok, try this

<?php
$tn_or_pn = $_GET['q'];
// void header ( string $string [, bool $replace = true [, int $http_response_code ]] )
if ($tn_or_pn === "tn") {
	header('Location: http://www.example.com/photos.php?tn=pb');
} else if ($tn_or_pn === "pn") {
	header('Location: http://www.example.com/photos.php?pn=1');
} else {
	var_dump($_GET['q']);
}
?>

same thing…

(stays on test.php, removes query string), but get on page:

NULL

thank you…

NULL ???

Do you have an htaccess file that might be involved here?

hmmm…

I don’t know, but I don’t think so…

searched for “htaccess” in my PHP env…

'HD/Library/WebServer/Documents

found nothing…

thank you…

I don’t recognize that path. WAMP or an IDE?

what?

that’s where all my PHP files reside…

my photos “app” is here, /Library/WebServer/Documents/photos/

the root of it is requested thus in browser:

http://localhost/photos/

I understand that, what I was after is what your localhost server is. I have used a couple for Windows and none had a path like that.

I’m on a mac…

And what are you using as a localhost server?