PHP - Authenticating Rest Apis To Your Server. How Do You Do It?
Do you use the OS userids or do you keep them separate in MYSQL? Must users login to a website and request a token to use for REST API requests? Did you use a framework provided method? I need something ultra-simple Similar TutorialsI really don't understand the point of an API. I am totally lost on this one. I have never in my life used JSON and barely touched Javascript so I'm already quite behind the curve but this was my understanding of the "purpose" of an API;
You have some data in a database that others might find useful so you write a script that allows people to go in and pull data from it.
So why aren't these APIs just built using PHP? If I have a database table of first names, last names and email-addresses, and for some reason I want other people on the internet to be able to get at that, then why don't I just write a one-page script that list them all out? Then all the user has to do is "include" it in their code, right?
That's probably really over-simplistic, and I am surely missing the point. There must be a point, but I cannot find a single source anywhere with an actual decent explanation of this. What am I missing?
You never know, perhaps you're all about to tell me that most APIs are built using PHP and what I've described is pretty much it. But everything I research leads to a dead end because they all refer to one another;
Example 1 - "Oh JSON is freaking awesome. I use it because it's awesome. It's awesome for work working with APIs".
Example 2 - "Oh, APIs, yeah, you totally have to have APIs. All you have to do is use JSON. It's awesome".
Not direct quotes, but close enough! Seriously, help me out. I have a lot of public data on my server and I am positive that someone can make good use of it. But how?
Hi all,
I'm working on a project involving an orders set of APIs, and having trouble coming up with the best logic to handle this - with the smallest amount of overhead and client facing slowness. Here's the jist of what I'm looking at...
There are 21 API methods to pull different types of orders, and each of them handle paging by requesting a number of records (10 - 500), and a page number. So I could say in my URI, "page-no=1&no-of-records=50", followed by "page-no=2&no-of-records=50", to get subsequent records. The API will return in each call the total records returned as well as the total records in their database.
Now, I want to insert all of this into my database, and so that means something like 21 APIs * 3 SQL requests each = 63 sql queries (check it exists, if so update - else insert).
This seems to me like way too much work for a client facing application. Any suggestions?
Has anyone ever used these. I want to develop a tool so users of my site can invite there friends. Hi, Trying PostgreSQL for the first time but not making much progress. Get peer failure when not including a host and Ident error when including a host. Never heard of Ident authentication until today and don't know for sure if I even have such a server running. Using Centos7, PHP7.4 using remi's repo, and PostgreSQL 12 from their repo. Any thoughts? Thanks
try { //use Unix domain sockets $dbh = new PDO("pgsql:dbname=postgres", 'postgres', 'secret'); } catch(Exception $e){ echo($e->getMessage().PHP_EOL); } try { $dbh = new PDO("pgsql:host=localhost;dbname=postgres", 'postgres', 'secret'); } catch(Exception $e){ echo($e->getMessage().PHP_EOL); } try { $dbh = new PDO("pgsql:host=127.0.0.1;dbname=postgres", 'postgres', 'secret'); } catch(Exception $e){ echo($e->getMessage().PHP_EOL); }
SQLSTATE[08006] [7] FATAL: Peer authentication failed for user "postgres" SQLSTATE[08006] [7] FATAL: Ident authentication failed for user "postgres" SQLSTATE[08006] [7] FATAL: Ident authentication failed for user "postgres"
Does anyone know of a json or php method of authenticating a youtube user without using zend? Code: [Select] <?php $id = NULL; $username = 'myYouTubeAccount'; $url = 'http://gdata.youtube.com/feeds/api/users/%s/uploads?orderby=updated&max-results=8'; $xml = simplexml_load_file(sprintf($url, $username)); foreach ($xml->entry as $entry) : $kids = $entry->children('http://search.yahoo.com/mrss/'); $attributes = $kids->group->content[0]->attributes(); $flv = $attributes['url']; $attributes = $kids->group->player->attributes(); $link = $attributes['url']; $querystring = parse_url($link,PHP_URL_QUERY); parse_str($querystring, $id_temp); $id = $id_temp['v']; ?> <a href="<?=$link?>"> <img src="http://i4.ytimg.com/vi/<?=$id?>/default.jpg" /> </a> <?php endforeach; ?> Sorry if i posted this in the wrong place but i dident see anthing about Active Directory or Security Questions
But has anyone used Active Directory as their User Database? Has anyone even tryed braking Active Directory with injection attacks?
Notes that i have found so far:
Php Sends to CMD first so encode userdata in base64 as a transport layer
$rand is a random number to prevent users from useing Success: as a ligitimate user
You will need to clean up the many many spaces that powershell sends back as it is a concole
Special Charicters dont need to be escaped
I am using
Win 2008 RC2
Apache
PHP (of course)
Powershell
Active Directory
PHP Script
$psScriptPath = 'C:/Apache/PSScripts/' //Path outside Website Root $rand = mt_rand(mt_getrandmax(),mt_getrandmax()); //UTF-8 Standard only $username = utf8_decode($_POST["username"]); $password = utf8_decode($_POST["password"]); $base64_username = base64_encode($username); //Transport Layer Base64 $base64_password = base64_encode($password); //Transport Layer Base64 //The danger happens here as it is sent to powershell. $query = shell_exec('powershell.exe -ExecutionPolicy ByPass -command "' . $psScriptPath . '" < NUL -rand "' . $rand . '" < NUL -base64_username "' . $base64_username . '" < NUL -base64_password "' . $base64_password . '" < NUL');// Execute the PowerShell script, passing the parametersPowershell Script #*============================================================================= #* Script Name: adpwchange2014.ps1 #* Created: 2014-10-07 #* Author: #* Purpose: This is a simple script that queries AD users. #* Reference Website: http://theboywonder.co.uk/2012/07/29/executing-powershell-using-php-and-iis/ #* #*============================================================================= #*============================================================================= #* PARAMETER DECLARATION #*============================================================================= param( [string]$base64_username, [string]$base64_password, [string]$rand ) #*============================================================================= #* IMPORT LIBRARIES #*============================================================================= if ((Get-Module | where {$_.Name -match "ActiveDirectory"}) -eq $null){ #Loading module Write-Host "Loading module AcitveDirectory..." Import-Module ActiveDirectory }else{ write-output "Error: Please install ActiveDirectory Module" EXIT NUL Stop-Process -processname powershell* } #*============================================================================= #* PARAMETERS #*============================================================================= $username = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($base64_username)) $password = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($base64_password)) #*============================================================================= #* INITIALISE VARIABLES #*============================================================================= # Increase buffer width/height to avoid PowerShell from wrapping the text before # sending it back to PHP (this results in weird spaces). $pshost = Get-Host $pswindow = $pshost.ui.rawui $newsize = $pswindow.buffersize $newsize.height = 1000 $newsize.width = 300 $pswindow.buffersize = $newsize #*============================================================================= #* EXCEPTION HANDLER #*============================================================================= #*============================================================================= #* FUNCTION LISTINGS #*============================================================================= Function Test-ADAuthentication { Param($Auth_User, $Auth_Pass) Write-Output "Running Function Test-ADAuthenication" $domain = $env:USERDOMAIN Add-Type -AssemblyName System.DirectoryServices.AccountManagement $ct = [System.DirectoryServices.AccountManagement.ContextType]::Domain $pc = New-Object System.DirectoryServices.AccountManagement.PrincipalContext($ct, $domain) $pc.ValidateCredentials($Auth_User, $Auth_Pass).ToString() } #*============================================================================= #* SCRIPT BODY #*============================================================================= Write-Output $PSVersionTable Write-Output " " $authentication = Test-ADAuthentication "$username" "$password" if ($authentication -eq $TRUE) { Write-Output "Success:$rand Authentication" }elseif ($authentication -eq $FALSE) { Write-Output "Failed:$rand Authentication" }else { Write-Output "Error: EOS" EXIT NUL Stop-Process -processname powershell* } #*============================================================================= #* SCRIPT Exit #*============================================================================= Write-Output "End Of Script" EXIT NUL Stop-Process -processname powershell* <?php //check for required fields from the form if ((!$_POST['username']) || (!$_POST['password'])) { header("Location: auth1.php"); //header("Location: auth1.php");
exit;
// Create connection
$message=""; } ?> When I enter any username ad password the code from auth2.php (the code above allows a connection anyway) I am attempting to redirect users back to auth1 if there is an incorrect username or password I am moving a site from another server to a new one. I have changed all the code snippets to reflect the new server and the new database but for some reason when I come to login it will not take me further. I know that the code has connected to the database as I have a userlog table on there telling me I when I logged in last. elow is my login.php (there is obviously more than the code included) Code: [Select] <? require 'include/common.inc.php'; require 'include/session.inc.php'; if(($u_username != "") || ($u_password != "")) { $funcResult = authenticateUser($u_username, $u_password, $chkRemember); if(!$funcResult->returnValue) { header("Location: login.php?msg=" . $funcResult->errorMessage); echo "ERROR: " . $funcResult->errorMessage; } else { if($artid!="") { header("Location: news/readarticle.php?artid=$artid"); } else { if($funcResult->errorMessage == "M") { header("Location: members/index.php"); exit; } elseif($funcResult->errorMessage == "B") { header("Location: business/index.php"); exit; } $msg = "Invalid UserName/Password"; } } } ?> <html> <head> <title>Welcome to Newquay Uncovered</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="images/style.css" rel="stylesheet" type="text/css"> <script language="Javascript"> <!-- function validate(frm) { for(i=0;i<frm.length;i++) { if((frm.elements[i].type == "text" || frm.elements[i].type == "password") && frm.elements[i].value == "") { alert("Please fill in the required details"); frm.elements[i].focus(); return false; } } return true; } //--> </script> Here is Common Code: [Select] <? require '/home/xmasphot/public_html/www.newquayuncovered.com/include/db.inc.php'; // require '/dump/ldev/newquayuncovered/revamped/include/db.inc.php'; // USER UPLOAD FOLDER $uploaddir = "/home/xmasphot/public_html/www.newquayuncovered.com/members/uploads/"; // $uploaddir = "/dump/ldev/newquayuncovered/revamped/members/uploads/"; $pic_path = "/members/uploads/"; $nophoto = "/images/nophoto.jpg"; $pending = "/images/pending.jpg"; $fromemailaddresss = "help@newquayuncovered.com"; global $sportspicpath; global $sports_rpicpath; // $sports_rpicpath = "/dump/ldev/newquayuncovered/revamped/admin/sports/images/"; // $sports_picpath = "/newquayuncovered/revamped/admin/sports/images/"; $sports_rpicpath = "/home/xmasphot/public_html/www.newquayuncovered.com/admin/sports/images/"; $sports_picpath = "/admin/sports/images/"; if ($uid == "") { $uid = 0; } function sendErrorPage($mesg) { echo "Error Generated: <BR>$mesg"; exit; } function getDateString() { /* The function getDateString() returns the current date in the * format YYYY-MM-DD. This function is used when inserting date * columns into MySQL table */ return date(Y-m-d); } function getCountry($chk) { $query = "SELECT c_cid, c_cname FROM nq_country ORDER BY c_cname"; $results = mysql_query($query); echo "<option value=''><-- Select --></option>"; while($row = mysql_fetch_object($results)) { if($chk == $row->c_cid) { echo "<option value='$row->c_cid' selected>$row->c_cname</option>\n"; } else { echo "<option value='$row->c_cid'>$row->c_cname</option>\n"; } } } function getGender($chk) { echo "<option value=''><-- Select --></option>\n"; if($chk != "" && $chk == 0) { echo "<option value=0 selected>Female</option>\n"; } else { echo "<option value=0>Female</option>\n"; } if($chk == 1) { echo "<option value=1 selected>Male</option>\n"; } else { echo "<option value=1>Male</option>\n"; } } function getSexuality($chk, $type="") { $arrVals = array( "R" => "Rather Not Say", "S" => "Straight", "O" => "Open Minded", "G" => "Gay/Lesbian", "B" => "BiSexual" ); if($type == 1) { echo $arrVals[$chk]; return; } echo "<option value=''><-- Select --></option>\n"; foreach($arrVals as $abbr=>$val) { if($abbr == $chk) { echo "<option value='" . $abbr . "' selected>" . $val . "</option>\n"; } else { echo "<option value='" . $abbr . "'>" . $val . "</option>\n"; } } } function getDOB_Date($chk) { echo "<option>--</option>\n"; for($i=1; $i<=31; $i++) { if($chk == $i) { echo "<option value=$i selected>$i</option>\n"; } else { echo "<option value=$i>$i</option>\n"; } } } function getDOB_Month($chk) { echo "<option>--</option>\n"; $arr_Month = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); $i = 1; foreach ($arr_Month as $temp) { if($chk == $i) { echo "<option value=$i selected>$temp</option>\n"; } else { echo "<option value=$i>$temp</option>\n"; } $i++; } } function getDOB_Year($chk) { echo "<option>--</option>\n"; for($i=1960; $i<=1999; $i++) { if($chk == $i) { echo "<option value=$i selected>$i</option>\n"; } else { echo "<option value=$i>$i</option>\n"; } } } function getDBConnection() { global $hostName, $databaseName, $userName, $password, $con; // Get a persistent database connection if(!($link = mysql_pconnect($hostName, $userName, $password))) { return new Function_Result("Internal Error: Could not open database connection", null); } // Select mysql database if(!mysql_select_db($databaseName, $link)) { return new Function_Result("Internal Error: Could not select database",null); } return new Function_Result(null, $link); } function logout() { global $uid; global $username; global $isAuthenticated; global $userType; session_start(); global $REMOTE_ADDR; // Get DB Connection $funcResult = getDBConnection(); if($funcResult->returnValue == null) { return $funcResult; } $link = $funcResult->returnValue; $updStmt = "UPDATE nq_userlog SET ul_online_status=0 ,ul_last_logout=now() ,ul_last_logon_ip='$REMOTE_ADDR' WHERE ul_ulid='$uid'"; if(!mysql_query($updStmt, $link)) { return new Function_Result("Cannot update log.", null); } session_unregister("uid"); session_unregister("username"); session_unregister("isAuthenticated"); session_unregister("userType"); return new Function_Result(null, true); } class Function_Result { var $errorMessage; var $returnValue; function Function_Result($errMessage, $retValue) { $this->errorMessage = $errMessage; $this->returnValue = $retValue; } } function validateusername($u_username){ $u_username = trim($u_username); $funcResult = getDBConnection(); if($funcResult->returnValue == null) { return $funcResult; } $link = $funcResult->returnValue; $selectUserStmt = "SELECT u_uid,u_password,u_email FROM nq_user WHERE u_username='$u_username'"; if(!($result = mysql_query($selectUserStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query", null); } if(!($row = mysql_fetch_object($result))) { return new Function_Result("Invalid UserName", null); } return new Function_Result(null,$row); } function dynamicpictures() { $funcResult = getDBConnection(); if($funcResult->returnValue == null) { return $funcResult; } $link = $funcResult->returnValue; $selectUserStmt = "SELECT * FROM nq_pictures LEFT JOIN nq_user on pic_uid=u_uid WHERE pic_approval=1 AND pic_folder=0 AND pic_adult=0 AND pic_filename!='' AND pic_default=1 ORDER BY pic_date DESC LIMIT 5"; if(!($result = mysql_query($selectUserStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query", null); } return new Function_Result(null,$result); } function msgStatus($uid) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT COUNT(*) FROM nq_message WHERE msg_to_uid=$uid AND msg_status=0"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } if(!($row = mysql_fetch_row($result))) { return new Function_Result("Internal Error: Could not assign record", null); } return new Function_Result(null, $row); } function getContact_country() { $query = "SELECT c_cname FROM nq_country ORDER BY c_cname"; $results = mysql_query($query); echo "<option value=''><-- Select --></option>"; while($row = mysql_fetch_object($results)) { echo "<option value='$row->c_cname'>$row->c_cname</option>\n"; } } function getState($ud_cid) { if ($ud_cid==130) { $qry = "limit 0, 54 " ;} elseif ($ud_cid==127) { $qry= "limit 55, 66"; } else { echo "<option value=''><-- Not Applicable --></option>"; return; } $query = "SELECT s_sid, s_sname FROM nq_state $qry" ; echo "<option value=''><-- Please Choose --></option>"; $results = mysql_query($query); while($row = mysql_fetch_object($results)) { echo "<option value='$row->s_sid'>$row->s_sname</option>\n"; } } function selectedstates($ud_cid, $chk) { if ($ud_cid==130) { $qry = "limit 0, 54 " ;} elseif ($ud_cid==127) { $qry= "limit 55, 66"; } else { echo "<option value=''><-- Not Applicable --></option>"; return; } $query = "SELECT s_sid, s_sname FROM nq_state $qry" ; echo "<option value=''><-- Please Choose --></option>"; $results = mysql_query($query); while($row = mysql_fetch_object($results)) { if($chk == $row->s_sid) { echo "<option value='$row->s_sid' selected>$row->s_sname</option>\n"; } else { echo "<option value='$row->s_sid'>$row->s_sname</option>\n"; } } } function getindexpagecontent($indexpageid) { $funcResult = getDBConnection(); if($funcResult->returnValue == null) { return $funcResult; } $link = $funcResult->returnValue; $selectStmt = "Select * from nq_config where con_conid='$indexpageid'"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query $selectStmt", null); } return new Function_Result(null,$result); } function getTop_latest_news($limit=2) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt_Top_latest_news = "SELECT *, CONCAT(LEFT(nwa_content, 90), '...') AS nwa_content FROM nq_newsarticle WHERE (nwa_topstories in (1,2,3)) and nwa_status='1' ORDER BY nwa_topstories ASC limit 0,". $limit; if(!($result_Top_latest_news = mysql_query($selectStmt_Top_latest_news, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt_Top_latest_news", null); } return new Function_Result(null, $result_Top_latest_news); } function Display_Admin_lst_evt() { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt_lst_evt = "SELECT *, DATE_FORMAT(evt_from_date, '%b %d, %Y %h:%i %p') AS evt_fromdate, DATE_FORMAT(evt_to_date, '%b %d, %Y %h:%i %p') AS evt_todate FROM nq_events WHERE evt_uid=0 order by evt_evtid desc limit 0,2"; if(!($result_lst_evt = mysql_query($selectStmt_lst_evt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query $result_lst_evt", null); } return new Function_Result(null, $result_lst_evt); } function get_News_links($name,$limit) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt_Newslink = "SELECT *, CONCAT(LEFT(nwa_content, 50), '...') AS content, CONCAT(LEFT(nwa_title, 50), '...') AS title FROM nq_newsarticle left join nq_newscategory on nwc_nwcid=nwa_nwcid WHERE nwc_name='$name' order by nwa_createdate desc limit 0 , ". $limit; if(!($result_Newslink = mysql_query($selectStmt_Newslink, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt_Newslink", null); } return new Function_Result(null, $result_Newslink); } function getNightlife_title() { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_nightlife WHERE nl_parent !=0 ORDER BY nl_lastupdated desc"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getNightlife_details($nl_nlid) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_nightlife where nl_parent !=0 AND nl_nlid = '$nl_nlid'"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getNightlife_homepage_details($nl_nlid) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_nightlife where nl_parent !=1 AND nl_nlid = '$nl_nlid'"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getNightlife_title_topten() { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_nightlife where nl_parent !=0 ORDER BY nl_lastupdated desc limit 0,10"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getSection($id) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_section where sec_secid='$id'"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getTop_sectionStories($id) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_sectionstory WHERE ssty_secid='$id' and ssty_position !='0' ORDER BY ssty_sstyid desc limit 0,3"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getTopLink($id) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_sectionlinks WHERE slnk_secid='$id' ORDER BY slnk_lastupdated desc"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getAllStories($id) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_sectionstory WHERE ssty_secid='$id' ORDER BY ssty_lastupdated desc"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getStorydetails($id) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_sectionstory where ssty_sstyid='$id'"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getAllLink($id) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_sectionlinks left join nq_section on sec_secid=slnk_secid WHERE slnk_secid='$id' ORDER BY slnk_slnkid desc"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getLinkdetails($id) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_sectionlinks WHERE slnk_slnkid='$id'"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getTopBeaches($limit) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; if ($limit == "") { $selectStmt = "SELECT * FROM nq_beaches where bch_position !='0' order by bch_position asc"; } else { $selectStmt = "SELECT * FROM nq_beaches where bch_position !='0' order by bch_position asc limit 0, $limit"; } if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getBeachDetails($id) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_beaches where bch_bchid ='$id'"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getTopBeachsafety($limit) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; if ($limit == "") { $selectStmt = "SELECT * FROM nq_beachsafety where bs_position !='0' order by bs_position asc"; } else { $selectStmt = "SELECT * FROM nq_beachsafety where bs_position !='0' order by bs_position asc limit 0, $limit"; } if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getBeachSafetyDetails($id) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_beachsafety where bs_bsid ='$id'"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getTopSectionCategory($id) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_sectioncategory WHERE scat_secid='$id' and scat_position !='0' ORDER BY scat_position asc"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getAllSectionCategory($id) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_sectioncategory left join nq_section on scat_secid=sec_secid WHERE scat_secid='$id' and scat_position !=0 ORDER BY scat_position asc"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getAllSectionArticle($id,$cat) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_sectionlinks left join nq_section on sec_secid=slnk_secid WHERE slnk_secid='$id' and slnk_scatid='$cat' ORDER BY slnk_slnkid desc"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } return new Function_Result(null, $result); } function getUserTypeCheck($name) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT * FROM nq_user where u_username='$name'"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } if(!($row = mysql_fetch_object($result))) { return new Function_Result("Could not assign records.", null); } return new Function_Result(null, $row); } function getBigAdd($secid) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $selectStmt = "SELECT count(*) as rcount FROM nq_assingbanner LEFT JOIN nq_banner ON ban_banid=ab_banid WHERE ban_bannertype=1 AND ab_secid='".$secid."'"; if(!($result = mysql_query($selectStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query. <BR>$selectStmt", null); } $rowad = mysql_fetch_object($result); if ($rowad->rcount > 0) { $rd = rand(0,$rowad->rcount)-1; if($rd < 0){ $rd = 0; } $sqlad = "SELECT * FROM nq_assingbanner LEFT JOIN nq_banner ON ban_banid=ab_banid WHERE ban_bannertype=1 AND ab_secid='".$secid."' limit $rd,1"; $resultad = mysql_query($sqlad); if(mysql_num_rows($resultad) > 0) { $rowad = mysql_fetch_object($resultad); if($rowad->ban_target == "n"){ $target = "_blank"; } else { $target = "_self"; } $ret_value="<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr height=\"18\"><td height=\"62\" align=\"center\" valign=\"middle\"><a href =\"".$rowad->ban_page."\" target=\"".$target."\"><img src=\""; if($rowad->ban_image !='') { $ret_value.="/admin/images/ads/".$rowad->ban_image; } else { $ret_value.=$rowad->ban_url; } $ret_value.="\" border=\"0\" alt=\"".$rowad->ban_alttext."\"></a></td> </tr> </table>"; } return new Function_Result(null,$ret_value); } else { return new Function_Result(null,"<br>"); } } function getTwoSmallAdd($secid) { $funcResult = getDBConnection(); if(!$funcResult->returnValue) { sendErrorPage($funcResult->errorMessage); } $link = $funcResult->returnValue; $sqlad = "SELECT * FROM nq_assingbanner LEFT JOIN nq_banner ON ban_banid=ab_banid WHERE ban_bannertype=2 AND ab_secid='".$secid."' order by rand() limit 0,2"; $resultad = mysql_query($sqlad); $ret_value="<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"; while($rowad = mysql_fetch_object($resultad)) { if($rowad->ban_target == "n"){ $target = "_blank"; } else { $target = "_self"; } $ret_value.="<tr><td height=\"20\" valign=\"top\"><img src=\"/images/spcr.gif\" width=\"1\" height=\"1\"></td></tr><tr><td valign=\"top\"><a href=\"".$rowad->ban_page."\" target=\"".$target."\"><img src=\""; if($rowad->ban_image !='') { $ret_value.="/admin/images/ads/".$rowad->ban_image; } else { $ret_value.=$rowad->ban_url; } $ret_value.="\" border=\"0\" alt=\"".$rowad->ban_alttext."\"></a></td></tr>"; } $ret_value.="</table>"; return new Function_Result(null,$ret_value); } ?> And finally session Code: [Select] <? function setUserSession($u_uid, $u_username, $type) { global $uid; global $username; global $isAuthenticated; global $userType; session_start(); session_register("uid"); session_register("username"); session_register("isAuthenticated"); session_register("userType"); $uid = $u_uid; $username = $u_username; $isAuthenticated = true; $userType = $type; return true; } /***** SESSION HANDLING - ENDS HERE *****/ function authenticateUser($u_username, $u_password, $chkRemember) { $u_username = trim($u_username); $u_password = trim($u_password); $chkRemember=($chkRemember); if(($u_username == "") || ($u_password == "")) { sendErrorPage("The username/password you have entered is invalid. Please try again."); exit; } //$cryptPassword = crypt($u_password, CRYPT_STD_DES); // Get DB Connection $funcResult = getDBConnection(); if($funcResult->returnValue == null) { return $funcResult; } $link = $funcResult->returnValue; $selectUserStmt = "SELECT u_uid, u_username, u_type FROM nq_user WHERE u_username='$u_username' AND u_password='$u_password' and u_status!='U'"; if(!($result = mysql_query($selectUserStmt, $link))) { return new Function_Result("Internal Error: Could not execute SQL Query", null); } if(!($row = mysql_fetch_row($result))) { return new Function_Result("Invalid UserName/Password", null); } else { if ($chkRemember==1){ setcookie("newquay",$row[1],time()+60*60*24*30); } else { setcookie("newquay","",time()+60*60*24*30); } setUserSession($row[0], $row[1], $row[2]); global $REMOTE_ADDR; $updStmt = "UPDATE nq_userlog SET ul_last_updated=now(), ul_last_logon_ip='$REMOTE_ADDR', ul_online_status=1 WHERE ul_ulid=$row[0]"; if(!mysql_query($updStmt, $link)) { return new Function_Result("Cannot update log.<BR>$updStmt", null); } return new Function_Result($row[2], true); } } ?> The site isn't doing anything when I enter username and password, just bringing me back to the same page. Also I am unable to access the areas of the site that are only for registered members. Any help here would be greatly apprecaited, I have spent days on this now. Thanks in advance! There are a few other bugs that need ironing out too. You can view the site at www.newquayuncovered.com Hi all, I've been working on a new php application that my users will host on their own domains. I also have my company domain. What I'm trying to do is create a php file that will verify a value from MySQL DB on my company domain. All I'm waiting is to get a date from company domain MySQL. So, I have user.com/Program AND developer.com/ Developer.com has a DB named Allowed_User that store CompID and AuthDate. I'm trying to send CompID from User.com and return AuthDate from Developer.com. Basically, when their pay the fees, AuthDate is set to the 15th of next month. The program will then compare the AuthDate to the current date and either allow the script to continue or it will exit saying they haven't paid Not having any experience with this sort of thing, is there a better route to go? I was planning on verifying this date every time someone logs in, so atleast once per day/user/location. Any suggestions on how to do is would be greatly appreciated. Thanks, Ray <?php $myData = file_get_contents(""); $myObject = json_decode($myData); $myObjectMap = $myObject->result; ?> can i somehow build in that it only request every 5 minutes because if there are many users on the site it request too much? I want to create a REST API for my website. What I want to do is to display advertisements from my database on websites that I sell to clients. Their website will call my database for advertisements to display on their websites. Also, I am performing a site validity check where the client's site would send the site URL, site name, and site token to my database for validation. If it returns false then the site will not display as it will be invalid according to my database. I've been Googling this topic all day, but cannot seem to get my head around it. I want to set an API key on my website so that not just anybody can be querying my database. For the advertisement query, no parameters need to be sent from the client websites to my database. Can anyone offer some advice on how to do this? Hi guys. I'm new to php and struggleing with the REST POST for some reason.... I need to insert a contact into this accouting system http://help.saasu.com/api/#toc-http-post search for Example: Insert Contact. the data strcutre looks like: Code: [Select] <?xml version="1.0" encoding="utf-8"?> <tasks> <insertContact> <contact uid="0"> <salutation>Mr.</salutation> <givenName>John</givenName> <familyName>Smith</familyName> <organisationName>Saasy.tv</organisationName> <organisationAbn>777888999</organisationAbn> <organisationPosition>Director</organisationPosition> <email>john.smith@saasy.tv</email> <mainPhone> 02 9999 9999 </mainPhone> <mobilePhone> 0444 444 444 </mobilePhone> <contactID>XYZ123</contactID> <tags>Gold Prospect, Film</tags> <postalAddress> <street>3/33 Victory Av</street> <city>North Sydney</city> <state>NSW</state> <postCode>2000</postCode> <country>Australia</country> </postalAddress> <otherAddress> <street>111 Elizabeth street</street> <city>Sydney</city> <state>NSW</state> <postCode>2000</postCode> <country>Australia</country> </otherAddress> <isActive>true</isActive> <acceptDirectDeposit>false</acceptDirectDeposit> <directDepositAccountName>John Smith</directDepositAccountName> <directDepositBsb>000000</directDepositBsb> <directDepositAccountNumber>12345678</directDepositAccountNumber> <acceptCheque>false</acceptCheque> <customField1>This is custom field 1</customField1> <customField2>This is custom field 2</customField2> <twitterID>Contact twitter id</twitterID> <skypeID>Contact skype id</skypeID> </contact> </insertContact> </tasks> I only have to insert 3 mandatory fields whcih are in the below code snipit im using but nothings working... Code: [Select] //set POST variables $service_url = 'https://secure.saasu.com/webservices/rest/r1/tasks?wsaccesskey=<key removed>'; $curl = curl_init($service_url); $fileds = array( 'insertContact' => array( 'contact' => array( 'givenName' => urlencode('John'), 'familyName' => urlencode('Smith'), 'organisationName' => urlencode('Saasy.tv') ) ) ); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data); $curl_response = curl_exec($curl); curl_close($curl); $xml = new SimpleXMLElement($curl_response); Please help, I'm not sure what I'm doing wrong.... Here is the scenario. I created a niche market API which provides environmental data. The data is obtained by industrial controllers which don't monitor anything by default, and the API has additional endpoints which are used to instruct the industrial controllers to start monitoring some parameter so the API can then start storing the trend data. The API primarily responds with JSON, however, a couple of endpoints support CSV data. For humans/webclients to access the data, I also created a webserver application which can be added to a Concrete5 (C5) CMS. I tried to make as many of its endpoints do nothing except receive the webclient's request, add a JSON Web Token to it which contains a unique identifier, forward it to the API using cURL, and return the response as is to the webclient. To limit the scope which needed to be created for the C5 application, the API has endpoints to return JSON which is used by JavaScript on the webclient for client-side validation, endpoints (actually, a different domain) to return static JavaScript/CSS/etc, and endpoints to restructure the JSON data to some more suitable format. I now am looking at creating different applications which does not use C5, but either are 100% custom or use some other CMS such as Drupal, etc. While I tried to limit the scope implemented on the C5 application, I have much more than I desire and will need to duplicate much for any future application. The primary scope I would like to remove from the webserver application relates to the HTML views and consists of templates which create HTML from JSON, the JavaScript which interacts with the HTML, and to a lesser degree controllers to determine the type of view (i.e. a list of records or one specific detail record). While the API will only be managed by myself, the intent is that the C5, 100% custom, etc webserver apps are installed and managed by others. Ideally, there is some existing Composer package for transforming JSON to HTML which is CMS agnostic, however, I don't know whether such exists. Also, while not 100% necessary, ideally this functionality could exist on my server and not the individual web application's server. Whether I build it myself or use some existing package, I expect it will need to do something like the following: The various webserver apps will have some routing table to proxy the request either to my JSON API server (complete) or my new "HTML API Server" (remaining discusses this portion). This HTML API server would generate the content either by making a cURL request to the main JSON API, or better yet since likely located on the same server have routing functional to make direct calls to the JSON API's methods, and return something like the following: { "html": "<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Pharetra massa massa ultricies mi quis hendrerit dolor. Leo integer malesuada nunc vel risus commodo viverra.</div>", "javascript_files": [ "https://resources.myserver.com/someFile.js", "https://resources.myserver.com/someOtherFile.js" ], "css_files": [ "https://resources.myserver.com/someFile.css", "https://resources.myserver.com/someOtherFile.css" ] } The various applications would then take the HTML and resource files and insert them using their proprietary methods. EDIT. Also, thinking of using an IFRAME, however, definitely have concerns with doing so. My day job has nothing to do with software, however, am hoping to make it so. Before embarking on this task, I would like to know whether some existing framework exists and if not what general strategy (organization, caching, etc) I should take to develop it. Thanks Edited January 18 by NotionCommotionAdded IFRAME idea I have a PHP web system that store in a windows server. In the system, there is a function for user to upload files to another server (Shared server in Unix). When i try to upload a file, it gives warning: Warning: move_uploaded_file(\\unixserver/sharedfolder/upload/test.txt) [function.move-uploaded-file]: failed to open stream: Permission denied in C:\wamp\www\upload\index.php on line 40 For your information, my username has been assigned in xxx's group that has access to read and write on that folder. Besides, i'm able to open,create and delete files on that folder's server manually (samba). The safe mode setting is off. Does anybody has any idea why this thing happen? I'm trying to make a simple website where people register to my website. When the user doesn't fill anything inside the boxes they get a message "Please fill all required fields" on the register.php page On my local host require_once works good. It shows up.
But when i upload the files to my sever the require_once does not show up on the register.php It just refreshes and i dont get the message "Please fill all required fields"
This is the code that works in local host but not in a live server <?php require_once 'messages.php'; ?>
Here is my full code
Register page: <html> <?php require_once 'messages.php'; ?> <br><br> <form action="register-clicked.php" method="POST"> Username:<br> <input type="text" name="usernamebox" placeholder="Enter Username Here"> <br><br> Email:<br> <input type="text" name="emailbox" placeholder="Enter email here"> <br><br> Password:<br> <input type="password" name="passwordbox" placeholder="Enter password here"> <br><br> Confirm Password:<br> <input type="password" name="passwordconfirmbox" placeholder="Re-enter password here"> <br><br> <input type="submit" name="submitbox" value="Press to submit"> <br><br> </form> </html>
Register clicked <?php session_start(); $data = $_POST; if( empty($data['usernamebox']) || empty($data['emailbox']) || empty($data['passwordbox']) || empty($data['passwordconfirmbox'])) { $_SESSION['messages'][] = 'Please fill all required fields'; header('Location: register.php'); exit; } if ($data['passwordbox'] !== $data['passwordconfirmbox']) { $_SESSION['messages'][] = 'Passwords do not match'; header('Location: register.php'); exit; } $dsn = 'mysql:dbname=mydatabase;host=localhost'; $dbUser='myuser'; $dbPassword= 'password'; try{ $connection = new PDO($dsn, $dbUser, $dbPassword); } catch (PDOException $exception){ $_SESSION['messages'][] = 'Connection failed: ' . $exception->getMessage(); header('Location: register.php'); exit; }
messages.php <?php session_start(); if (empty($_SESSION['messages'])){ return; } $messages = $_SESSION['messages']; unset($_SESSION['messages']); ?> <ul> <?php foreach ($messages as $message): ?> <li><?php echo $message; ?></li> <?php endforeach; ?> </ul> Edited Wednesday at 12:49 AM by bee65 Hi, I am not a PHP programmer. I took on a new client with a simple PHP site, without any databases. The site is up and running on the web. I would like to get it running on my local machine for further development. I have latest version of WAMP installed, running Apache version 2.2.11 and PHP version 5.3.0 I created a directory in the WAMP "www" project directory and it shows up there like it's supposed to when I browse to "localhost" Problem: The home page of website displays text but no, images, styles, footer, header, nav links, etc. Here is the code for the home page: <? define("NAV","home"); require_once('local/local.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"> <head> <title>TITLE</title> <meta name="keywords" content=""> <meta name="Description" content=""> <? include("common/dochead.php"); ?> </head> <body onLoad="<? include('common/preloads.php'); ?>"> <!-- ============================ main ============================= --> <div id="main-frame"><div id="main" class="noCollapse"> <? include("common/sign.php"); ?> <div id="right-frame"> <? include("common/navigation.php"); ?> <div id="content-frame"> <div id="content"> <h1>Welcome</h1> <p>This is the content area. This is the content area. This is the content area. </p> </div><!-- end content --> </div><!-- end content-frame --> </div><!-- end right-frame --> <div class="clearFloats"></div> </div><!-- end main --></div><!-- end main-frame --> <? include("common/footer.php"); ?> </body> </html> Any help would be greatly appreciated. I have spent many hours on this. Regards Hi folks, I'm curious if I can for example, save a file from my server and it will save to all other servers - obviously if they accepted the connection first. It's for a software I developed and is almost complete and know there will be frequent updates to it. Instead of users downloading upates, I want the update files from my server to somehow synchronize to their server automatically? Anything called this?? Thanks for info. Hi, I am using the Google map API to display some businesses on a map - the sequence is map and below it a list of the establishments from a DB. Before I put the google map in, the list of establishments in the while table loop worked correctly. Now the map is there - that works, but the looping table doesnt display - I feel that it may be something to do with Code: [Select] <?php while ($row = mysql_fetch_array($result2, MYSQL_ASSOC)) { ?> new google.maps.LatLng(<? echo $row['latitude'] ?>, <? echo $row['longitude']?>), <?php ; } ?> and the second fetch array - Code: [Select] while ($row = mysql_fetch_array($result2, MYSQL_ASSOC)) Any Advice? Code: [Select] <?php // *******************************below is bit that selects hotels based on outcode of postcode and prints table with links to details pages $sql2 = "SELECT * FROM hotels WHERE (SUBSTRING_INDEX(est_postcode, ' ', 1)) IN ('$matches') "; $result2 = mysql_query($sql2) or die('query failed: ' . mysql_error()); $num_rows = mysql_num_rows($result2); echo "<p> Your search has found ".$num_rows . " establishment(s) </p>"; ?> <script type="text/javascript"> var berlin = new google.maps.LatLng(<? echo $lat2 ?>, <? echo $lng2 ?>); var neighborhoods = [ <?php while ($row = mysql_fetch_array($result2, MYSQL_ASSOC)) { ?> new google.maps.LatLng(<? echo $row['latitude'] ?>, <? echo $row['longitude']?>), <?php ; } ?> ]; var markers = []; var iterator = 0; var map; function initialize() { var mapOptions = { zoom: 12, mapTypeId: google.maps.MapTypeId.ROADMAP, center: berlin }; map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); } function drop() { for (var i = 0; i < neighborhoods.length; i++) { setTimeout(function() { addMarker(); }, i * 200); } } function addMarker() { markers.push(new google.maps.Marker({ position: neighborhoods[iterator], map: map, title:"Hello World!", draggable: false, animation: google.maps.Animation.DROP })); iterator++; } </script> <div id="map_canvas" style="width: 614px; height: 400px;">map div</div> <button id="drop" onclick="drop()">Drop Markers</button> <?php echo "<table id ='results' border=0>"; while ($row = mysql_fetch_array($result2, MYSQL_ASSOC)) { echo "<tr>"; echo "<td><a class='blueboldtitle' href='bandb.php?id=". $row["id"] . "'>" . ucwords(strtolower($row["est_name"])) ."</a></td><td>" . $row["est_postcode"] ."</td><td> ". $row["est_areacode"]." ". $row["est_landline"] ."</td><td><a href='bandb.php?id=". $row["id"] . "'>[More Info] </a></td>"; echo "</tr>"; } echo "</table>"; ?> I tried to find working tutorial for REST API and with these two frameworks but nothing what i found worked.Basicly i want to attach REST API
to a simple CRUD application.
So if anyone have links with good explanation that would be good.
Hello, I'm trying to use a rest-based card clearence service, but I don't know how to pass the information through the URL without using the form action attribute. I need to have a URL looking like this: index.php?p=checkout?service=cardAuth&msg_id=3864&num_md5=e2740266aab85558996a9a87fc561c0e&amount=24.99¤cy=GBP&api_key=739a720ade31ad2a14b30aa7b3a6b20e But at the moment, I have a URL looking like this: index.php?cardAuth=&title=Mr&fname=Alderton&sname=Arkie&ctype=mastercard&cnumber=5105105105105100&smonth=01&syear=07&fmonth=01&fyear=10&checkout=Check+Out There's a few more problems; - I can't get the card number to md5 - I don't know how to retreive a variable used in another file, which counts up the total amount due Here's my PHP: Code: [Select] <h2>Please enter your details</h2> <h3>All fields required</h3> <div id="checkout"> <?php if (isset($_GET['checkout'])){ $title = $_GET['title']; $fname = $_GET['fname']; $sname = $_GET['sname']; $ctype = $_GET['ctype']; $cnumber = md5($_GET['cnumber']); $syear = $_GET['smonth'] . $_GET['syear']; $fyear = $_GET['fmonth'] . $_GET['fyear']; $service = $_GET['cardAuth']; $amount = $_REQUEST[$total]; $msg = rand(1000,9999); $api = 'd41d8cd98f00b204e9800998ecf8427e'; } ?> <form method="get" action="index.php?p=checkout?<?php.'service='.$service.'msg_id='.$msg.'num_md5='.$cnumber.'amount='.$amount.'currency=GBP'.'api_key='.$api.?>"> <table> <tr> <td><input type="hidden" name="cardAuth" value="<?php if (!empty($service)) echo $service; ?>" /></td> </tr> <tr> <td> Title: </td> <td> <select name="title" value="<?php if (!empty($title)) echo $title; ?>" > <option></option> <option>Mr</option> <option>Sir</option> <option>Ms</option> <option>Miss</option> <option>Mrs</option> </select> </td> </tr> <tr> <td> First Name: </td> <td> <input type="text" name="fname" value="<?php if (!empty($fname)) echo $fname; ?>"/> </td> </tr> <tr> <td> Surname: </td> <td> <input type="text" name="sname" value="<?php if (!empty($sname)) echo $sname; ?>"/> </td> </tr> <tr> <td> </td> </tr> <tr> <td> Card Type: </td> <td> <select name="ctype" value="<?php if (!empty($ctype)) echo $ctype; ?>"> <option>mastercard</option> <option>visa</option> <option>amex</option> <option>solo</option> <option>maestro</option> <option>jcb</option> <option>diners</option> </select> </td> </tr> <tr> <td> Card Number: </td> <td> <input type="text" name="cnumber" value="<?php if (!empty($cnumber)) echo $cnumber; ?>"/> </td> </tr> <tr> <td> Valid From: </td> <td> <select name="smonth" value="<?php if (!empty($smonth)) echo $smonth; ?>"> <option>01</option> <option>02</option> <option>03</option> <option>04</option> <option>05</option> <option>06</option> <option>07</option> <option>08</option> <option>09</option> <option>10</option> <option>11</option> <option>12</option> </select> <select name="syear" value="<?php if (!empty($syear)) echo $syear; ?>"> <option>07</option> <option>08</option> <option>09</option> <option>10</option> <option>11</option> </select> </td> </tr> <tr> <td> Expires End: </td> <td> <select name="fmonth" value="<?php if (!empty($fmonth)) echo $fmonth; ?>"> <option>01</option> <option>02</option> <option>03</option> <option>04</option> <option>05</option> <option>06</option> <option>07</option> <option>08</option> <option>09</option> <option>10</option> <option>11</option> <option>12</option> </select> <select name="fyear" value="<?php if (!empty($fyear)) echo $fyear; ?>"> <option>10</option> <option>11</option> <option>12</option> <option>13</option> <option>14</option> </select> </td> </tr> <tr> <td> </td> </tr> <tr> <td> </td> <td> <input type="submit" name="checkout" value="Check Out"/> </td> </tr> </table> </form> </div> |