PHP - Redirect Http://site.com/index.php To Http://site.com/
How do I only redirect the page when index.php is present?
Similar Tutorialshi hope you all are fine. i have been working on a Email Form (like user fills up the form which send the information to our email) but i was having problem with (URL field i created) link of form is (http://services.shadowaura.com/allquotations/static.php) field which is not working is "Inspirational Website:" when i submit the form it says (Forbidden You don't have permission to access /allquotations/staticworking.php on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.) Can some one help me out ????????????? code behind this form is: Code: [Select] <?php /* Email Variables */ $emailSubject = 'Shadow Aura Contact Info!'; $webMaster = '*****@shadowaura.com'; /* Data Variables */ $Name = $_POST['Name']; $email = $_POST['email']; $Cell = $_POST['Cell']; $Phone = $_POST['Phone']; $CompanyName = $_POST['CompanyName']; $TypeOfBusiness = $_POST['TypeOfBusiness']; $Address = $_POST['Address']; $YourBudget = $_POST['YourBudget']; $HaveDomain = $_POST['HaveDomain']; $RunningWeb = $_POST['RunningWeb']; $WebLink = $_POST['WebLink']; $Inspiration1 = $_POST['Inspiration1']; $Inspiration2 = $_POST['Inspiration2']; $NumberPages = $_POST['NumberPages']; $UseFlash = $_POST['UseFlash']; $TimeFrame = $_POST['TimeFrame']; $Provided = $_POST['Provided']; $Comments = $_POST['Comments']; $body = <<<EOD <h1> Static Website Quotation </h1> <br> <b>Name of Client:</b>$Name<br> <b>Your Email:</b>$email<br> <b>Cell Number:</b>$Cell<br> <b>Line Phone Number:</b>$Phone<br> <b>Company Name:</b>$CompanyName<br> <b>Type of Business:</b>$TypeOfBusiness<br> <b>Address:</b>$Address<br> <b>Your Budget:</b>$YourBudget <br> <b>Do you have Domain:</b>$HaveDomain<br> <b>Your Site is Running:</b>$RunningWeb <br> <b>Website Link:</b><a href="$WebLink">$WebLink</a><br> <b>Inspiration:</b>$Inspiration1<br> <b>2nd Inspiration:</b>$Inspiration2<br> <b>Number of Pages:</b>$NumberPages<br> <b>Use Flash:</b>$UseFlash <br> <b>Time Frame:</b>$TimeFrame<br> <b>You will provide:</b>$Provided<br> <b>Comments:</b>$Comments<br> EOD; $headers = "From: $email\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); /* Results rendered as HTML */ $theResults = <<<EOD <html> <head> <title>sent message</title> <meta http-equiv="refresh" content="3;URL=http://services.shadowaura.com/"> <style type="text/css"> <!-- body { background-color: #8CC640; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 20px; font-style: normal; line-height: normal; font-weight: normal; color: #fec001; text-decoration: none; padding-top: 200px; margin-left: 150px; width: 800px; } --> </style> </head> <div align="center">Your email will be answered soon as possible! You will return to <b>Shadow Aura Services</b> in a few seconds !</div> </div> </body> </html> EOD; echo "$theResults"; ?> Okay, my organanization has a page that we really need to autodirect to https:// in case anyone manually types in the http:// version. I've tried this (among many others) and it just sits there like a knot on a log: Code: [Select] <?php header( "Location: https://www.mywebsite.com/myfile.php" ) ; ?> Any ideas? It just simply doesn't redirect. It just sits there in its http:// format. I've also tried numerous other methods. None of them worked, either, but this is the simplest. Thanks! I'm trying to redirect visitors that contain broadly matched URLs. For example, redirect the visitor if their url contains: "/welcome" or "order.php" or "login.mysite/" At the same time I also want to redirect the user if they a particular User Agent. Here's what I have, but doesn't seem to be entirely working... Code: [Select] <?php //detect referrer $ref = $_SERVER['HTTP_REFERER']; $find = "order.php"; $find = "login.mysite/"; //setting the variables $linux = stripos($_SERVER['HTTP_USER_AGENT'],"Linux"); $aol = stripos($_SERVER['HTTP_USER_AGENT'],"AOL"); //detecting user agent device, os, browser, etc. if ($linux == true || $aol == true) $redirect = 1; //detect referrer elseif (preg_match($ref, $find)) $redirect = 1; //set redirects if ($redirect) { $url = "http://www.google.com"; } else { $url = "http://www.yahoo.com"; } header("Location: $url"); ?> Any help you can offer is appreciated. Thanks! Hello there,
I am coding Arduino micro controller, and intended to GET the data from server MySQL db through php to turn ON/OFF LED. I could able to GET the data from manually updated MySQL db value, even I could able to successfully change the data of MySQL db from micro controller POST method. But I am getting error when trying to change the MySQL db value from browser using online POST tool, Following is PHP code at server 8 $api_key_value ="XXXXXXXXX";//Sample 9 $api_key =""; 10 $status = ""; 11 $id =""; 12 13 if ($_SERVER["REQUEST_METHOD"] == "POST") { 14 $api_key = test_input($_POST["api_key"]); 15 if($api_key == $api_key_value) { $id = test_input($_POST["id"]); $status = test_input($_POST["status"]); // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } //$sql = "INSERT INTO led (status) //VALUES ('" . $status . "')"; $sql = "UPDATE led SET status='$status' WHERE id='$id'"; if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } $conn->close(); } else { echo "Wrong API Key provided."; } } else { echo "No data posted with HTTP POST."; } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } Post Command: http://url/MySQL_POST.php?api_key=XXXXXXXXX&id=1&status=on Response/Error: Notice: Undefined index: api_key in <PATH>/MySQL_POST.php on line 14 Wrong API Key provided. Could be a basic issue, but I am very new to php coding and cannot solve this problem yet. Could someone please help? Thanks. Trying to run a simple program that, when submitted, stores the username and password as cookies. When clicking Submit, I get the error "HTTP Error 405 - The HTTP verb used to access this page is not allowed". If the username and password fields are left blank when submitting it's suppose to give a message to enter a username and password, but, I still get that error message. HTML form: Code: [Select] <!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" xml:lang="en" lang="en"> <head> <title>Week 1 Project--Cookies</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head> <body> <form action="cookie1.php" method="post"> <h2 align="center">Cookies</h2> <br /> <div> <p>Enter your username and password and click "Submit":</p><br /> <p>Username:<input type="text" name="username" size="20"></p> <p>Password:<input type="text" name="password" size="20"></p> </div> <br /> <div><input type="submit" name="submit" value="Submit" /></div> <br /> <div> <input type="reset" name="Reset" value="Start Over" /> </div> </form> </body> </html> PHP file: Code: [Select] <!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" xml:lang="en" lang="en"> <head> <title>Cookie File</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head> <body> <div> <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { setcookie('username', $_POST['username'], time() + 2592000); setcookie('password', $_POST['password'], time() + 2592000); } if(($_POST['username'] == "") || ($_POST['password'] == "")) { print "You must enter both a username and password. Press the Back button on your browser and try again."; } else if (isset($_COOKIE['username'])) { print "Welcome, " .$_COOKIE['username']; } ?> </div> </body> </html> Hi, Ive got a script to redirect some traffic from one site to another as follows: Code: [Select] $checker = $_SERVER['HTTP_REFERER']; if($checker == "http://siteone.com) { header("Location: http://www.sitetwo.com"); } It works fine but when the URL is like site.com/anotherpage.php it dosen't redirect. How can i redirect no matter what page siteone is on I have an account on theirsite.com and I want to be able to submit my login credentials from mysite.com/page1.php and then redirect back to mysite.com/page2.php. I've been Googling for hours now and nothing I can find works and I don't know a thing about cURL and would rather not get into it. Not to mention, I'm using free hosting for now and I don't believe I'm able to use cURL anyways. I can get it to log in with the credentials just fine, that's no problem, but I just have no clue how to get it to redirect back to my page or just send the credentials and then staying on my page because I could work with that as well (send credentials to theirsite.com from mysite.com/page1.php and staying on mysite.com/page1.php). Is there anyone that could give me a hand on how to do this without using cURL since my php.ini is not editable? Thanks Hello: I'm trying to redirect my current site to point to the secure site, and am having a problem getting it to work for all instances. I currently have this: .htaccess Code: [Select] RewriteEngine on RewriteRule ^$ https://www.mysite.com/index.htm This works fine when using the URLs "www.mysite.com" and "http://www.mysite.com" But when I enter "mysite.com" it directs to something like "https://www.mysite.com/www.mysite.com" which is incorrect. Also, if I enter a URL like "http://www.mysite.com/about.htm" it does not direct to "https" What is the trick to always have the "https" no matter what URL is entered? Any help would be great. Thanks! This is probably some silly mistake but I can't figure out why this code isn't working. I put this at the top of my php page: Code: [Select] <?php $https_url = 'https://somesite.com'; if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'off' ) { header('location: ' . $https_url); exit; } else if ( !isset( $_SERVER['HTTPS']) && $_SERVER['SERVER_PORT'] == 443 ) { header('location: ' . $https_url); exit; } ?> When I was just trying this code out it worked and redirected to https. No errors no infinite loops...it worked perfectly. However, once our server guy actually applied the SSL to the page, the code stopped working and I get the error "The page must be viewed over a secure location." It throws the error before it processes anything on that page. I found the code online on another help forum and it worked for everyone else, so what am I doing wrong? I also tried a different version of the code that also works for everyone else but got the same error. Thanks for your help! i have been searching for a solution for about a day already. can anyone help me on how to use the http functions (if thats what it is called) in php? http://www.php.net/manual/en/book.http.php like for example. i need to use the http_get() function but it returns Fatal error: Call to undefined function.. in the manual it says that i need to put php_http.dll on the ext dir and enable it in php ini like this.. extension=php_http.dll ..which i already did im working under.. windows xp sp3 php 5.3.1 thanks guys Hi All, I know it is a silly error but I am very new to PHP (only 2 days!!!) & unable to resolve this. I have seen a lot of resolutions online for example: 1) Copying the "php5isapi.dll" file to the PHP directory & under "Program Files" as well. 2) Copying the "favicon.ico" file etc etc Before I could elaborate the issue, please note that I am a Windows user - Windows XP (I know its not the best of the OS's to work with!!!) When initially I started getting the issue, I checked the "error.log" file under "C:\Program Files\Apache Software Foundation\Apache2.2\logs" & following is what I saw: ----------------------- [Sun Sep 18 14:13:25 2011] [notice] Server built: Sep 9 2011 10:26:10 [Sun Sep 18 14:13:25 2011] [notice] Parent: Created child process 4420 [Sun Sep 18 14:13:25 2011] [notice] Child 4420: Child process is running [Sun Sep 18 14:13:25 2011] [notice] Child 4420: Acquired the start mutex. [Sun Sep 18 14:13:25 2011] [notice] Child 4420: Starting 64 worker threads. [Sun Sep 18 14:13:25 2011] [notice] Child 4420: Starting thread to listen on port 80. [Sun Sep 18 14:14:55 2011] [error] [client 127.0.0.1] File does not exist: C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/favicon.ico [Sun Sep 18 14:21:37 2011] [notice] Server built: Sep 9 2011 10:26:10 [Sun Sep 18 14:21:37 2011] [notice] Parent: Created child process 7976 [Sun Sep 18 14:21:37 2011] [notice] Child 7976: Child process is running [Sun Sep 18 14:21:38 2011] [notice] Child 7976: Acquired the start mutex. [Sun Sep 18 14:21:38 2011] [notice] Child 4420: Released the start mutex [Sun Sep 18 14:21:38 2011] [notice] Child 7976: Starting 64 worker threads. [Sun Sep 18 14:21:39 2011] [notice] Child 4420: All worker threads have exited. [Sun Sep 18 14:21:39 2011] [notice] Child 4420: Child process is exiting [Sun Sep 18 14:21:39 2011] [notice] Child 7976: Starting thread to listen on port 80. [Sun Sep 18 14:21:52 2011] [error] [client 127.0.0.1] File does not exist: C:/Rahul/Personal/Web Development/favicon.ico ---------------------- Then I created an icon file and named it "favicon.ico" & placed it in the following destinations: 1) C:/Rahul/Personal/Web Development/ and 2) C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/ but to no avail But interestingly & surprisingly, the error.log file stopped giving any of the above error messages but I still get the HTTP Error. Following is the error message that I get on the browser: -------------------------- Server error The website encountered an error while retrieving http://localhost/Forms/insert%20data.php. It may be down for maintenance or configured incorrectly. Here are some suggestions: Reload this webpage later. HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request. -------------------------- Now, just to let you know which php I am using, so, just to let you know, I just copied the html & php from http://www.w3schools.com/PHP/php_mysql_insert.asp. Following are they: HTML: ---------------------------- <html> <body> <form action="insert data.php" method="post"> Firstname: <input type="text" name="firstname" /> Lastname: <input type="text" name="lastname" /> Age: <input type="text" name="age" /> <input type="submit" /> </form> </body> </html> ----------------------------- PHP ----------------------------- <?php $con = mysql_connect("localhost","root","orange"); if (!$con) { die('Could not connect: ' . mysql_error()); } echo "Connection established"; mysql_select_db("my_db", $con); $sql="INSERT INTO Persons (FirstName, LastName, Age) VALUES ('$_POST['firstname']','$_POST['lastname']','$_POST['age']')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added with name: " $_POST[firstname] $_POST[lastname]; mysql_close($con) ?> ------------------------- I hope someone is able to help me in this & I guess I have mentioned everything I could to explain the error! Many thanks in advance! Rahul I am trying to build an app which will scan a site multple times, the only problem is the 403 error, how do I get around this. Searching seems to imply curl or user_agent, but can't get it working. Any suggestions? Thanks Just a quick question. I'm using the Live HTTP Headers add-on for Firefox that display all the HTTP headers etc. I'm writing an article on it and want to include a screenshot of it in action. Are there any headers that I should hide from the reader for security reasons? Thanks for any help. Hi. I am trying to extract the main url from a string.
For example.
I want to extract:
"http://google.com" from "http://google.com/search/pic.jpg"
"https://secure.co.uk" from "https://secure.co.uk/secure/secure.gif"
I am able to do this with this code, where $url is the url:
preg_match("http://(.*?)/", $url, $matches);
preg_match("https://(.*?)/", $url, $matches);
Is there away to consolidate this into one regex search? Or am I being picky?
Thanks!
when i upload this code and refresh the page nothing shows up the only thing htat shows up is HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request. please helop Code: [Select] <?php $title = "Home"; ?> <?php require("styles/top.php"); ?> <?php if ($username){ echo "<table> </div></td> </tr> <tr> <td width="244" valign="top"><br /> <form id="form1" name="form1" method="post" action="search_results.php" style="margin-left:20px;"> <input name="var" type="text" class="size12" id="var" style="width:124px; background-color: #A4D1FF;" /> <input name="button" type="submit" class="size11" id="button" value="Search" /> </form> <br /> <div id="leftNav" style="margin-left:22px;"> <!-- Start tv --> <strong><font color="#FFFFFF"><span class="size16">TV</span></font></strong><br /> <a href="tv.php?c=tv&sc=cartoons">Cartoons <font size="-3" color="#FFFFFF"></font></a><br /><a href="tv.php?c=tv&sc=news">News <font size="-3" color="#FFFFFF"></font></a><br /><a href="tv.php?c=tv&sc=adventures">Adventures <font size="-3" color="#FFFFFF"></font></a><br /><a href="tv.php?c=tv&sc=horror">Horror<font size="-3" color="#FFFFFF"></font></a><br /><a href="tv.php?c=tv&sc=Drama">Drama<font size="-3" color="#FFFFFF"></font></a><br><br /> //End TV --> // Start Videos --> <strong><font color="#FFFFFF"><span class="size16">Videos</span></font></strong><br /> <a href="videos.php?c=videoss&sc=children">Children <font size="-3" color="#FFFFFF"></font></a><br /><a href="videos.php?c=videos&sc=music">Music<font size="-3" color="#FFFFFF"></font></a><br /><a href="videos.php?c=videos&sc=comedy">Comedy<font size="-3" color="#FFFFFF"></font></a><br /><a href="videos.php?c=videos&sc=youtubemovies">Youtube Movies <font size="-3" color="#FFFFFF"></font></a><br /><a href="videos.php?c=videos&sc=sports">Sports <font size="-3" color="#FFFFFF"></font></a><br /> <br> <!-- End videos--> <!-- Start Movies --> <strong><font color="#FFFFFF"><span class="size16">Movies</span></font></strong><br /> <a href="movies.php?c=movies&sc=comedy">Comedy <font size="-3" color="#FFFFFF"></font></a><br /> <a href="movies.php?c=movies&sc=action">Action <font size="-3" color="#FFFFFF"></font></a><br /><a href="movies.php?c=movies&sc=adventure">Adventures <font size="-3" color="#FFFFFF"></font></a> <a href="movies.php?c=movies&sc=horror">horror <font size="-3" color="#FFFFFF"></font></a><br /> <a href="movies.php?c=movies&sc=drama">Drama<font size="-3" color="#FFFFFF"></font></a><br /><br /> <br /> //End Movies </div> </table>"; } else echo "<h2><font color='red'>You must be logged view this Part.</font></h2>"; ?> <?php require("styles/bottom.php"); ?> I am learning PHP using the book "Beginning PHP and MySQL 5 - From Novice to Professional", and I have come across a lesson in the book which I am stuck on. The lesson is on using the echo() statement. I've typed in the following code and saved it as a php file.... <?php $heavyweight = "Lennox Lewis"; $lightweight = "Floyd Mayweather"; echo &heavyweight, " and ", $lightweight, " are great fighters."; ?> My Apache and PHP is working fine as my other PHP files work properly. When I try and view the file it says... "The website encountered an error while retrieving http://localhost:8888/phpdocs/multiplestringsecho.php. It may be down for maintenance or configured incorrectly." and when I click on more information it says... "HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request." Any ideas? Have I done something wrong? Any help would be much appreciated. Hi, I don't know very much about php. I don't know any at all, actually. I play a game called Roblox where you get to use the programming languange, "Lua" to script your own games. What I am requesting has been done before on this game, but I only know Lua. I was also told PHP cURL is needed. Anyways, let me get to the point. I am essentially trying to create a system on my webserver (You can send HTTP Requests to external sites in this game via script) that will essentially log into an account on Roblox, to perform a task. My current idea would be to have the Lua script send a request to my webserver with an generated code that would access the username and password of my roblox account (Which would be on the webserver). It would then perform a task. Is this a good way to go about this? If not, I am open to suggestions. If you can find the time to actually help me set this up on my webserver, I would greatly appreciate it! I'm also sorry if this is the wrong place for this post, I'm new here. Not sure if this is possible. What I am trying to do is remove a section of text a user posts. ie: go to this url: http://url.com or http://this.domain.org I already have it to strip they <a href="whatever but not sure if I can do the other. Any help would be appreciated. Thanks I have several "sites" located in my html directory, and each has a "general" access point and an "administrator" access point:
/var/www/html/site1/index.php /var/www/html/site1/administrator/index.php /var/www/html/site2/index.php /var/www/html/site2/administrator/index.php /var/www/html/site3/index.php /var/www/html/site3/administrator/index.phpAll sites are similar except that data will be specific to site1, site2, or site3, etc. Users who log onto /var/www/html/siteX/index.php are totally unrelated to those who logon to /var/www/html/siteX/administrator/index.php, will have different logon credentials, are stored in different DB tables, and each should have their own session. If a user logs off of either the general or administrator site, it should not effect the other site even if they were previously logged on to both on the same PC (and of course not effect other sites). When a user logs off, I would like to destroy their previous cookie and associated session. Users for either will only use https. I am using Apache to rewrite https://www.mysite.com/ to https://mysite.com/. While I named the administrator site "administrator" above, the administrator user has the ability to change the directory name. I am thinking I need to use session_set_cookie_params to specify where I wish the session cookie to be stored since /var/www/html/siteX/administrator/index.php is a sub-directory to /var/www/html/siteX/index.php, but am not really sure. Sorry for the cryptic post, but I am not very well versed in this subject. How would you recommend setting up cookies/sessions for this scenario? Thank you I'm trying to integrate w/ a few APIs, and getting started is causing me fits. I'm using PHP locally to add common headers and as a contact form, and those are working fine. The Code: <?php require('HTTP/Request.php'); $url = "http://example.com"; $request =& new HTTP_Request($url); $request->sendRequest(); $response = $request->getResponseBody(); ?> The Result: Warning: require(HTTP/Request.php) [function.require]: failed to open stream: No such file or directory in /home/stodgy5/public_html/trackstart/start.php on line 3 Warning: require(HTTP/Request.php) [function.require]: failed to open stream: No such file or directory in /home/stodgy5/public_html/trackstart/start.php on line 3 Fatal error: require() [function.require]: Failed opening required 'HTTP/Request.php' (include_path='.:/usr/lib/php:/usr/local/lib/php:/home/stodgy5/php') in /home/stodgy5/public_html/trackstart/start.php on line 3 I'm assuming this is a directory issue, as my cPanel says Pear is installed. Any advice? |