Solved

Question For lozloz ONLY

Posted on 2003-12-01
5
231 Views
Last Modified: 2006-11-17
Hi again loz!

I have a script written in ASP that I use to display multiple pages of content with only one page....


http://www.mysite.com/index.asp?pg=home
http://www.mysite.com/index.asp?pg=terms

Here is the script I use:  <%ASP%>
<%
                                          action=Request.querystring("action")
      if action = "" then
                action = "home"
      end if

      Select Case action

                                                Case "home"
                                                      Server.Execute"content/home.asp"
                                                Case "services"
                                                      Server.Execute"content/home.asp"
                                                     Case "payments"
                                                      Server.Execute"content/home.asp"
                                                      Case "faq"
                                                      Server.Execute"content/home.asp"            
                        
Case else
End Select
%>

As I'm just beginning to learn PHP (and mind you it hasn't been as easy as I thought it would be) could you please give me a PHP example for converting this code?

Also, one other question I have is this....I reference all of my links by calling the value of the page I'm on (i.e., <a href="<%Request.ServerVariables("SCRIPT_NAME")%>?action=payments">).  The page the Request.ServerVariables will call is the index page.  Can you also give an example of that in PHP?

I hate to be soo much trouble, but I was very pleased with your help in my previous question.

Thanks in advance,

Trent
0
Comment
Question by:wkpreferredsolutions
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 13

Expert Comment

by:lozloz
ID: 9855269
hi there,

interesting what you say about php - i learnt php first and have found learning asp a lot harder than php.. maybe it's the 2nd language in the sequence which is harder. this should be quite easy to follow logically:

if(empty($_GET["action"])) { // if action = "" then
  $action = "home";
} else {
  $action = $_GET["action"]; // action=Request.querystring("action")
}
switch ($action){ // Select Case action
  case: "home"
    include("content/home.asp"); // Server.Execute"content/home.asp"
    break; // break is required otherwise all the cases below are executed as well unless another break is encountered
  case: "services"
    include("content/home.asp");
    break;
  case: "payments"
    include("content/home.asp");
    break;
  case: "faq"
    include("content/home.asp");
    break;
  // for a default case you want the following
  // default:
} // End Select

seems a bit strange wanting to include the same page for each action though so i assume you'll be changing this later

Request.ServerVariables in asp is equivalent to $_SERVER["SCRIPT_NAME"] but generally we use $_SERVER["PHP_SELF"] as this is a string containing the filename relative to the server's root

so for an example for your link - <?php print <a href=\"" . $_SERVER["PHP_SELF"] . "?action=payments\">Payments</a>"; ?>, or to be exact in the form of your code:

<a href="<? print $_SERVER["PHP_SELF"]; ?>"?action=payments">Payments</a>

good luck

loz
0
 

Author Comment

by:wkpreferredsolutions
ID: 9855694
Thanks for the quick reply loz!

I was always told that ASP was one of the harder languages to learn and PHP would be so much easier to learn after learning ASP!!!  I think I was lied to, :-)

The same include file was from a quick cut and paste in a script I was working on that I never finished.

I'm getting a parse error whenever the script reaches this line:

if(empty($_GET["action"])) { // if action = "" then
  $action = "home";
} else {
  $action = $_GET["action"]; // action=Request.querystring("action")
}
switch ($action){ // Select Case action
  case: "home" <=========================Parse Error On This Line

Trent
0
 
LVL 13

Accepted Solution

by:
lozloz earned 500 total points
ID: 9855729
sorry that's me being silly, all the cases should be in the following form:

case "home":

so:

switch ($action){ // Select Case action
  case "home" :
    include("content/home.asp"); // Server.Execute"content/home.asp"
    break; // break is required otherwise all the cases below are executed as well unless another break is encountered
  case "services":
    include("content/home.asp");
    break;
  case "payments":
    include("content/home.asp");
    break;
  case "faq":
    include("content/home.asp");
    break;
  // for a default case you want the following
  // default:
} // End Select

cheers,

loz
0
 

Author Comment

by:wkpreferredsolutions
ID: 9855734
Yep!  That fixed it!

Thanks again for the great answers!  Points are on the way!

Trent
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9855837
glad to help

loz
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

738 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