PHP - Return Requesturi Without Any Params, Howto?
Hi,
I'm trying to make a header("Location: "); where I want, the url I'm currently on, without any ?id=1 etc, so I get /category/editCategory/ instead of /category/editCategory/?id=1 How can I do that, when I do $_SERVER, sometimes I see one called $_SERVER['REQUEST_URL'] (yep, URL, not URI) - which does exactly what I want, but it's only sometimes I have it :S Is there a nice way of doing it? Best regards, Lucas R. Similar TutorialsHi I don't understand this stuff and am trying to debug it to see. This function seems to return Resource id #1. I have added an echo at line 33. Not a big file but would like to understand what is happening behind. http://www.des-otoole.co.uk/streetangels/eapi.php Code: [Select] <?php //==================================== Simple PHP code sample ==========================================// /* * We recommend that you use port 5567 instead of port 80, but your * firewall will probably block access to this port (see FAQ for more * details): * $url = 'http://www.bulksms.co.uk:5567/eapi/submission/send_sms/2/2.0'; * * Please note that this is only for illustrative purposes, we strongly recommend that you use our comprehensive example */ $url = 'http://www.bulksms.co.uk/eapi/submission/send_sms/2/2.0'; $data = 'username=your_username&password=your_password&message='.urlencode('Testing SMS').'&msisdn=44123123123'; $response = do_post_request($url, $data); print $response; function do_post_request($url, $data, $optional_headers = null) { $params = array('http' => array ( 'method' => 'POST', 'content' => $data, )); if ($optional_headers !== null) { $params['http']['header'] = $optional_headers; } $ctx = stream_context_create($params); echo "$ctx, $url, $data"; exit; $fp = fopen($url, 'rb', false, $ctx); if (!$fp) { print "Problem with $url, Cannot connect\n"; } $response = @stream_get_contents($fp); if ($response === false) { print "Problem reading data from $url, No status returned\n"; } return $response; } ?> <html> <body> <? echo $ctx ?> </body> </html> Ta Desmond. Hi again again, I'm making a search, where I use BETWEEN, if I have et $maxPrice is 2147483647 and $minPrice is 0 - (result from var_dump()), when I then use it in PDO, it's like it get another 'maxPrice' because it only show results under "200000" in price, but if I define, a static value of 2.000.000 it gets all the results as it should, but not when doing it with params in PDO :/ I also do a var_dump() of the maxprice, after the PDO, and the value is still the same as above (the 2147483647), and I've been spending loong time now, trying to find out why! Maybe someone here can spot the error! http://codepad.org/VIsk0UI8 Thank you a lot! Hi Guys
This may be a silly question. Apologies in advance.
Lets say I wanted to write a rewrite condition where I need to test both the query_string and the resquest_uri against the same regex. Is it possible to almost parametise these in one line?
e,g.
RewriteCond %{REQUEST_URI, QUERY_STRING} SOME-PATTERN etc. Hi all, I am trying to build a multidimensional array from values in a URL. For example: page.php?ind=123&loc=456&wt=789 needs to build the array like this: Code: [Select] Array ( [0] => Array ( [0] => 123 ) [1] => Array ( [0] => 456 ) [2] => Array ( [0] => 789 ) ) If one of these params is empty: page.php?ind=123&loc=&wt=789 I need the array to be Code: [Select] Array ( [0] => Array ( [0] => 123 ) [1] => Array ( [0] => 789 ) ) I am having some trouble wrapping my head around how to do this. I am using array_push to construct it, but i fear I may be missing something. There's a good change I am way off too . Any suggestions would be greatly appreciated. My code: <?php // get the id from the URL if (isset($_GET['ind'])) { $indId = $_GET['ind']; } if (isset($_GET['loc'])) { $locId = $_GET['loc']; } if (isset($_GET['wt'])) { $wtId = $_GET['wt']; } $searchArray = array(); if (!isset($_GET['ind'])) { empty($_GET['ind'); } else { array_push($searchArray, $ind); } if (!isset($_GET['loc'])) { empty($_GET['loc']); } else { array_push($searchArray, $loc); } if (isset($_GET['wt'])) { empty($_GET['wt']); } else { array_push($searchArray, $wt); } echo '<pre>'; print_r($searchArray); echo '</pre>'; ?> Hello. I have a mysql database with an 'entrytime' field which contains the unix timestamp the record was added. How do I create a mysql query to select all records for a given month/year? For example, if I wanted to create a query to display all records for October 2010 how do I go about it? I am at a loss and can't find my answer via google. Thanks in advance for any help! Hello phpfreaks.com, ive been wondering all week howto do so. If i make a mysql_query and chooses all emails, i only get my own. But how can i choose all the users registered in the database`? best regards William Pfaffe If a user is on Page X, but not logged in, when they log in to my website, I want them to return back to Page X (in this example). To handle this, I am adding this code to the top of each webpage... Code: [Select] // Set current Script Name. $_SESSION['returnToPage'] = $_SERVER['SCRIPT_NAME']; And then as part of my Log In script I have... Code: [Select] // Redirect User. if (isset($_SESSION['returnToPage'])){ header("Location: " . BASE_URL . $_SESSION['returnToPage']); }else{ // Take user to Home Page. header("Location: " . BASE_URL . "index.php"); } What do you think about this approach? Thanks, Debbie Hey all. My site has a config database table that has a column showlogin to set whether or not login functionality is enabled. I'm playing around with MySQLi, Classes, and Returns. My return is always 1. Where am I going wrong? test.php <?php // Start Session session_start(); // Production Settings ini_set('display_errors', 1); mysqli_report(MYSQLI_REPORT_ALL); include 'db.php'; $mysqli = new mysqli($host, $user, $pass, $db); class styles { function showlogin($show) { global $mysqli; $select = $mysqli->query("SELECT showlogin FROM config LIMIT 1"); $value = $select->fetch_object(); if ($value->showlogin = 1) { return 1; } return 0; } } $login = new styles(); echo $login->showlogin($show); ?> Hi Everyone,
My name is Raoul Grosser, live in The Netherlands.
I'm a front/backend developer working with AngularJS and Bootstrap and Symphone2.
I've been writing PHP code for over 4 years now my focus is on opensource projects.
If you have any question, please let me know!
return (int) $value VS return $value
What is the purpose of using int in a bracket? return (int) $value
Which is the best and safest method?
Thank you
Hello First of all i am very weak about OOP and classes in php. I am learning now but i stuck with very silly problem. My codes are below. <?php class myTestClass { function __construct() { $this->OldName("This is Old Name"); } function OldName($VeryOld) { if($VeryOld == "This is Old Name") $this->NewName(); else $VeryOld = "Something Wrong"; return $VeryOld; } function NewName() { echo "This is Brand New Name"; } } $i = new myTestClass(); ?> if i send value to OldName "This is Old Name" then codes works fine. But if i send "This is Old Nameeee" then does not appear anything. what i want to do is print "Something Wrong" text if i enter different value. I have no idea what return do and how it do? How to retrieve/print "Something Wrong"? i can do that with echo but i want to transfer result of return to another function. Really appreciate for any help/idea. I am trying make my code display different things depending on how many rows are returned This is my code Code: [Select] <?PHP include 'db_con.php'; $month = date("n"); $day = date("j"); $sql = mysql_query("SELECT * FROM table WHERE month = $month AND day = $day ")or die(mysql_error()); while($row = mysql_fetch_array($sql) ) if (mysql_fetch_array($row = 1 ) ) ///THIS IS AN ERROR BUT IF ONE ROW RETURNED THEN THIS { echo "ONE THING"; } elseif (mysql_fetch_array($row >1 ) )////IF > 1 ROW RETURNED THAN THIS { echo"TWO THINGS"; } else { echo "SOMETHING ELSE "; } ?> I have tried several variations of the above code but cannot get it to work. Thanks for any help anyone can give me. Hi all, I am kinda stuck on the return() statement in the php.net manual about control structures. (http://au.php.net/manual/en/function.return.php) All I see is notes on when not to use it and some scary examples with loads of foo and bar but, it's hard to find out when it would be nice to use it. At the moment i am thinking its another way of echo, but I bet that's wrong. If someone could enlighten me a bit on when return() is useful I would be very happy since i see it more often everyday. CHeers! Hello again. I use echo "Rating:".$json['Rating]."/10"; and get in return: 7.5/10 - it's ok. But I want to replace 7.5 with 75.png (image), 6.3 with 63.png, 9.4 with 94.png... hope u understand. Know someone how I can do this? Thanks. Hi all, can you give me suggestion how to return value from function like this Code: [Select] function returnArray(){ for($i=1; $i<=3; $i++){ return $i; //how to return this as array?? } } when I code "echo" inside the function then call the function it give me output => 123 but when I code "return" inside the function, it will give output => 1 Can you suggest me how to output it as array? Hi, I have setup my paypal payment method for a shopping cart on my site, all is well but in order for my server to flag an invoice as paid, the user must return to my website after paying and the query string in the url give the script the go ahead to mark it as paid which in turn alerts the appropriate department that its ok to source the order. ~The problem is, if the user for whatever reason skip the redirect back to my site, the invoice is remain 'unpaid' and has to be changed manually when the payment has been checked in the account. As you might imagine this is a bit of a problem because not only can it cause quite a delay, it also requires manually changing values which can lead to other problems. So if there is a better way i would appreciate the info, thanks a lot. Say I have my login form which then when person tries to log in with the wrong user name and password and sent straight back to the log in page, how do I send back they got the password and/or username wrong. I read somewhere in some code header("location: index.php&$errorvariable"); or something like that. I haven't tested it, not even sure how to get it to work on the index, would I just use an isset on a get/post to check if it exists then echo the error? I have a form page (referred to as form.php) which is then processed via a submit button, the script then processes the data from the form.php and if it discovers an error it then sets a variable containing the error message my process page contains Code: [Select] if (empty($b_addr)) { $b_addr_error = "Address is required"; $check_failed = TRUE;} header("Location: form.php"); then my form.php contains Code: [Select] $b_addr_error = safe($_GET['b_addr_error']); if (isset($_POST['$b_addr_error'])) { echo "<div class='errorfont' align='center'>'".$b_addr_error."';</div>"; } but the variables do not get passed back to form.php from the process page, any ideas? Thank you. |