PHP - How To Make A Redirect Like This
Hi I had it on my old site but forgot what I put in the index.php file.
Basicly, I want something like this: http://site.com/index.php?go=home or: http://site.com/index.php?home Does anyone know what I put in the index.php file to specify link and where it redirects too? Thank you. Similar TutorialsI have a paypal shopping cart form. Right now the form submits to paypals normal site and works fine. But the problem is the user can use firebug and change the price before sending to paypal. So i want the form to submit to my php script, where ill whatever is in the session, not what was posted, create an NVP string from that post, then POST that to paypal. I thought i could do this with cURL, but cURL always responds, it never actually takes the user to paypal with post. Is there a way to mimic what a form submit does completely in PHP? Hey guys, i always get the error: Warning: Cannot modify header information - headers already sent by (output started at /home/worldw44/public_html/Newsletter/Admin/Admin.php:1) in /home/worldw44/public_html/Newsletter/Admin/Admin.php on line 6 when im tyring to run: <?php if(isset($_SESSION['adminlogin'])) { $run=yes; } else { header( 'Location: http://www.worldwidelighthouses.com/Newsletter/Admin/Log-In.php'); }?> <!DOCTYPE HTML> <html lang="en-GB"> <head> <meta charset="utf-8"> <!--Search Engine Meta Tags--> <meta name="author" content="Worldwide Lighthouses"> <meta name="keywords" content="Lighthouses,Lightships,Trinity House,Fog Signals,Fog Horns,Fresnel"> <meta name="description" content="Worldwide Lighthouses is the number 1 source of information, pictures and videos on the Subject of Lighthouses and Lightships"> <!--Stylesheets/Javascript--> <link rel="stylesheet" href="../../Page-Layout.css" media="screen and (min-width: 481px)"> <link rel="stylesheet" href="../../Mobile-Page-Layout.css" media="only screen and (max-width:480px)"> <!--Mobile Browser Support--> <meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"> <!--IE Support--> <!--[if lt IE 9]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <link rel="stylesheet" href="../Page-Layout.css"><![endif]--> <meta name="application-name" content="Worldwide Lighthouses"> <meta name="msapplication-starturl" content="http://worldwidelighthouses.com/"> <meta name="msapplication-tooltip" content="Worldwide Lighthouses: Your number one source of Lighthouse Information, Videos and Pictures"> <meta name="msapplication-task" content="name=Lighthouses;action-uri=http://worldwidelighthouses.com/Lighthouses.php;icon-uri=http://worldwidelighthouses.com/IE9/Lighthouses.ico"> <meta name="msapplication-task" content="name=Lightships;action-uri=http://worldwidelighthouses.com/Lightships.php;icon-uri=http://worldwidelighthouses.com/IE9/Lightships.ico"> <meta name="msapplication-task" content="name=Fog Signals;action-uri=http://worldwidelighthouses.com/Fog-Signals.php;icon-uri=http://worldwidelighthouses.com/IE9/Fog-Signals.ico"> <meta name="msapplication-task" content="name=Glossary;action-uri=http://worldwidelighthouses.com/Glossary.php;icon-uri=http://worldwidelighthouses.com/IE9/Glossary.ico"> <title>Mailing List Administration | Worldwide Lighthouses</title> </head> <body> <header> <h1 id="WWLH">Worldwide Lighthouses</h1> <form method="get" action="http://www.worldwidelighthouses.com/Search/search.php" id="Search-Box"> <input type="search" placeholder="Search Worldwide Lighthouses" name="query" id="query" size="30" value="" autocomplete="off"> <input type="submit" value="Search"> <input type="hidden" name="search" value="1"> </form> </header> <nav> <ul id="Nav"> <li class="MenuButton" id="Index"><a href="../Index.php"><p class="Nav">Home</p></a></li> <li class="MenuButton" id="Lighthouses"><a href="../Lighthouses.php"><p class="Nav">Lighthouses</p></a></li> <li class="MenuButton" id="Lightships"><a href="../Lightships.php"><p class="Nav">Lightships</p></a></li> <li class="MenuButton" id="FogSignals"><a href="../Fog-Signals.php"><p class="Nav">Fog Signals</p></a></li> <li class="MenuButton" id="Daymarks"><a href="../Daymarks.php"><p class="Nav">Daymarks</p></a></li> <li class="MenuButton" id="Buoys"><a href="../Buoys.php"><p class="Nav">Buoys</p></a></li> <li id="MenuButtonLast"><a href="../Glossary.php"><p class="Nav">Glossary</p></a></li> </ul> </nav> <article> <h1 class="Title">Contact Admin Centre</h1> <div class="Textbox"> <div id="Social"> <a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-via="WWlighthouses">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script> <object id="Facebook" data="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fworldwidelighthouses.com/&layout=button_count&show_faces=false&width=450&action=like&colorscheme=light&height=21"></object> </div> </div> </article> <footer> <ul> <li><a href="../About.php">About</a></li> <li><a href="../Contact-us.php">Contact</a></li> <li><a href="../Use-Our-Media.php">Use our media</a></li> <li><a href="../Search/search.php">Search</a></li> <li><a href="../Social-Networking.php">Social</a></li> <li><a href="#Top">Back to top</a></li> </ul> <br> <br> &#169; Worldwide Lighthouses <?php echo date("Y"); ?> </footer> </body> Cany anyone offer some suggestions as to why? Note i have no ability to change phpconfig. I'm trying to put together a script that redirects visitors based on their IP, user agent and/or referral url. Basically I want the script to scan these three factors from the visitor, if any of them turn out to match my redirect-requirement it redirects the user. I know the code is horribly coded, I'm incredibly new to the php-scene and consider myself a complete noob. As you can see I want redirected visitors to go to google.com and un-redirected to msn.com(examples). Really thankful for all the help I can get! Right now nothing works, any suggestions? <?php function redirect($page) { Header( "HTTP/1.1 301 Moved Permanently" ); header('Location: ' . $page); exit; } $referrals=array('pitchingit.org','referral2'); $badAgents = array("useragent1", "useragent2"); $deny = array("78.105.191..*","100.101.103..*"); if (in_array($_SERVER['HTTP_REFERER'], $referrals, FALSE)) { header("Location: http://www.google.com"); } else { header("Location: http://www.msn.com"); } if(in_array($_SERVER['HTTP_USER_AGENT'],$badAgents)) { redirect("http://www.google.com/"); exit(); } $add=$_SERVER['REMOTE_ADDR']; foreach ($deny as $ip) { if (preg_match("^.$add.*^",$ip)) { redirect("http://www.google.com"); } } redirect("http://www.msn.com"); ?> How can one re-direct a visitor, without using a header re-direct? I'd like a page to show up, then after about 5 seconds I need the visitor sent to another page. How can I do this? Okay so my news script is set to view only 10 pieces of news. But I want it so that it starts a new page once I have more than 10 pieces of news. Code: [Select] <?php require("functions.php"); include("dbconnect.php"); session_start(); head1(); body1(); new_temp(); sotw(); navbar(); $start = 0; $display = 10; $query = "SELECT * FROM news ORDER BY id DESC LIMIT $start, $display"; $result = mysql_query( $query ); if ($result) { while( $row = @mysql_fetch_array( $result, MYSQL_ASSOC ) ) { news_box( $row['news'], $row['title'], $row['user'], $row['date'], $row['id'] ); } mysql_free_result($result); } else { news_box( 'Could not retrieve news entries!', 'Error', 'Error', 'Error'); } footer(); mysql_close($link); ?> I tried a few things but they failed....miserably. $looponce = 1; foreach ($this->info as $k => $v) { if ( (($k == 'subject') && ($v['required'])) && (!$this->settings['customSubject'])) { for ($i = 0; $i <= 0; $i++) { $output[] = $this->display_errors('error_system_subject'); } } if ( (($k == 'name') && (!$v['required'])) || ((!array_key_exists("name", $this->info)) && ($looponce == 1)) ) { $output[] = $this->display_errors('error_system_name'); $looponce++; } } That is my loop that i check things in. What i'm more interested in is the name if statement. If currently checks for a name key in an array(below) and makes sure that it is set to required. If it's not set to required, print out a system error and die()'s. I'm looking for ways to remove the need for program errors and just change them to what is needed to run. What i know how to do is, get into the inner array, what i don't know is how to edit the data and put it back exactly as it was given to me. The inner array data can be put back in any order, but the outer array must be in exact order as it was given. above code $this->info = $formdata; $formdata = array( 'name' => array('name'=>"Full Name", 'required'=>false, 'type'=>'text'), # This needs to be required=>true, but i can't trust the user, which is why i have the error. 'telephone' => array('name'=>"Telephone", 'required'=>false, 'type'=>'phone'), ); Any help is greatly appreciated, also am i doing the foreach loop in the code above in an efficient manner or is there another way? Hi there, As the question says i tried several things but i can't work it out and my knowledge about php isn't that well. maybe a silly question, but when somebody visits my site i.e. domain.com i want it to redirect them to www.domain.com example can be seen @ facebook.com <?php $get = fetch("SELECT number FROM dom") if "$get = 1" echo "<meta http-equiv='refresh' content='0;url=http://toxicpets.co.uk/down_for_maitenence.php'>"; elseif "$get = 0" echo "<meta http-equiv='refresh' content='0;url=http://toxicpets.co.uk/index.php'>"; ?> is this code right??? Can someone tell me how to fix this At the top of every page i have this. Code: [Select] <?php include('GiveAway_Control.php');?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> in the GiveAway_Control.php there is the Code: [Select] header("Location: http://www.domain.com/winner.html"); /* Redirect browser */ The GiveAway_Control.php has NO echo statements what so ever. Hi,
Can someone tell me what this redirect will do?
RewriteCond %{HTTP_HOST} ^(www\.)?website\.com/microsite$Thanks! Hi, I'm trying to figure out if I can get a redirect page to work, without needing to use the header("Location: page.php"); command. I know with asp, there is a response.redirect for redirecting pages, but, with the header, I can only use this, if there is no output before calling the command. Is there any method that can be used where I can process some code, if output is required, and depending on processing on the page, redirect it to another page, using a command similar to response.redirect? I have seen the http_redirect, but I can only see this working with clearing buffers etc. I have also a redirect_to("page.php"); command, but I cannot get this to work. I am using php 5. Any help would be appreciated. Thanks. I having trouble with my re-direct code on my php registration form. The form does submit data to the database but I'm getting the following error. "Warning: Cannot modify header information - headers already sent by (output started at /homepages/25/d232402382/htdocs/testencourage/registration.php:15) in /homepages/25/d232402382/htdocs/testencourage/registration.php on line 87" I would like the form goes to the thanks.php after submitting the data but its not doing its job. Here is the code. Code: [Select] <?php if ($_SERVER['HTTPS']) { header('location: https://www.fakewebsite.com'); } the regular html syntax <title>, site navigation, etc... ?> <?php if (isset($_POST['submitted'])){ $fields = array( 'email', 'state', 'district', 'gender', 'age', 'profession', ); if (safe($_POST['survey']=="Yes")){ $survey = "Yes"; } else{ $survey = "No"; } foreach($fields as $fieldName) { if(isset($_POST[$fieldName]) and safe(trim(stripslashes($_POST[$fieldName]))) !==''){ $$fieldName = safe(trim(stripslashes($_POST[$fieldName]))); }else { $errors[] = "Please enter your". $fieldName .""; //code to validate fields } } if(!isset($errors)){ require_once('Connections/encourage.php'); $query = "INSERT INTO participants (email, state, district, gender, age, profession, survey, registration_date) VALUES ('$email', '$state', '$district', '$gender', '$age', '$profession','$survey', NOW())"; //databasse connection $result = mysql_query ($query); if ($result){ $url = 'http://'. $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); if ((substr($url, -1) == '/') || (substr($url, -1) == '\\')) { $url = substr ($url, 0 -1); } $url .= '/thanks.php'; header("Location: $url");// this is line 87 exit(); }else{ echo '<h1 id="mainhead">System Error</hl> <p>Your registration could not be completed due to a system error We apologize for any incovience</p>';//gives system error echo 'p' . mysql_error(). '<br /><br />Query: ' . $query . '</p>'; exit(); } mysql_close(); } else { echo '<h1 id="mainhead">Error!</h1> <p class="error">The following error(s) occurred:<br />'; foreach($errors as $msg) { echo " - $msg<br/>\n"; } echo '</p><p>Please try again.</p><p><br/></p>'; } } function safe($string) { $pattern = "/\r|\n|\%0a|\%0d|Content\-Type:|bcc:|to:|cc:/i"; return preg_replace($pattern, '', $string); } ?> Also I'm going to set up my ssl on the server so I'm planning to use that https redirect syntax but since I'm very new at this, am I missing something. Your help will be greatly appreciated, thanks! Hello, Basicly, I want to make a php index, but make a certain redirect from it, for example, make: http://mysite.com/index.php?goto=forums Go to forums of my link choice, is their a simple code I can use? Thanks Hi guys, this is my first post here. I'm looking for some help with some code for a form submission. It all works fine but if I add in a redirect using the advice found he http://www.computing.net/answers/webdevel/redirection-after-submit-php-form/3580.html. I'm using the following code: Code: [Select] <?php header ('Location: http://www.jwhunterhill.co.uk/return.html'); exit (); if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "xxx@gmail.com"; $email_subject = "E-mail from JWHunterHill.co.uk"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $comments = $_POST['comments']; // required $error_message = ""; $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$"; if(!eregi($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "^[a-z .'-]+$"; if(!eregi($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(!eregi($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Last Name: ".clean_string($last_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <!-- include your own success html here --> Thank you for contacting me. I will be in touch with you very soon. <?php } ?> As I said the code works fine just if I include the redirect, the form will not send me an e-mail as required. Could you help me out please? Thanks in advance, Jonathon Im setting up members on my site i want the profile url to be like www.mywebsite.com/NATHAN but not go to a folder on my server called nathan but instead go to mywebsite.com/?profile=Nathan
Hi all, I have a page url that looks like this: jobs.php?view=view&id=5 Their is a login on this page, the form ends with this command: header("Location: ".$session->referrer); The fuction for this is: <?php function startSession(){ global $database; //The database connection session_start(); //Tell PHP to start the session /* Determine if user is logged in */ $this->logged_in = $this->checkLogin(); /** * Set guest value to users not logged in, and update * active guests table accordingly. */ if(!$this->logged_in){ $this->username = $_SESSION['username'] = GUEST_NAME; $this->userlevel = GUEST_LEVEL; $database->addActiveGuest($_SERVER['REMOTE_ADDR'], $this->time); } /* Update users last active timestamp */ else{ $database->addActiveUser($this->username, $this->time); } /* Remove inactive visitors from database */ $database->removeInactiveUsers(); $database->removeInactiveGuests(); /* Set referrer page */ if(isset($_SESSION['url'])){ $this->referrer = $_SESSION['url']; }else{ $this->referrer = "/"; } /* Set current url */ $this->url = $_SESSION['url'] = $_SERVER['PHP_SELF']; } ?> Basically $this->url = $_SESSION['url'] = $_SERVER['PHP_SELF']; seems to cut my url to: jobs.php instead of: jobs.php?view=view&id=5 Can anyone here tell me how to fix this? Thanks Guys Can anyone enlighten me on why this doesn't redirect and if there's a better / different way of achieving a redirect deep within a page?
<?php echo"anything"; // remove this echo or even make it blank and it redirects as expected header("location:blah.php"); ?> Hello everyone, I am new to php,and i am making my website......where i am unable to redirect a user to his respctive homepage.. Can anyone help me out with a sample script.......... Thanks, cool_techie how do i redirect page within an if/else statement |