PHP - User Redirection
Hi,
I am having a little problem with my coding and was wondering if someone could please help me. The code below is a working login script where when a user logs in they are redirected to a URL which I have in my SQL database. The problem I am having is I would like to create a link on every page which says something like "My Account" - and when a user clicks the link the script automatically knows who is logged on and redirects to the page which matches the URL in the database. I hope I am making sense as I've been working on it for days and cannot figure out how to do it. Code: [Select] <?php session_start(); require 'config.php'; $user_name = $_POST['username']; $user_password = $_POST['password']; $qry = "SELECT id, redirect FROM users WHERE username = '".$user_name."' AND password = '".$user_password."'"; $result = mysql_query($qry); $count = (int)mysql_num_rows($result); if($count != 0) { $row = mysql_fetch_assoc($result); $_SESSION['loggedIn'] = true; header('Location: '.$row['redirect']); } else { header('Location: index.php'); } exit; ?> The config.php has basically my login details for phpmyadmin and nothing else. If anyone can help me it would be greatly appreciated. Kind regards, Robert. Similar TutorialsHi i have multilang website when you entered homepage default site if you are from polonia it redirect to you polonia page this script works perfect but the problem is if you are trying to see www.server.com instead server.pl and if you are from polonia you not able see because of redirection on google they solved this problem like www.google.com/ncr post is there something i can do like this for example server.com/ncr and this will disable redirect function would be nice if you help me to how to do it thanks in advance Code: [Select] <?php function redirect() { $Destination['en-au'] = 'http://www.server.com.au'; //austr$Destination['pl'] = 'http://www.server.pl'; //polonia $Destination['se'] = 'http://www.server.se'; //sweden $DefaultDestination = 'http://www.server.com'; //us $lang = preg_replace('/;.*$/','',$_SERVER['HTTP_ACCEPT_LANGUAGE']); $lang = preg_replace('/,.*$/','',strtolower($lang)); $dest = ''; if( isset($Destination[$lang]) ) { $dest = $Destination[$lang]; } if( empty($dest) ) { $lang = substr($lang,0,2); if( isset($Destination[$lang]) ) { $dest = $Destination[$lang]; } else { $dest = $DefaultDestination; } } if( ! empty($dest) ) { header("Location: $dest"); exit; } } redirect(); ?>[/code] Hi, for sometime i have tried to create what this person is doing below with his script, when a user clicks the buy it now button he redirects them to another url. Is it possible to replicate what he has done? I plan using the body onload to redirect the user however im not sure how i can get the url from the url redirected from? Quote http://searchchief.co.uk/Search/Essential-Michael-Jackson If i have not made myself clear please let me know as I'm totally new to PHP. Thanks, Hi I have coded a form, and dependant upon the result I would like to re-direct to a different page. The problem is I am getting the "headers already sent" message..Is there a way around this, I can't use JS re-direction because of accessibility. E.G: <?php //Do stuff with form data if($result = y){ header(Location: "mysite.php/thankyou.php"); } else{ header(Location: "mysite.php/error.php"); } ?> In-fact whilst typing this I have an idea, why not do all of this at the top of the page before headers are sent? I'll go ahead and try it now, in the meantime if anybody knows how or if headers can be sent after output please let me know thanks. Hi All, I'm doing some testing using Google Website Optimiser and i have a problem which i wonder if you might be able to help me with. Basically with website optimiser you need a common conversion page that all variations land at to track conversions. My problem is this that the pages i want to test are all very different in design and have different conversion (thankyou) pages based on teh site design. So i'm wondering if i can put some sort of bridge page that all conversion come through to before being redirected to the thank you page. so for example index1.html goes to conversion.php page which then redirects to thanks1.html index2.html goes to conversion.php page then redirecting to thanks2.html this would get over the issue of having one common conversion page. I know to redirect a page i can use the following code: <?php header( 'Location: http://www.yoursite.com/new_page.html' ) ; ?> But i need to add this to redirect specific incoming pages to different thank you pages. Any ideas? Thanks I am trying to redirect the user to a different Web site after they enter a password. I have two problems, I think. a. My phone file is not retrieving the 'input' from my html5 form. b. My phone header is not working: header (' location: http://filefippo.com'); What is wrong with my coding? <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="keywords" content="html"> <meta http-equiv="refresh" content "1800"> <link rel="stylesheet" href="menu_blue.css" type="text/css" media="screen" /> <title>Members 2</title> <script src="http://1.2.3.4/bmi-i...sion=1350564613" language="javascript"> </script> <!--[if IE 6]> <style> body {behavior: url("csshover3.htc");} #menu li .drop {background:url("img/drop.gif") no-repeat right 8px; </style> <![endif]--> </head> <body bgcolor="#000080"> <ul id="menu"> <li> <a href="index.html">Home</a> <!-- Home page --> </li> <!-- End Home page --> <li> <a href="contactform.html">Contact</a> <!-- Contact page --> </li> <!-- End Contact page --> <li> <a href="feedbackform.html">FeedBack</a> <!-- Feedback Page --> </li> <!-- End Feedback page --> <li> <a href="construc.html">Free Estimate</a> <!-- Free Estimate Page --> </li> <!-- End Free Estimate page --> <li> <a href="construc.html">Humor</a> <!-- Humor Page --> </li> <!-- End Free Humor page --> <li> <a href="#" class="drop">Other Links</a> <!-- Other Links Page --> <div class="dropdown_1column align_right"> <div class="col_1"> <ul class="simple"> <li> <a href="construc.html"> Members</a></li> <li> <a href="military.html"> Military</a></li> </ul> </div> </div> </li><!-- End Other Links page --> <li> <a href="repair_upgradeform.html">Repair/Upgrade</a> <!-- Repair/Upgrade Page --> </li><!-- End Repair/Upgrade page --> <li class="menu_right"> <a href="#" class="drop">Training</a> <!-- Training Page --> <div class="dropdown_1column align_right"> <div class="col_1"> <ul class="simple"> <li> <a href="tng_appsform.html"> Applications</a></li> <li> <a href="tng_hardwareform.html"> Hardware</a></li> <li> <a href="tng_osform.html"> Operating Systems</a></li> </ul> </div> </div> </li><!-- End Training page --> </ul> <br> <form name="myform" method="post" action="members2.php"> <table width="100%" align="center" bgcolor="#000080"> <tr> <th align="center" > <font size="+2" color=#ffff00"> ~ ~ ~ Member ~ ~ ~ </font> <br> </th> </tr> </table> <br> <table width="699" bgcolor="#000080" align="center"> <tr align="center"> <td align="center"> <input type="password" name="password" maxlength="15" size="15"> </td> </tr> </table> <table width="699" bgcolor="#000080" align="center"> <tr align="center"> <td align="center"> <font color="#ffffffff" size="+1"> (Please enter the password on your receipt) </font> </td> </tr> </table> <br> <table width="669" bgcolor="#000080" align="center"> <tr> <td align=center> <input type="submit" value="Submit"> <input type="reset" value="Reset"> </td> </tr> </table> </form> <script language="JavaScript" type="text/javascript"> //You should create the validator only after the definition of the HTML form var frmvalidator = new Validator("myform"); frmvalidator.EnableMsgsTogether(); frmvalidator.addValidation("Password","req","Please enter the Password."); frmvalidator.addValidation("Password","maxlen=15","Max length for the Password is 15"); frmvalidator.addValidation("Password","alnum_s","Password - Alphabetic and Numeric chars"); </script> </body> </html> <script language="javascript"><!--//bmi_orig_img 0 // --> </script> PHP CODE <?php ob_start(); // Process membersform2.html error_reporting(-1) ; // Get Data From Form if ($_SERVER["REQUEST_METHOD"] == "POST") { if(isset($_POST["password"])) { $password = $_POST["passwords"]; trim($password); echo "$Password"; } else { if(empty($_POST["password"])) { echo "Password is required"; } } } // Validate Pwd if($password == "Z0y1X2w3V"){ header(' Location: http://filehippo.com/ '); exit; }else { members(); } // FUNCTION function members(){ // Print to browser global $password; // echo " <html>\n"; echo " <head>\n"; echo " <title>Redirect</title>\n"; echo " </head>\n"; echo " <body BGCOLOR=\"#000080\" TEXT=\"#ffff00\">\n"; echo " <table width=\"600\" Align=\"center\">\n"; echo " <tr>\n"; echo " <td width=\"600\" Align=\"left\">\n"; echo " You will be redirected to the members page in a moment.\n"; echo " <br />\n"; echo " $password \n"; echo " <br /><br />\n"; echo " </td>\n"; echo " </tr>\n"; echo " </table>\n"; echo " </body>\n"; echo " </html>"; } ob_flush(); ?> hello Guys, Please refer this site http://www.dreamvacationrent.com/, it is having a link called "Our Rental Properties" now when you click on it it will show the url with the page name "properties-rental.html" but actually the page is "properties.php" like wise is has done with other links values passed through url are seen by using + or - sign, so how could this be done. Please help me... Thank you. Hi, Working on a URL re-direction site. http://ziz.im At the moment, it's not using the most effecient of redirections. I want to change this to a 301 redirect. But I can't quite figure out how to get it to work. Currently: - I am using a .htaccess rewrite to re-direct all shortened urls to a page (parse.php) which is providing the public variable 'q' containing the shortened keywork (e.g. GTRfdrtlls). - This is then checked through the DB to find if its valid, then redirects to that URL. How can I get it to use 301 Redirects, like the below: <? Header( "HTTP/1.1 301 Moved Permanently" ); Header( "Location: http://www.new-url.com" ); ?> I need to be able to query the database to get the URL / Check if its valid before I can specify the URL. But you need to specify the headers at the start. Confused. Cheers. Ok so what I am trying to do is have multiple folders pull from one folder. So if I have this structu Code: [Select] /test1/some_folder /test2/some_folder /test3/some_folder I would want all of those folders named some_folder to read from a master directory. I dont need them to be able to go that specific url just need it to include the files from the main directory in each of those. Imagine I was setting up shared functions and just wanted to store them in one place but be able to include them on any site. I didnt know what to google (tried folder redirection but didnt seem right) so if anyone can offer a suggestion as to what to google or wants to provide an answer it would be appreciated. Hi all, we are new bee to php, I am developing a project that has config and other sub folders under admin directory ROOT/ADMIN, ROOT/ADMIN/FOLDER1,2,3... how to manage redirection from one file to another folder. Hi, what i am after is for instance, the user is viewing my website. He is in a different section on my website and there is a sign in button. The user goes to the sign in page, now what i want is when the user logs in, the user to be redirected back to the section which he was viewing before signing in. Basically in more clear words, I want the user to return to the content he was viewing after logging in. Hi all, I'm using some code that I got from the net (I forget where but all credit to the author). I've tried to adapt it to suit my own needs (almost suceeded?). I have an upload page with 5 file uploads which is processed by this script: (I've annotated where I think the problems may be) UPLOAD FORM <table width="600" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#993399"> <tr> <form action="../uploads/upload2.php" method="post" enctype="multipart/form-data" name="form1" id="form1"> <td> <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#993399"> <tr> <td><div align="center"><strong><h3>Upload your files</h3></strong></div></td> </tr> <tr> <td align="center">Select file <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td align="center">Select file <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td align="center">Select file <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td align="center">Select file <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td align="center">Select file <input name="ufile[]" type="file" id="ufile[]" size="50" /></td> </tr> <tr> <td align="center"><input type="submit" name="Submit" value="Upload" /></td> </tr> </table> </td> </form> </tr> </table> Here is "uploads.php" <?php $path1= "../uploads/".$HTTP_POST_FILES['ufile']['name'][0]; $path2= "../uploads/".$HTTP_POST_FILES['ufile']['name'][1]; $path3= "../uploads/".$HTTP_POST_FILES['ufile']['name'][2]; $path4= "../uploads/".$HTTP_POST_FILES['ufile']['name'][3]; $path5= "../uploads/".$HTTP_POST_FILES['ufile']['name'][4]; copy($HTTP_POST_FILES['ufile']['tmp_name'][0], $path1); copy($HTTP_POST_FILES['ufile']['tmp_name'][1], $path2); copy($HTTP_POST_FILES['ufile']['tmp_name'][2], $path3); copy($HTTP_POST_FILES['ufile']['tmp_name'][3], $path4); copy($HTTP_POST_FILES['ufile']['tmp_name'][4], $path5); include '../includes/smile.php'; echo "<table width=\"900\"height=\"180\"cellpadding=\"5\" cellspacing=\"5\" background=\"../images/upbg.png\" align=\"center\"> <tr><td align=center><img src=\"$path1\" width=\"100\" height=\"100\"></td>"; echo "<td align=center><img src=\"$path2\" width=\"100\" height=\"100\"></td>"; echo "<td align=center><img src=\"$path3\" width=\"100\" height=\"100\"></td>"; echo "<td align=center><img src=\"$path4\" width=\"100\" height=\"100\"></td>"; echo "<td align=center><img src=\"$path5\" width=\"100\" height=\"100\"></td></tr></table>"; $filesize1=$HTTP_POST_FILES['ufile']['size'][0]; $filesize2=$HTTP_POST_FILES['ufile']['size'][1]; $filesize3=$HTTP_POST_FILES['ufile']['size'][2]; $filesize4=$HTTP_POST_FILES['ufile']['size'][3]; $filesize5=$HTTP_POST_FILES['ufile']['size'][4]; if($filesize1 && $filesize2 && $filesize3 && $filesize4 && $filesize5 !=0) // possible error? { echo "<h3 align=center><img src=\"../images/niceone.png\"></h3>"; include '../includes/smilefoot.php'; } else { echo "<meta http-equiv='Refresh' content='0; url=../includes/fail.php'>"; // possible error? } ?> It took me an entire day to get it at this level of functionality where if you sucessfully upload your files you get a success message on the same page but otherwise are redirected to a failure page. The problem is, if you don't upload a file for each of the 5 form inputs, you get the succes message and then redirected to the fail page. Someone who actually knows something about php will probably see a solution straight away but I don't know anything much really and I have few ideas on how to fix this. I am beginning to suspect that it is my redirect method but I have no idea how to do it differently. I'd be really grateful if someone could explain what I'm doing wrong here, this is for my personal family site and I want it to be good. It took me a week to do the login! What I'd love to achieve is exactly the same as the attachment box(es) right below where I am typing now. I have attached my two relavent pages. Thanks in advance. Paul [attachment deleted by admin] I need help getting my login form to redirect to my admin area. I have been following tutorials on youtube trying to create a content management system and have made it as far as creating the form and creating the login action required to look for a username and password form my database and log in. I'll post up the pages I think are required for someone to give me some advice on where im going wrong. my login page login.php Code: [Select] <html> <head> <title>Basic CMS - Admin Area - Login</title> </head> <body> <?PHP session_start(); if(isset($_SESSION['user'])) header("Location: index.php"); ?> <form action="dologin.php" method="post"> <table> <tr> <td><span>Username:</span></td> <td><input type="text" name="username" /></td> </tr> <tr> <td><span>Password:</span></td> <td><input type="password" name="password" /></td> </tr> <tr> <td colspan="2" align="right"><input type="submit" name="login" value="Login" /></td> </tr> </table> </form> </body> </html> my login actions page dologin.php Code: [Select] <?php include('includes/functions.php'); session_start(); if (isset($_POST['login'])) { if(isset($_POST['username'])) { if(isset($_POST['password'])) { $username = $_POST['username']; $query = mysql_query("SELECT * FROM users WHERE Username = '$username'") or die (mysql_error()); $user = mysql_fetch_array($query); if(md5($_POST['password']) == $user['Password']) { echo "Login successful"; $_SESSION['user'] = $user['Username']; header("Location: index.php"); } else { echo "Please check your login details!"; include('login.php'); } } else { echo "Please check your password!"; include('login.php'); } } else { echo "Please check your username!"; include('login.php'); } } else { echo "Please check that you filled out the login form!"; include('login.php'); } ?> and my admin area index.php Code: [Select] <?php session_start(); if(!isset($_SESSION['user'])) header("Location: admin/login.php"); ?> <html> <head> <title>Basic CMS - Admin Area</title> </head> <body> <span>Logged In! Welcome <?php> echo $_SESSION['user']; ?></span> <a href="logout.php">Logout</a> <a href="posts.php">Manage Posts</a> </body> </html> On logging in I am given "Login succesful" on the dologin.php page but I need it to redirect me to my index.php page, which is my admin area. If there's any other information you need to help me out just let me know. Any help anyone has for me is greatly appreciated! Thank you in advance. Hi, Have a project, http://ziz.im URL Shortener. For some reason, shortened youtube links don't work. When used, they go to the youtube page, displaying a message saying the video is not available. But it's the same link (once redirected) as the original link. Any idea what could be causing this ? I am having an issue with some scripts on my site. It won't redirect and emits an error. This occurs for only some of my scripts, but for the ones in which it does occur, it occurs 100% of the time. On a previous server, I didn't have this issue, now I do. I get the following error: Warning: Cannot modify header information - headers already sent by (output started at /www/zzl.org/f/a/n/fantasyboxingonline/htdocs/bg/train_stat.php:5) in /www/zzl.org/f/a/n/fantasyboxingonline/htdocs/bg/train_stat.php on line 29 Below is the code to the page that emitted the error above (Note: session_start(); IS in autoupdater.php I'm not that stupid): <?php require_once("../autoupdater.php"); ?> <link rel="stylesheet" type="text/css" href="/style.css"/> <?php if(!$_SESSION["loggedin"]) { die("<b>You are not logged in, or you have been logged out. Please <a href=\"/login/\" target=\"_top\">login again!</a></b>"); } $id = $_GET["id"]; if($id > 4 || $id < 1) { die("<center><h2>An error occurred. You are trying to train an invalid statistic.</h2></center>"); } $userid = $_SESSION["userid"]; $time = time(); $stattraining = $_SESSION["stattraining"]; if($stattraining) { if($stattraining == 1) { $statname = "powerful"; } elseif($stattraining == 2) { $statname = "quick"; } elseif($stattraining == 3) { $statname = "skilled"; } elseif($stattraining == 4) { $statname = "durable"; } die("<center><h2>You cannot train! You are already training $statname!</h2></center>"); } mysql_query("UPDATE `users` SET `stattraining`='$id', `statstarttime`='$time' WHERE `userid`='$userid'", db_connect_select()); header("Location: training.php"); die(); ?> Any help or suggestions would be greatly appreciated. -Moon Hey everyone! I'm an absolute beginner with PHP but in my struggle with a project, I keep seeing 'PHP' so here I am, asking for help from the experts. I have a client who wants a basic 'mobile version' of their website to be displayed automatically when people view it on a mobile device (iPhone, Android especially). I've tried a couple of JavaScript solutions but, for some reason, they wouldn't work on Android (despite the author of the code specifying that it 'should do'). This has led me to look into a server-side solution. If the user visits the site, e.g. www.mysite.com on a mobile device, I want it to redirect to the subdomain m.mysite.com (I could even use www.mysite.com/mobile). On this 'mobile version' there should be a link to view the full site (and vice versa). Does anyone know of any tried and tested methods to achieve this? I'm literally pulling my hair out now with this. Thank you so much in advance. Have a great day. Regards Darryl Hi Guys, This is my first time posting so let me get right to this. I'm trying to create a PHP MYSQL webpage that would create a session, allowing an anonymous (guest) user to view a particular page.. lets say "page1.php" for a certain amount of time "30 mins" and then be redirected to "page2.php" if they go back (or refresh) "page1.php" when that time runs out. The auto-redirection should only last about 3 hours ( session timeout ). Then they should be able to view "page 1" again. This sounds so simple in theory but i just cant wrap my head around doing it. Any help would be very appreciated. Dear All, I am sure that this is a really basic question. However I cannot see the way forward and would like some help. If we accept that the best practice is not to self call a form but to process the form in a separate php file then if the form fails validation how do we return to the form and display the appropriate information to be edited. I have attempted to use $_SESSION to save the $_POST and use a header function to redirect the flow upon failure of validation is this the correct approach? If anyone can advise or point me in the direction of a suitable tutorial I would be very grateful Regards Hello, I have a simple feedback form which asks for name, location and a simple comment about the business. I have inserted data into the database successfully but I'm not sure on the best way to display the data from the table on the same page as the form (after redirection). Here is my code: FORM: Code: [Select] <form id="feedback" name="feedback" action="php/phpcustom.php" method="POST"> <fieldset> <legend>Gardenable.com Feedback</legend> <p><label for="fname">Name:</label><input type="text" size="30" maxlength="40" id="fname" name="fname" /></p> <p><label for="loc">Location:</label><input type="text" size="30" maxlength="40" id="loc" name="loc" /></p> <p><label for="com">Comments:</label><textarea cols="40" rows="6" maxlength="300" id="com" name="com"></textarea></p> <p><input type="submit" name="send" id="submitbutton" value="Submit" /><input type="reset" name="reset" value="Reset" /></p> </fieldset> </form> ACTION SCRIPT on submit: Code: [Select] <?php session_start(); $dbhandle = mysql_connect('localhost', 'root', '') or die("Unable to connect to MySQL"); $selected = mysql_select_db("commentdatabase",$dbhandle) or die("Could not select the database"); $name = $_POST['fname']; $loc = $_POST['loc']; $com = $_POST['com']; $sql = "INSERT INTO userinfo (name, location, comment) VALUES ('{$name}','{$loc}','{$com}')"; if(!mysql_query($sql, $dbhandle)) { die('Error: ' . mysql_error()); } $dbselect = "SELECT * FROM userinfo"; if(!mysql_query($dbselect, $dbhandle)) { die('Error: ' . mysql_error()); } header('Location: ../contact.htm'); mysql_close(); ?> //This is underneath the FORM CODE: Code: [Select] <div id="feedbackDiv"> <?php $dbhandle = mysql_connect('localhost', 'root', '') or die("Unable to connect to MySQL"); $selected = mysql_select_db("commentdatabase",$dbhandle) or die("Could not select the database"); $result = mysql_query("SELECT * FROM userinfo"); while ($row = mysql_fetch_array($result)) { echo "ID:".$row{'name'}." Name:".$row{'location'}."Year: ". $row{'comment'}."<br />"; } ?> </div> It is displaying a tiny part of php code rather than the returned data. This is what i being displayed: "; } ?> The data is inserting correctly but i'm unsure as to whether or not I need to pass the values in the url string in the header function? Thank you for any information you can provide me. Regards, BuNgLe Hi, i'm trying to redesign the smarty based website . My job is to just change the 'look and feel' of the web site .i have downloaded the server contents and trying out in the local machine. The site has some functionalites for registered users.The function required after login is to show some catagories of the site . i'm using the login page of the site and after entering username and password i'm not able to redirect the page to the 'catagories ' page its redirecting to some file called showcatagories.php but no data is written in it. can anyone please tell me where the code is written for redirection.. |