PHP - Get Page Url Minus Php Variables
Hey guys,
Was wondering if someone could point me on the right path here. I am able to get the page URL using: $url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; But was wondering if there was a way to drop the PHP variables attached to the URL. e.g. mysite.com/catalogue/?item=23 becomes mysite.com/catalogue/ Can anyone help me out? Thanks! Similar TutorialsHi I'm using SimpleXMLElement to work with a supplied XML file, problem is with the way the XML document is formatted. The document uses '-' (minus) in the element names instead of _ so when I go to read the values, nothing is returned: Code: [Select] $developer->developer-region; //returns nothing However if I change the sample XML document that I've been supplied to <developer_region></developer_region> and do Code: [Select] $developer->developer_region; //returns child elements This is not practical to manually change the document, is there a way to use '-' in the xml document? Thanks in advance Ste Hi Can someone point me in the right direction. I can force php to put a Plus(+) sign in front of positive numbers with printf('%0+4.2f',$x) But I cant get this to work inside <option>printf('%0+4.2f',$x)</option> tags Any help is greatly appreciated. hi , i want to select qty from master where id=$id , then i want to minus the qty = qty -1 and update in the query . here is my code . can tell me what went wrong ? Code: [Select] $query= "SELECT qty FROM master where id=$id"; $result = mysql_query($query,$dblink); while($myrow = mysql_fetch_row($result)) { qty -= 1; $query = "UPDATE master SET qty='$qty' WHERE id= $id"; $result = mysql_query($query,$dblink); } thanks Hi all I have a string called $voucher_code which is a value used to deduct or add value to a shopping cart. If the value is a minus I need it to show the minus sign, or if it's a plus value, it needs to show a plus sign. Here's my code: <strong>£ -".number_format(($voucher_code),2)."</strong> How do I modify the above code to show + instead of -- which it does at the moment? Many thanks for your help Pete Hi all I'm building a script which reads a XML document, and so far so good... until now! the document uses '-' extensively all the way through it (not something that I would have chosen) so to combat this I've used {}. The part of the document I am working on now, this simply does not work, and I really cannot see why... XML Code: [Select] <plot> <name-number>87</name-number> <price>183000</price> <bedrooms>4</bedrooms> <status>available</status> <summary>With three double bedrooms, including one en suite and a further bedroom plus family bathroom to the first floor,&nbsp;separate lounge and&nbsp;dining room with kitchen&nbsp;and utility to the ground floor, the Otter is a modern home with a great deal to offer growing families.</summary> <feature>Separate lounge and dining room</feature> <feature>Kitchen with utility room</feature> <feature>Integral garage</feature> <feature>En suite to master bedroom</feature> <property-type>detached-house</property-type> <media> <caption> </caption> <type>image</type> <filename>1855_Otter-WhitehirstGrange.jpg</filename> <indexno>1</indexno> </media> <media> <caption> </caption> <type>floorplan</type> <filename>1386_Otter-WhitehirstGrange.pdf</filename> <indexno>2</indexno> </media> <media> <caption> </caption> <type>brochure</type> <filename>284_brochure.pdf</filename> <indexno>3</indexno> </media> <style-name>Otter</style-name> </plot> PHP Code: [Select] echo $plot->{name-number}; // echoes nothing, should echo 87 echo $plot->price; // echoes 183000 echo $plot->bedrooms // echoes 4 echo $plot->{style-name} // echoes nothing, should echo Otter This is frustrating the hell out of me, and I cannot see why this would work everywhere else in the XML document but not here. Any ideas or help would be received with gratitude! Hi, I'm having trouble with this: Code: [Select] $date = date('d/m/y') ; echo $date; echo "<br/>"; $date1 = strtotime('date -1 month'); echo date('Y-m-d', $date1); My result looks like this: Current Date: 19/05/11 Date minus 1 month: 1970-01-01 I want it to look like this: Current Date: 19/05/11 Date minus 1 month: 2011-04-19 Hello, I've been struggling for days on this problem now. And I'm getting frustrated! I know that the answer is simple, and I've done it before but I cannot figure out what I'm doing wrong. What do I want? Well, I get a date from the database in this format: YYYY-MM-DD. I first want to distract one month from that and then set in into this form: YYYY, MM, DD. I've got this but it's not working (I've tried a lot different values). $transformdate = date("Y-m-d", strtotime("-1 month", $d_datevalue)); $startpoint = str_replace("-", ", ", $transformdate); Thanks, NLCJ How would I pass variables from one page to another without using forms or $_GET features. Let say I have page (1.php) where If define $secret_phrase = "open sesame";. On that page (1.php) I have multiple html links to multiple pages (2.php, 3.php, ...) if you click on the link to 2.php page I would like to pass the $secret_phrase as well without having it encoded into a link or using forms. Is there a way to do it? Thanks I insert a time value using the following code
$ti= ( !empty($_POST['time']) ) ? "'{$_POST['time']}'" : 'NULL';
I want to insert a second time value into a differen column which would be the same time minus 1 hour
something along the lines of :
$ti2= ( !empty($_POST['time']) ) ? "'{$_POST['time'] -1 hour}'" : 'NULL';
What would be the correct way to do it
Hi, I am a beginner with php and I am having a hard time understanding a section in my code. The part I dont get is why we have to minus 1 from the number being passed into the array. For example, $FaceNamePlural[$die1-1] I tried looking at it over and over but I'm still very confused. Can anyone help me on this...Thanks. 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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <?php $FaceNameSingular = array("one", "two", "three", "four", "five", "six"); $FaceNamePlural = array("ones", "twos", "threes", "fours", "fives", "sixs"); function CheckForDoubles($die1, $die2) { global $FaceNameSingular; global $FaceNamePlural; if($die1 == $die2) // doubles echo "The roll was double ", $FaceNamePlural[$die1-1], "<br />"; if($die1 != $die2) //not doubles echo "The roll was a ", $FaceNameSingular[$die1-1], " and a ", $FaceNameSingular[$die2-1], ".<br />"; } function DisplayScoreText($Score) { if($Score == 2) echo "you roll snake eyes! <br />"; if($Score == 3) echo "you roll loose duece! <br />"; if($Score == 5) echo "you roll fever five! <br />"; if($Score == 7) echo "you roll natural! <br />"; if($Score == 9) echo "you roll nina! <br />"; if($Score == 11) echo "you roll yo! <br />"; if($Score == 12) echo "you roll boxcars! <br />"; } $dice = array(); $dice[0] = rand(1,6); $dice[1] = rand(1,6); $Score = $dice[0] + $dice[1] ; echo "<p>"; echo "The total score for the roll was $Score . <br />"; CheckForDoubles($dice[0],$dice[1]); DisplayScoreText($Score); echo "</p>"; ?> </body> </html> Hello $row[longdescription] contains a description of a product (complete with HTML mark-up). I would like to display the first 250 characters in the results of a search. I would also like to remove any images that may crop up. This is what I have so far... Code: [Select] echo strip_tags(html_entity_decode(substr(preg_replace('/<img[^>]*>/Ui', '', $row[longdescription]), 0, 250))); The thing is (as you guys can probably already see), it also counts the HTML mark-up as characters and I get very different outputs (especially if an image occurs). I'd appreciate if you could advise me as to the correct way of doing this. Thank you Hello I have this login page with code Code: [Select] <?php header("Expires: Thu, 17 May 2001 10:17:17 GMT"); // Date in the past header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header ("Pragma: no-cache"); // HTTP/1.0 session_start(); //Below means if session database server crdentials is not set, require to use/set that connection then if (!isset($_SESSION['SESSION'])) require ( "../db_connection.php"); if($_SESSION['LOGGEDIN'] == TRUE) { header("Location: account.php"); exit; } $_SESSION['FORM_SUBMITTED'] = ""; $CRLF = chr(13).chr(10); $user_id = ""; if (isset($HTTP_GET_VARS["user_id"])) $user_id = $HTTP_GET_VARS["user_id"]; if ($user_id == '') { if (isset($_SESSION['user_id'])) $user_id = $_SESSION['user_id']; } //Validations $flg = ""; $error = ""; if (isset($HTTP_GET_VARS["flg"])) $flg = $HTTP_GET_VARS["flg"]; switch ($flg) { case "yellow": $error = "<font class=\"txt_main_str12_mar\"><BR>Your Account Has Not Been Verified.<BR>Check your email for Activation Instructions.<br>Click <a href=\"/courses/forgot_login.php\">here</a> to have the activation email resent.</font>"; break; case "red": $error = "<font class=\"txt_main_str12_mar\"><BR>That userid/password combination is not in our database.<br>Please Try Again.</font>"; break; case "blue": $error = "<font class=\"txt_main_str12_mar\"><BR>Your Session has Expired.<br>Please Login Again.</font>"; break; default: $error = " <br>"; } ?> <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Login Page</title> <script language="JavaScript"> <!-- function loadedPage() { } function submitForm() { if (isEmpty(document.forms[0].user_id.value)) { alert("Please enter your UserID."); bSubmit = false; return false; } if (isEmpty(document.forms[0].password.value)) { alert("Please enter your Password."); bSubmit = false; return false; } document.forms[0].submit(); } //--> </script> </head> <body><center><br /><br /> <form name="form1" method="post" id="form1" action="/php/sessions/login/login_processing.php"> <table> <tr> <td>User ID</td> <td><input type="text" name="user_id" id="user_id" value="<?php echo $user_id ?>" size="24" maxlength="30" /></td> </tr> <tr> <td>Password</td> <td><input type="password" name="password" id="password" size="24" maxlength="30" /></td> </tr> <tr> <td> </td> <td><input type="submit" name="Submit" value="Submit" onclick="submitForm();" /></td> </tr> </table> </form> </center> </body> </html> and login processing page with code Code: [Select] <?php header("Expires: Thu, 17 May 2001 10:17:17 GMT"); // Date in the past header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header ("Pragma: no-cache"); // HTTP/1.0 session_start(); //Below means if session database server crdentials is not set, require to use/set that connection then if (!isset($_SESSION['SESSION'])) require ( "../db_connection.php"); // reset session variables... $_SESSION['user_id'] = ""; $_SESSION['LOGGEDIN'] = false; $_SESSION['EMAIL'] = ""; $_SESSION['FNAME'] = ""; $_SESSION['LNAME'] = ""; // initialize variables... $user_id = ""; $password = ""; $email = ""; // make sure post parameters were sent... if (isset($HTTP_POST_VARS["user_id"])) $user_id = addslashes($HTTP_POST_VARS["user_id"]); if (isset($HTTP_POST_VARS["password"])) $passwd = addslashes($HTTP_POST_VARS["password"]); $_SESSION['user_id'] = $user_id; // form variables must have something in them... if ($user_id == "" || $password == "") { header("Location: ./login_page.php?flg=yellow&user_id=".$user_id); exit; } ?> I'm having problem with the last piece of code above, it's redirecting me eventhough I have entered a value on the userid and password from the login page... Hey people, I know this is going back to basics but i'm just learning and want to make sure I do it all correctly. I want to pass variable's from one page to another. Now currently say I wanted to hold the users age and email address from his record in the database from page A and pass it to page B for it to be displayed back to him I would store each in their own session variable (so for the purpose of the explanation session_user_email=me@email.com and session_user_age=18. On page B I would then call the session and store it in a variable then destroy the session. Just out of curiosity is the the best way to pass the data? or should i use another method? i've read about session hijacking and i'm now worried about holding personal data within a session so i'm wondering what other people do?? Cheers I have a php script which is viewed with ajax. The script does some important things and I want to make sure that it's viewed by only the ajax and now the user so I was thinking I'd need to pass a code from the main page using a GET in either php or more likely javascript, as I don't want the user to be able to see the code and then be able to just copy it and view the script with it. I've tried to sort this by saving Math.random() to the database by using ajax using a separate file, then underneath it use it to access the file like this: Code: [Select] function saveCode() { var xmlHttp = connect(); if(xmlHttp != false) {var code = Math.random(); xmlHttp.open('GET', '/inc/battle/saveCode.php?i='+code, true); xmlHttp.onreadystatechange = function() { if(xmlHttp.readyState == 4) { battleLog = xmlHttp.responseText; battleList = battleLog.split('\n'); battleCount = battleList.length; addLine(); } } xmlHttp.send('null'); } This would save the code to the database, then with a separate function, namely endBattle() the variable code would be used to access a file called endBattle.php?i= where this script would compare the code from the GET variable to the code in the database. However, I realised before finishing this that the user could manually set the code to whatever they want through the saveCode.php page, then view the endBattle.php Does anyone have any ideas how else I could validate my endBattle.php page so that users couldn't view it in their browser to run it? Forgive me if this is in the completely wrong forum, I just thought I'd see whether there were any php methods of doing this. Thanks! i have problem : I have a page(page1) that sends details to the login page(page2) to check if the details are correct checks these and if there is a match it directs them to the next page.(page 3) The page1 sends 3 details to the page 2 that are stored into variavles but as there is no submittion when they check the details how do i then send these details onto the page 3 ? Is there anyway I can like "exit" the variables so i can use the same variable name later in the page? ok ive searched everywhere online for a webform that is in 2 or more parts... so the first page passes variables to the second page then saves info for next page to submit all info from both pages of application to a server etc. ideally my page would look like this... page 1: small form with 3 fields: 1. type of loan: [dropdown menu] a. Cashout refinance b. Purchase 2. Property type: [dropdown menu] a. single family b. multi-unit, etc. 3. Property State: [dropdown menu] a. states....... [Next Page] <---Button page 2: a few more fields: (for example:) 1. Approximate credit score [dropdown menu] a. 650-700 etc.... 2. Phone number [textbox] 3. email address [textbox] [submit button] I know its possible, i just need to be put on the path... any help is much appreciated! Hi all, I've been trying to create a page whereby a user enters a few details which is then emailed, but I'm seriously stuck on one issue. First page - console type Second page - serial number Only two steps at the moment as I need to figure it out. I'm passing everything into a variable from a post(ed) form. It appears on the next page fine, as I've been testing, but the details entered on the first page don't show on the third, however, the details from the second page do! Here is the code I have: Code: [Select] <?php switch ($step) { case "1": ?> <table width="75%" align="center"> <tr> <td colspan="2" valign="top"> <form action="?step=2" method="post" id="consoletype">Please select your console type<br /></td></tr> <tr><td align="center" valign="top" width="50%"> <label>Xbox 360 Original (Beige or Black)<br /><img src="images/xbox360orig.gif" width="250" height="250"><br /><input class="button" type="radio" name="console" value="xboxorig" /></label></td> <td align="center" valign="top" width="50%"><label>Xbox 360 Slim<br /><img src="images/xbox360slim.gif" width="250" height="250"><br /><input type="radio" name="console" value="xboxslim" /></label></td> </tr> <tr> <td colspan="2"> <input type="submit" value="Next"> </form> </td> </tr> </table> <?php echo $code; include("footer.php"); echo $code2; include("compat.php"); echo $code3; case "2": $console = $_POST['console']; echo $console; ?> Please enter your Xbox 360 Serial Number:<br /> <form action="?step=3" method="post"> <input name="serialno" type="text" size="20" maxlength="20"> <input type="submit" value="Next"> </form> <?php echo $code; include("footer.php"); echo $code2; include("compat.php"); echo $code3; case "3": echo "<br />"; $serialno = $_POST['serialno']; echo $serialno; echo $console; echo $code; include("footer.php"); echo $code2; include("compat.php"); echo $code3; } ?> I do understand it's messy at the moment but I don't see much point beautifying everything until I can solve this problem! Cheers! I'm new to PHP and I have an html page I would like to pull specific data into certain areas on the page that I will modified for php. Here are some details. The page is a static html page that has the prices of 40+ products in a standard <li> list. When I update the prices in our database through our shopping cart, I have to change these prices manually in the html. https://www.novon.co...mic_mixers.html. It would be great if I could link the field for Base_Price in the products table to each affiliated <li> tag, I am pulling all the data I need into ($results) and can display it all but I don't know how to get just the single products Base_Price in my <li> tag. <?=$row['Base_Price'] ?> I know this code is not correct but to get the point across, can I create a variable that I define in each <li> tag with a statement like,,,, <?=$row['Base_Price with Product_Code=123456'] ?> I could create a new SQL query for each <li> like "SELECT Base_Price from Products WHERE Product_Code='123456' ", but that's a lot of calls to the DB and a lot of code on the page. And just so I weed out the hard core coders, I can not rebuild the entire page. This is too big of a project for me and my limited coding with PHP. Can anyone help?? Thanks in advance Michael Is there any way to access a variable that is not assigned until further down the page eg: echo $myname; $myname = 'batman'; // clearly my real name which is why I am so poor at coding Thanks |