PHP - Post On A Page Load
When a person visits my site I would like for the form on the page to submit and reload with the predetermined search criteria. Is this possible?
So for example...if you visited my site as soon as you entered the from would submit and display Google search results for "php freaks" I tried header("location: mysite.com?q=php+freaks"); but that is a continuous loop. -Any thoughts Similar TutorialsI'm having a problem and need an answer to why its happening and how to prevent it. Scenario: I begin load my home page which starts with a session_start(); .... Before it FULLY completes loading I try to navigate to another page and BOOM, that page will not load and any other page that begins with session_start(); will not load unless I close and restart the entire browser or wait about 10 minutes.... I will note my website makes ajax calls every 5 seconds or so, but I use setTimeout for them. Any help??? Thanks ahead! Some code from my pages ,
Page1 ( Redirecting page )
<html> <title>login_redirect.</title> body> <form name="redirect" action="http://mysite/page2.php" method="post"> <input type="hidden" name="mac" value="$(mac)"> </form> <script language="JavaScript"> <!-- document.redirect.submit(); //--> </script> </body> </html>Page 2 ( select product ) <?php session_start(); ini_set('display_errors',1); error_reporting(E_ALL); include '../lib/config.php'; include '../lib/opendb.php'; // get user mac adres from redirect post page1 $_SESSION['macid'] = $_POST['mac']; // set $macid for other use ( maybe not needed, am learning ) $macid = $_SESSION['macid']; // echo $macid does show mac adress, so variable is not empty here if (!empty($_POST["submit"])) { $product_choice = $_POST['accounttype']; $query= "SELECT AccountIndex, AccountCost, AccountName FROM AccountTypes WHERE AccountIndex='$product_choice'"; $result = mysql_query($query) or die('Query failed. ' . mysql_error()); while($row = mysql_fetch_array($result)) { $_SESSION['AccountIndex'] = $row['AccountIndex']; $_SESSION['AccountCost'] = $row['AccountCost']; $_SESSION['AccountName'] = $row['AccountName']; } header('Location: page3.php'); } // did leave out the other/html/form stuff herePage 3 ( show Session variables ) <?php ini_set('display_errors',1); error_reporting(E_ALL); session_start(); print_r($_SESSION); ?>Now, on page 3 i do see the right session varables, only the "macid" is empty. why ? I have a page with results from a query that displays that has a link (works fine - passes variables etc) that deletes that line item from a database. It goes to the delete.php and actually executes and removes the item from the database and then has the line header("Location: page.php"); which returns BACK to the page displaying the results. However, it shows the old results until I hit Refresh in the browser. Its like the header is redirecting to a cached version of the page.
NOTE: This script used to work fine untouched when we where on a shared hosting account. We JUST updates to VPS hosting by the same host. Now this problem has risen and I can't figure out what is wrong. From what I can guess is there is something in php.ini that is either not set, set or set wrong. Any help would be greatly appreciated.
Thanks.
Hello frnds, Im new in ur forum....I want to know that my one page is taking too much time to load....in that page no images exists..but on that page around 6000 records are loding from database....I m confuse that may be such a large records it is taking too much time...so will u help me out that what can i do so the page can be loaded quickly with these records.... this is urgent for me.....pls pls pls....give me solution soon Thnx a lot in advance hello, i want to get into a particular page if the user stays more than lets say 20 minutes to automatically load another php page. More specific i have a page which is a test. The user answears to some multiple choice questions. i want him to have only a particular time to anwear. Lets say after 20 min i want to load the results page. Any ideas? I have a page that processes a variable passed in the url to go get information out of a text file in JSON format. For some reason though, passing one variable loads a page, passing a certain variable (who's data in the file is virtually identical to the first) will cause the browser to just load the page indefinitely. Maybe even more strange is that on my local machine, the variable that won't load is switched, and the other loads fine. How can I debug what's happening when the page never loads so that I never get an error? Hi! I am looking for a script that counts how many queries is executed on page load? I hadn't realised one of my scripts was doing hundreds of queries simultaneously and never would of thought this would be the cause of high load. As I'm developing stuff in PHP, I want to ensure minimum queries are executed especially because I am doing this in a procedural manner and not OOP. Thanks in advance. Hi, I've been wondering if it is possible to load a php page according to certain time. For example at 12:00 pm a php form will pop up automatically informing an employee to fill in something in the form, another form will pop up at 4:00 pm, etc... Thanks in advance Hey, I need to generate a script which tells me how long it takes for an external page to load... Please can you help? Thanks I'm trying to block access to a particular page if the visitor is not from a specific country (using Maxmind Geoip Country database), but not quite sure how to code this properly: I tried this and many variations of this inside the head tags, bud doesn't work. Any suggestions on the best way to go about this? Code: [Select] <?php require_once("geoip.inc"); $gi = geoip_open("/home/username/GeoIP.dat",GEOIP_STANDARD); $country_code = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']); geoip_close($gi); if($country_code !== 'US') header("HTTP/1.0 404 Not Found"); exit; ?> can someone please help me with this I'm trying to make it so that when the page loads just the condition below will happend unless the if statment happends. so I need two if statments that work off of one condition? so i was thinking of using OR but i would need a if statement that says the page is being loaded what this code does it displays someones profile when search is hit but i want it to display the persons own profile soon as the page is loaded first Code: [Select] <?php if(isset($_POST['search'])) { // searches goaulds then displays them $search3 = "SELECT goauld,id FROM users WHERE goauld='".mysql_real_escape_string($_POST['goaulds'])."'"; $search2 = mysql_query($search3) or die(mysql_error()); WHILE($search1 = mysql_fetch_array($search2)){ $grab_goauld = $search1['goauld']; echo '<table width="300" height="5" border="1" align="center">'; echo '<th><center>Goauld Statistics</center></th>'; echo "<tr><td height='340'>$grab_goauld</td></tr>"; } } echo '</table>'; ?> Hi,
I am trying to make a page where the footer is loaded according to the screen size, so if someone is accessing the website via a tablet will be a footer, if it is from the computer, there will be another footer.
my problem is that although it is recognizing the windows width, it is not changing the footer accordingly.
this is my code:
$width = "<script>document.write(window.innerWidth);</script>"; if ($width < 900) { include("footer_mobile.php"); } else { include("footer.php"); }for some reason it is always loading the else footer even though the windows with changes. I added echo"$width" ; and the result of the variable was fine. does anyone know what the problem is cause it is driving me crazy? Hi, I have a div which reloads every 10 seconds but I want it so that if it equals something then redirect the whole page when at the moment it just loads the whole page in in the div but need the div as it stores all my variables, anyone know of anything else I can use? Thanks Is there some way of a php include which is visible on every page (footer), itself having two php includes, but only one of which would be visible, then on the user refreshing the page or on visiting another page on the site, that include would be replaced with another php include? Preferably done without any js. Any help appreciated. Chris So I have a page that has profile images basically, but these images cache and when someone clicks on anything, like rotate image, since my script rotates the image and saves it correctly, I can hit Ctrl+F5 and the image then shows up correct, but the page loading itself after running my script using a get method and then using the header coming back to the same page the image looks like it wasn't reloaded. Noones gonna hit Ctrl+F5, so how do I get this to cache the image completely when the page reloads? I've tried <meta http-equiv="pragma" content="no-cache" /> But this doesn't work, well nothing seems to work really. I am creating a stream page that updates automatically without the page reloading by reloading a div on the page using a timer. However, I only want it to run the update and fade in/fade out when there is a new status in the table. I tried doing it through PHP getting the number of rows in the table on the page itself and then checking the number of rows on an action page, however, the number of rows didnt update when the div was reloaded. I then tried doing it using jquery/javscript but had the same problem. How can I acheive this? Thanks in advance hi! i dont know if the query below from mysql is slowing down the page or i have not written it properly: It is very slow, even when you limit the results to 100 . Thanks in advance.. Code: [Select] SELECT `tbl_business`.`appformno`, " _ & "`tbl_business`.`pobox`, `tbl_business`.`plotno`, `tbl_business`.`postalcode`, " _ & "`tbl_business`.`zonecode`, `tbl_business`.`ne`, `tbl_activities`.`act_code`, " _ & "`tbl_activity_codes`.`approved_fee`, `tbl_payment_status`.`status`, " _ & "`tbl_business`.`company`, `tbl_activity_codes`.`description` " _ & "FROM (`citycouncil`.`tbl_activity_codes` `tbl_activity_codes` " _ & "LEFT JOIN (`citycouncil`.`tbl_business` `tbl_business` " _ & "LEFT JOIN `citycouncil`.`tbl_activities` `tbl_activities` " _ & "ON `tbl_business`.`appformno`=`tbl_activities`.`appformno`) " _ & "ON `tbl_activity_codes`.`act_code`=`tbl_activities`.`act_code`) " _ & "LEFT JOIN `citycouncil`.`tbl_payment_status` `tbl_payment_status` " _ & "ON `tbl_activities`.`id`=`tbl_payment_status`.`activity_id` " _ & "WHERE tbl_business.appformno LIKE '%" & strFormNo & "%' " _ & "AND tbl_business.bid LIKE '%" & strBizIdNo & "%'" _ & " AND `tbl_business`.`contperson` LIKE '%" & strContPerson & "%' " _ & "AND `tbl_business`.`zonecode` LIKE '%" & strZoneCode & "%' " _ & " AND `tbl_activities`.`act_code` LIKE '%" & strBizActCode & "%' " _ & "AND `tbl_business`.`roadstreet` LIKE '%" & strStreet & "%' " _ & " AND `tbl_business`.`company` LIKE '%" & strBizName & "%' " _ & "AND `tbl_business`.`building` LIKE '%" & strBuilding & "%' " _ & "ORDER BY `tbl_business`.`appformno` Hello All,
I have been going crazy trying to figure this out, I hope someone can help me out
I have header and footer.php files that on all my pages I get them to load with include,
but for some strange reason, this certain page it will not load I did some research and apparently theres problems with div and php, does anyone know how to make this work?
Thank you in advance,
Elaine
Attached Files
test.txt 4.81KB
7 downloads lets say I have two pages: Code: [Select] one.php Code: [Select] two.php Now with that in mind, is there a way for page one.phpto automatically post values to page two.php viathe $_POST variable? I want my form to POST to the same page, but not have the 'document expired' problem when sessions are being used somewhere in the script (when I hit press the back button in the browser). I know this can be avoided by posting to a different PHP page, and then use a header(location) to redirect, but I ideally want to keep it on the same page as I use some of the variables produced from within the processing section.
Please excuse the crude examples,
This works:
session_start(); /*HEADER*/ if(isset($_POST['test']){ //do some validation $validated= true; if($validated){ //process the form $_SESSION['notification'] = 'form submitted successfully'; header('location: samepage.php'); exit; } else{ $_SESSION['notification'] = 'there was an error'; header('location: samepage.php'); exit; } } /*BODY*/ if(!isset($_SESSION['notification'])){ //show the form.. posts 'test' to current page } else { echo $_SESSION['notification']; unset($_SESSION['notification']); }And this method shows the document expired when the page is refreshed... session_start(); /*HEADER*/ if(isset($_POST['test']){ //do some validation $validated= true; if($validated){ //process the form $success = true; } else{ $success = false; } } /*BODY*/ if(!isset($success)){ //show the form.. posts 'test' to current page } else if($success){ echo 'form submitted successfully'; } else{ echo 'there was an error'; }I've read that I can edit the php.ini file to allow caching, which should solve the issue for example 2. Is example 1 the correct way to be doing this? It's been pointed out that I shouldn't be using 'exit' so much so I'm trying to explore the correct methods Edited by paddy_fields, 31 July 2014 - 07:04 AM. |