• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 513
  • Last Modified:

Need help with oscommerce template

Hello,
I have just purchased an OS commerce template that I need to customize into a website. I have already done the graphics, now its a matter of getting the behavior I want out of it. I have never programmed PHP ever, but do have a background in programming (JAva, C++) and experience in Web Dev (coldfusion). The first question I have is about how to construct the following if statement.
On the homepage of this oscommerce site there is a 3 image banner which is loaded on every page. I only want this to load on the homepage, to determine the homepage I want to be able to detect if the request was for index.php only (no query string) or whether or not index.php is called with a query string. If it is index.php and no query string show the banner, if there is a query string and its index.php do not show the banner.

What would this if statement look like?

Correct answer wortth 500 points.

Thanks,
Rick
0
richardsimnett
Asked:
richardsimnett
  • 8
  • 7
1 Solution
 
richardsimnettAuthor Commented:
just to clarify this is what I am looking for:

if (<it is only index.php with no query string>)
   insert this chunk of html.
else
   insert this chunk of html.

Thanks,
Rick
0
 
dr_dedoCommented:
i'm not familiar how oscommerce work, but if you have a page named index.php, then u can check in it if it has querysting or not (and no need to check it is index, as it will only run if index is called)

to check there is no querysting, try
if(!isset($_GET)){

} else{

}

not that you can use $_SERVER['REQUEST_URI'] to get the requested URL, but it would include querysting as well
so, try this
if ( $_SERVER['REQUEST_URI']=='/index.php'){

}
else{

}

if u r using some sort of mor_rewrite, then things would be a bit difficult to control, but for now, please post your feedback
0
 
richardsimnettAuthor Commented:
dr_dedo,
Ok I got the following error when I put in this code.

Parse error: parse error in E:\WHK\inetpub\vhosts\pcpluscorp.com\httpdocs\OSCommerceTemplate\osc\includes\header.php on line 153


Code Chunk:
<?
if ( $_SERVER['REQUEST_URI']=='/index.php'){
             <td><a href=<?=tep_href_link('product_info.php','products_id=110')?>><img src=images/m16.jpg width=172

height=219 border=0><img src=images/m17.jpg width=172 height=219 border=0><img src=images/m18.jpg width=174 height=219

border=0></a></td>
}
else{
<td></td>
}
?>

The error is probably due to my complete unfamiliarity with the language. Let me know.

Thanks,
Rick
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
dr_dedoCommented:
you can't use HTML inside PHP directly

consider this
<?
if ( $_SERVER['REQUEST_URI']=='/index.php'){
?>
             <td><a href=<?=tep_href_link('product_info.php','products_id=110')?>><img src=images/m16.jpg width=172
height=219 border=0><img src=images/m17.jpg width=172 height=219 border=0><img src=images/m18.jpg width=174 height=219
border=0></a></td>
<?
}
else{
echo "<td></td>";
}
?>

also, try to echo $_SERVER['REQUEST_URI'] to see what is going on (for debugging purpose)
0
 
richardsimnettAuthor Commented:
ok,
I think we've almost got it. I found an error in my logic that needs to be corrected. I didnt take into account the possible path settings for instance on the server the index is in <domain>/oscommercetemplate/osc/index.php.
This is causing it to never display the banner now. Instead of doing an exact match of /index.php  how would I cheeck to see if it is simply in the uri string?

After that check to see if it has a query string. If there is an index.php and no query string then display the banner, otherwise insert a blank cell.

Here is what I think the code needs to look like now without the exact match:

<?
if (($_SERVER['REQUEST_URI']=='/index.php') &&(!isset($_GET))){?>
          <td><a href=<?=tep_href_link('product_info.php','products_id=110')?>><img src=images/m16.jpg width=172 height=219

border=0><img src=images/m17.jpg width=172 height=219 border=0><img src=images/m18.jpg width=174 height=219

border=0></a></td>
<?
}
else{
echo "<td></td>";
}
?>
0
 
dr_dedoCommented:
$_SERVER['REQUEST_URI'] would print anything the user typed to get to your page
if user typed index/php?var1=sdsd&var2=eeee, then $_SERVER['REQUEST_URI'] will print index/php?var1=sdsd&var2=eeee

that's why you check only $_SERVER['REQUEST_URI']=='/index.php'

try
echo  $_SERVER['REQUEST_URI'];  to see what is actually going on
0
 
richardsimnettAuthor Commented:
Ok well its not echoing anything just blank.. heres the code I have.

<?
if (($_SERVER['REQUEST_URI']=='/index.php') &&(!isset($_GET))){?>
          <td><a href=<?=tep_href_link('product_info.php','products_id=110')?>><img src=images/m16.jpg width=172 height=219 border=0><img src=images/m17.jpg

width=172 height=219 border=0><img src=images/m18.jpg width=174 height=219 border=0></a></td>
<?
}
else{
echo "<td width=519 valign=top>";
}
?>
DEBUG:<? echo  $_SERVER['REQUEST_URI']; ?>


The complete url it is at is : http://www.pcpluscorp.com/OSCommerceTemplate/osc/index.php
0
 
dr_dedoCommented:
OK
try to echo this instead
$_SERVER['PHP_SELF']
0
 
richardsimnettAuthor Commented:
still nothing... just blank
0
 
dr_dedoCommented:
this is odd
lets test something, create a new php file, just a blank file and add these lines to it
<?
echo '$_SERVER['PHP_SELF']= '.$_SERVER['PHP_SELF'].'<br>';
echo '$_SERVER['REQUEST_URI']= '.$_SERVER['REQUEST_URI'].'<br>';
?>
name it anything, test.php for example
0
 
richardsimnettAuthor Commented:
it gives me this error:

Parse error: parse error, expecting `','' or `';'' in E:\WHK\inetpub\vhosts\pcpluscorp.com\httpdocs\OSCommerceTemplate\osc\test.php on line 2

Just a note... the code for what we are trying to do is somehow being included into the site I dont know if that makes a difference, but it actually resides in a file called header.php, which is included by another page in this case index.php, but it could be anything like cart.php, checkout.php etc.

Thanks,
Rick
0
 
dr_dedoCommented:
no, doesn't make a difference, what matters is the page being called, e.g. index.php

there was a typo in my code, sorry for that, try this in the test file and if worked, try it in your header file

<?
echo "\$_SERVER['PHP_SELF']= ".$_SERVER['PHP_SELF'].'<br>';
echo "\$_SERVER['REQUEST_URI']= ".$_SERVER['REQUEST_URI'].'<br>';
?>
0
 
richardsimnettAuthor Commented:
ok,
The code returns this (in the header file).

DEBUG: $_SERVER['PHP_SELF']= /OSCommerceTemplate/osc/index.php
$_SERVER['REQUEST_URI']=

So what I need to be able to do is check the string returned by the _SERVER['PHP_SELF']  for the existance of the substring index.php. I think that will do it.

Thanks,
Rick
0
 
richardsimnettAuthor Commented:
i've got it now.

Thanks for the help.
0
 
dr_dedoCommented:
no need to substinrg anything, use it as usch, if php_self is /OSCommerceTemplate/osc/index.php, then it is ok, else, do some other code
but you'll have to use if(!isset($_GET)) to exlcude andy querystring
glad you got it working
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 8
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now