toolman Posted January 18, 2011 Share Posted January 18, 2011 Hi there, I was wondering if there is a way to display content on only my index.php page? I believe there is a way and I have done it before, but some of my pages use index.php?category etc. Is there a way to show content just on index.php and not on any dynamic pages? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/224868-display-content-on-indexphp-and-not-on-indexphpdynamic/ Share on other sites More sharing options...
Psycho Posted January 18, 2011 Share Posted January 18, 2011 I was wondering if there is a way to display content on only my index.php page? I believe there is a way and I have done it before, but some of my pages use index.php?category etc. Well technically index.php?category is still the index.php page. In any case, you could checkif $_GET is set if(!isset($_GET)) { //No URL parameters set show index.php page content } else { //Some $_GET parameters are set, show appropirate content } Quote Link to comment https://forums.phpfreaks.com/topic/224868-display-content-on-indexphp-and-not-on-indexphpdynamic/#findComment-1161484 Share on other sites More sharing options...
AbraCadaver Posted January 18, 2011 Share Posted January 18, 2011 $_GET, $_POST etc. should always be set unless on CLI. Several ways, here are three: if(empty($_GET)) { // index.php } //or if(empty($_SERVER['QUERY_STRING'])) { // index.php } //or if($_SERVER["REQUEST_URI"] == $_SERVER["PHP_SELF"]) { // index.php } Quote Link to comment https://forums.phpfreaks.com/topic/224868-display-content-on-indexphp-and-not-on-indexphpdynamic/#findComment-1161485 Share on other sites More sharing options...
radi8 Posted January 18, 2011 Share Posted January 18, 2011 Well, a simple method is to use the index.php page as a director. You can have it load first and depending on conditions call other pages as needed. Here is an example: my index.php <?php include_once $_SERVER['DOCUMENT_ROOT'] . '\inc\magicquotes.inc.php'; include_once $_SERVER['DOCUMENT_ROOT'] . '/inc/base.inc.php'; include_once $_SERVER['DOCUMENT_ROOT'] . '/admin/export/excel-xml.php'; $frmErrorLevel=0; $frmErrMsg=''; /* if(isset($_POST['action']) && $_POST['action']=='submitted') { $carrierRatesdisabled=true; if(isset($_POST['ExportCarrier'])) { exportTruckingCompanies(); } if(isset($_POST['ExportDropFees'])) { exportDropFees(); } if(isset($_POST['ExportDomesticRates'])) { if(isset($_POST['Carrier_Name']) && $_POST['Carrier_Name'] == "0") { $frmErrorLevel=3; } else { exportDomesticRates($_POST[Carrier_Name]); } } if(isset($_POST['ExportCanadianRates'])) { exportCanadianRates(); } if(isset($_POST['ExportFuelSurcharge'])) { exportFuelCurchargeRates(); } } else { $carrierRatesdisabled=true; } */ // get the carrier recordset for the drop list $sql = 'SELECT * FROM `Carriers` order by `CarrierName`'; openRecordset($sql,$result, $link); if($result) { while ($row = mysqli_fetch_array($result)) { $carrierNames[] = array('id' => $row[0], 'name' => html($row[1])); } mysqli_free_result($result); close_mysql($link); } else $frmErrorLevel=1; switch($frmErrorLevel) { case 1: $frmErrMsg = 'Error retrieving Carrier Data'; break; case 2: $frmErrMsg = 'Error retrieving Drop Fee Data'; break; case 3: $frmErrMsg = 'Error retrieving Domestic Rates by Carrier, verify that a carrier is selected'; break; case 4: $frmErrMsg = 'Error retrieving Canadian Rate Data'; break; case 5: $frmErrMsg = 'Error retrieving Fuel Surcharge Rate Data'; break; default: $frmErrMsg = ''; break; } include 'form.html.php'; if (ob_get_length()){ @ob_flush(); @flush(); @ob_end_flush(); } exit(); ?> My form.html.php <?php session_start(); include_once $_SERVER['DOCUMENT_ROOT'] .'/inc/standardFunctions.inc.php'; //phpinfo(); $dodebug=2; if($dodebug > 0) { ini_set ("display_errors", "1"); //error_reporting(E_ALL); error_reporting(-1); echo "<pre>"; switch($dodebug) { case 1: echo "--> Form data (POST) <-- <br>"; print_r ($_POST); echo "--> Form data (GET) <-- <br>"; print_r ($_GET); break; case 2: echo "--> Form data (POST) <-- <br>"; print_r ($_POST); echo "--> Form data (GET) <-- <br>"; print_r ($_GET); echo "--> Form data (SESSION) <-- <br>"; print_r ($_SESSION); break; case 3: echo "--> Form data (POST) <-- <br>"; print_r ($_POST); echo "--> Form data (GET) <-- <br>"; print_r ($_GET); echo "--> Form data (SESSION) <-- <br>"; print_r ($_SESSION); echo "--> Form data (SERVER) <-- <br>"; print_r ($_SERVER); break; case 4: echo "--> PHP Info <-- <br>"; phpinfo(); default: echo "--> Form data (POST) <-- <br>"; print_r ($_POST); break; } echo "</pre>"; } else { ini_set ("display_errors", "0"); error_reporting(0); } ?> <!DOCTYPE html> <html lang="en"> <!-- <head> <meta charset="utf-8"> <title><?php htmlout($pagetitle); ?></title> </head> <body> <h1><?php htmlout($pagetitle); ?></h1> <form action="?<?php htmlout($action); ?>" method="post"> <table width="500" border="0"> --> <head> <meta charset="utf-8"> <title>Export Trucking Data</title> </head> <body> <h1>Export Data</h1> <form action="?addform" method="post"> <?php if($frmErrorLevel>0) { echo '<font color=#CC6600 size=+1>'.$frmErrMsg.'</font><br><br>'; } ?> <table width="650" border="0"> <caption> Data Export Options </caption> <tr> <td> <?php if($frmErrorLevel==1) print '<img src= ..\..\images\rdx.gif>'; else echo " "; ?> </td> <td width="275"><label>Carrier table data</label></td> <td width="100"><input name="ExportCarrier" type="submit" value="Submit"></td> <td> <div align="center"> </div></td> </tr> <tr> <td> <?php if($frmErrorLevel==2) print '<img src= ..\..\images\rdx.gif>'; else echo " "; ?> </td> <td><label>Drop Fees Table data</label></td> <td><input type="submit" name="ExportDropFees" value="Submit"></td> <td> <div align="center"> </div></td> </tr> <tr> <td> <?php if($frmErrorLevel==3) print '<img src= ..\..\images\rdx.gif>'; else echo " "; ?> </td> <td><label>Domestic Carrier Rates, by Carrier</label></td> <td><input type="submit" name="ExportDomesticRates" value="Submit"></td> <td> <div align="center"> <select name="Carrier Name" id="selectCarrier"> <option value="0">Select Carrier</option> <?php foreach ($carrierNames as $cn): ?> <option value="<?php htmlout($cn['id']); ?>"> <?php htmlout($cn['name']); ?> </option> <?php endforeach; unset($carrierNames); ?> </select> </div></td> </tr> <tr> <td> <?php if($frmErrorLevel==4) print '<img src= ..\..\images\rdx.gif>'; else echo " "; ?> </td> <td><label>Canadian Carrier Rates</label></td> <td><input type="submit" name="ExportCanadianRates" value="Submit"></td> <td> <div align="center"> </div></td> </tr> <tr> <td> <?php if($frmErrorLevel==5) print '<img src= ..\..\images\rdx.gif>'; else echo " "; ?> </td> <td><label>Export Fuel Surcharge Rate table data</label></td> <td><input type="submit" name="ExportFuelSurcharge" value="Submit"></td> <td> <div align="center"> </div></td> </tr> </table> <div> <input type="hidden" name="action" value="submitted" /> </div> </form> </body> </html> Notice that the index page processes all of the load and $_POST processes and at the end calls the single form.html.php page. It could be easily modified to call any number of separate pages, with full accessibility of index page variables on the page that was called. Quote Link to comment https://forums.phpfreaks.com/topic/224868-display-content-on-indexphp-and-not-on-indexphpdynamic/#findComment-1161502 Share on other sites More sharing options...
Psycho Posted January 18, 2011 Share Posted January 18, 2011 $_GET, $_POST etc. should always be set unless on CLI. Several ways, here are three: True, I forgot about that. You can also use count($_GET) Quote Link to comment https://forums.phpfreaks.com/topic/224868-display-content-on-indexphp-and-not-on-indexphpdynamic/#findComment-1161506 Share on other sites More sharing options...
QuickOldCar Posted January 18, 2011 Share Posted January 18, 2011 I guess is many ways to do this. <?php $url = filter_var("http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING); if (!empty($_SERVER["QUERY_STRING"])){ $query_string = filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_STRING); $url .= "?".$query_string; } echo "<a href='$url'>$url</a><br />"; if (empty($_SERVER["QUERY_STRING"])){ echo "Showing index.php"; } else { echo "Showing everything"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/224868-display-content-on-indexphp-and-not-on-indexphpdynamic/#findComment-1161527 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.