Solved

Another hopefull easy php question

Posted on 2008-06-23
12
186 Views
Last Modified: 2008-11-21
I got , with help, the "next.gif" images  in this script to show up but the "here.gif" and "prev.gif" don't display.

Here's what I see when I click source

<a href="_1.php"><img src="http://www.mybelovedangels.com/images/next.gif" alt="1" border="0"></a><a href="_2.php"><img src="http://www.mybelovedangels.com/images/next.gif" alt="2" border="0"></a><a href="_3.php"><img src="http://www.mybelovedangels.com/images/next.gif" alt="3" border="0"></a><a href="_4.php"><img src="http://www.mybelovedangels.com/images/next.gif" alt="4" border="0"></a><a href="_5.php"><img src="http://www.mybelovedangels.com/images/next.gif" alt="5" border="0"></a>
:
Heres the code I'm trying to get to work (it does change pages):
 
<?php

//This script is created by Reptilian Feline

//www.reptilian-feline.net

//If you use it, please link to my site

$full_path = getenv("REQUEST_URI");

//put the base URL in case you need it

$base = "http://www.mybelovedangels.com/catalog/main-log/";

//Get the name of the file

$page_file = basename($full_path);

//The files are named file_1.php, file_2.php, etc. Extract number from it.

$page_num = substr($page_file

, strrpos($page_file, "_") + 1

, strpos($page_file, ".php") - strrpos($page_file, "_") - 1

);

$partial_path = substr($page_file, 0, strrpos($page_file, "_"));

//Build array of pagenumbers. Here are ten pages.

$all_pages = array (1,2,3,4,5);
 

foreach ($all_pages as $all_page)

{

//Create link to all the previus pages and put in prev-image.

if ($all_page < $page_num) 

{

print "<a href=\"$partial_path"."_". $all_page . ".php\"><img src=\"http://www.mybelovedangels.com/images/prev.gif\" alt=\"$all_page\" border=\"0\"></a>";

}

//Create I-am-here-image.

elseif ($all_page == $page_num) 

{

print "<img src=\"http://www.mybelovedangels.com/images/here.gif\" alt=\"$page_num\" border=\"0\">";

}

//Create links to all the next pages and put in next-image.

else 

{

print "<a href=\"$partial_path"."_" . $all_page . ".php\"><img src=\"http://www.mybelovedangels.com/images/next.gif\" alt=\"$all_page\" border=\"0\"></a>";

}

}

?>

Open in new window

0
Comment
Question by:Freejoy
  • 7
  • 2
12 Comments
 

Author Comment

by:Freejoy
Comment Utility
By the way just in case it matters I changed the following in the above code:

[code]
$base = "http://subomain.domain.ext";
[/code]

to:

[code]

$base = "http://www.mybelovedangels.com/catalog/main-log/";
[/code]

Thanks

0
 
LVL 1

Expert Comment

by:binarydesignnz
Comment Utility
The image links are still pointing to "http://www.mybelovedangels.com/catalog/main-log/images/next.gif" where they should be "http://www.mybelovedangels.com/images/next.gif"

May I ask, why are you using graphics for this when you could just use &lt, X and &gt ?  This may simplify things?
0
 

Author Comment

by:Freejoy
Comment Utility
I'm just trying to get it going correctly so I was trying to follow the directions.

my images are at: mybelovedangels.com/images.gif

these pages are in: mybelovedangels.com/catalog/main-log/_2.php

I mention this because i changed:
$base = "http://www.mybelovedangels.com/catalog/main-log/";

to:
$base = "http://www.mybelovedangels.com/";
it had no effect

I kinda like using the images a little because after it's going I could change the images to something neat....maybe.  They hardly weigh anything.


0
 

Author Comment

by:Freejoy
Comment Utility
Oh yea, the thing is the "next.gif" images are working.  It the other two that aren't
0
 
LVL 4

Expert Comment

by:trippy1976
Comment Utility
Well, I think you are not parsing $page_num correctly.  What is the output from that?  Have you printed it to see what it is?

The only part of your if statement ever triggering is "else" so $all_page is

- either always larger than and not equal to what you are getting in $page_num
- $page_num is not right... probably not a number.  Either you're getting some other character in it or you may need to do some kind of "intval" cast from string to a number.

I think your substr call is fubared.  those can be tricky
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:Freejoy
Comment Utility
I kinda see what your saying.  

So what's the solution to get it working correctly?(smile)

Like the bad guy on "Die Hard" said,  "Give me the code!"

 
0
 
LVL 4

Accepted Solution

by:
trippy1976 earned 500 total points
Comment Utility
I'd have to be running your script inside your environment.

Put this code after the line you set $page_num on:

die($page_file . " :: " .  $page_num)

Then cut/paste that output here so I can see it.  Then you will be sure to know what is in both variables, which will be very helpful to you.

I think you are going to want to do something like

$substStart = strrpos($page_file, "_");
$substEnd = len($page_file) - $strrpos($page_file, ".php");
$page_num = substr($pagefile, $substStart, $substEnd);

You might need to add 1 to the start variable.  But that will be pretty close.
$substStart = strrpos($page_file, "_");

$substEnd = len($page_file) - $strrpos($page_file, ".php");

$page_num = substr($pagefile, $substStart, $substEnd);

Open in new window

0
 

Author Comment

by:Freejoy
Comment Utility
OK I'm on it!

But what do/did you mean by,  "Have you printed it to see what it is?"
0
 

Author Comment

by:Freejoy
Comment Utility
I added the code exactly like below and when I went to open the page I get this:

PHP Parse error: syntax error, unexpected T_VARIABLE in D:\hshome\freejoy\mybelovedangels.com\catalog\main-log\_4.php on line 899


Here's  how I  changed the code so far, I just added the one line:
<?php

//This script is created by Reptilian Feline

//www.reptilian-feline.net

//If you use it, please link to my site

$full_path = getenv("REQUEST_URI");

//put the base URL in case you need it

$base = "http://www.mybelovedangels.com/";

//Get the name of the file

$page_file = basename($full_path);

//The files are named file_1.php, file_2.php, etc. Extract number from it.

$page_num = substr($page_file

, strrpos($page_file, "_") + 1

, strpos($page_file, ".php") - strrpos($page_file, "_") - 1

);

die($page_file . " :: " .  $page_num) 
 

$partial_path = substr($page_file, 0, strrpos($page_file, "_"));

//Build array of pagenumbers. Here are ten pages.

$all_pages = array (1,2,3,4,5);
 

foreach ($all_pages as $all_page)

{

//Create link to all the previus pages and put in prev-image.

if ($all_page < $page_num) 

{

print "<a href=\"$partial_path"."_". $all_page . ".php\"><img src=\"http://www.mybelovedangels.com/images/prev.gif\" alt=\"$all_page\" border=\"0\"></a>";

}

//Create I-am-here-image.

elseif ($all_page == $page_num) 

{

print "<img src=\"http://www.mybelovedangels.com/images/here.gif\" alt=\"$page_num\" border=\"0\">";

}

//Create links to all the next pages and put in next-image.

else 

{

print "<a href=\"$partial_path"."_" . $all_page . ".php\"><img src=\"http://www.mybelovedangels.com/images/next.gif\" alt=\"$all_page\" border=\"0\"></a>";

}

}

?>

Open in new window

0
 

Author Comment

by:Freejoy
Comment Utility
Here's how I finally added your  code

On line 905 I get a PHP Parse error: syntax error, unexpected T_VARIABLE .  That's this line:

 $partial_path = substr($page_file, 0, strrpos($page_file, "_"));

Here's the complete code how I've got it together so far.
<?php

//This script is created by Reptilian Feline

//www.reptilian-feline.net

//If you use it, please link to my site

$full_path = getenv("REQUEST_URI");

//put the base URL in case you need it

$base = "http://www.mybelovedangels.com/catalog/main-log/";

//Get the name of the file

$page_file = basename($full_path);

//The files are named file_1.php, file_2.php, etc. Extract number from it.
 

$substStart = strrpos($page_file, "_");

$substEnd = len($page_file) - $strrpos($page_file, ".php");

$page_num = substr($pagefile, $substStart, $substEnd);
 
 
 

die($page_file . " :: " .  $page_num) 
 
 
 
 

$partial_path = substr($page_file, 0, strrpos($page_file, "_"));

//Build array of pagenumbers. Here are ten pages.

$all_pages = array (1,2,3,4,5);
 

foreach ($all_pages as $all_page)

{

//Create link to all the previus pages and put in prev-image.

if ($all_page < $page_num) 

{

print "<a href=\"$partial_path"."_". $all_page . ".php\"><img src=\"http://www.mybelovedangels.com/images/prev.gif\" alt=\"$all_page\" border=\"0\"></a>";

}

//Create I-am-here-image.

elseif ($all_page == $page_num) 

{

print "<img src=\"http://www.mybelovedangels.com/images/here.gif\" alt=\"$page_num\" border=\"0\">";

}

//Create links to all the next pages and put in next-image.

else 

{

print "<a href=\"$partial_path"."_" . $all_page . ".php\"><img src=\"http://www.mybelovedangels.com/images/next.gif\" alt=\"$all_page\" border=\"0\"></a>";

}

}

?>

Open in new window

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now